Skip to content

Commit

Permalink
added functionality to set the lastlaunchedacad registry key to ACADE…
Browse files Browse the repository at this point in the history
… if it is not.

set backgroundplot to 1 instead of 0. if its an issue then need to revert it.
  • Loading branch information
wgyalpo committed May 17, 2022
1 parent 4ee05a4 commit edcc24b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
56 changes: 33 additions & 23 deletions AutoCAD Electrical/coolOrange.AcadElectrical/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,22 @@ public override void Start()
bool finished = false;
Proxy.Instance.Collection.Add(() =>
{
// start the application and prepare it
try
{
//Log.Info("Starting AutoCAD Electrical ...");
//var startParams = Properties.Settings.Default.AcadStartParameters;
//var psi = new ProcessStartInfo(AcadExePath, startParams)
//{
// WorkingDirectory = @"C:\temp"
//};
//var acadProcess = Process.Start(psi);
//acadProcess.WaitForInputIdle();
// TODO - use ROT to make sure using correct AutoCAD instance in case there are more than one (https://adndevblog.typepad.com/autocad/2013/12/accessing-com-applications-from-the-running-object-table.html)
try
{
AcadApplication = Marshal.GetActiveObject(AcadProgId);
SetAcadEAsLastLaunchedProduct();
Type acType = Type.GetTypeFromProgID(AcadProgId);
AcadApplication = Activator.CreateInstance(acType, true);
RegisterMessageFilter();
Console.WriteLine("Get object of type \"" + AcadProgId + "\"");
Console.WriteLine("create object of type \"" + AcadProgId + "\"");
}
catch
{
try
{
Type acType = Type.GetTypeFromProgID(AcadProgId);
AcadApplication = Activator.CreateInstance(acType, true);
RegisterMessageFilter();
Console.WriteLine("create object of type \"" + AcadProgId + "\"");
}
catch
{
Log.Error("Cannot create object of type \"" + AcadProgId + "\"");
}
Log.Error("Cannot create object of type \"" + AcadProgId + "\"");
}
Log.Info("Successfully started AutoCAD Electrical!");
Expand Down Expand Up @@ -235,6 +218,33 @@ protected override void Stop_Internal()
}
}

bool SetAcadEAsLastLaunchedProduct()
{
try
{
Log.Info($"Checking if AutoCAD Electrical is the last launcehd product ...");
var curVer = Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD", "CurVer", null);
if (curVer != null)
{
var keyName = $"HKEY_CURRENT_USER\\SOFTWARE\\Autodesk\\AutoCAD\\{curVer}";
var valueName = "LastLaunchedProduct";
var lastLaunchedProductValue = Registry.GetValue(keyName, valueName, null);
if (lastLaunchedProductValue != null && !lastLaunchedProductValue.ToString().Equals("ACADE"))
{
Registry.SetValue(keyName, valueName, "ACADE");
Log.Info($"Set AutoCAD Electrical as the last launcehd product successfully.");
}
}
return true;
}
catch (Exception ex)
{
Log.Error($"Failed to set AutoCAD Electrical as last launched product: {ex.Message}", ex);
}

return false;
}

#region IMessageFilter


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void PublishFile(string dsdFilename)
{
// prepare for publish command
Log.Debug("Setting variable BACKGROUNDPLOT = 0 ...");
AcadDocHelper.SendCommandWait(AcadActiveDocument, "_backgroundplot 0 ");
AcadDocHelper.SendCommandWait(AcadActiveDocument, "_backgroundplot 1 ");

Log.Debug("Setting variable FILEDIA = 0 ...");
AcadDocHelper.SendCommandWait(AcadActiveDocument, "_filedia 0 ");
Expand Down

0 comments on commit edcc24b

Please sign in to comment.