Auto-Setup AutoCAD Options (OPTIONS command) using C#.NET

Auto-Setup AutoCAD Options (OPTIONS command) using C#.NET

mcoH3VZV
Advocate Advocate
3,286 Views
6 Replies
Message 1 of 7

Auto-Setup AutoCAD Options (OPTIONS command) using C#.NET

mcoH3VZV
Advocate
Advocate

Is there a way using C#.NET to set up specific options in autocad's system immediately as it opens? Or it could be through a command.

 

For example, set all support file search paths, maybe change a couple of display settings, etc? I am not looking to simply import/export a profile. I want this to change their default <<ACADE>> profile.

 

The main issue is that at my company, new AutoCAD users need to set everything up, but occasionally a few of the settings get missed. I want this automated.

 

Thanks,

 

0 Likes
Accepted solutions (1)
3,287 Views
6 Replies
Replies (6)
Message 2 of 7

moogalm
Autodesk Support
Autodesk Support

Hi,

 

We can leverage ActiveX API  AcadPreferences.Files to get access on support and project files.

To get information on Support Files Search Path either we can using Acad system variable “ACADPREFIX” or following code:

Search File Path, you can use COM API .NET  (ACADPreferences)

 

https://adndevblog.typepad.com/autocad/2012/05/modifying-autocad-support-path-through-net.html

https://adndevblog.typepad.com/autocad/2015/08/accessing-support-files-and-project-files-search-path...

 

maybe change a couple of display settings

Like ? can you be specific ..

If you are looking color settings, there is only C++ API, you may need to pinvoke in .NET.

 

 

static void ASDkMyGroupBGColorTest(void)
{
    AcColorSettings pColorSettings; 
    acedGetCurrentColors(&pColorSettings); // Get the current colors
    pColorSettings.dwGfxModelBkColor=RGB(255,0,0);// Set the background to red
    pColorSettings.dwModelCrossHairColor=RGB(255,255,0);// set the cursor to yellow
        pColorSettings.dwParallelBkColor = RGB(255,0,0);// set the 3dParallel projection to red
    acedSetCurrentColors(&pColorSettings);
        acedColorSettingsChanged(false, true, true);  // apply the changes. //...
}

 

.NET

 

 class AutoCADColors
  {
    public struct AcColorSettings
    {
      public UInt32 dwGfxModelBkColor;
      public UInt32 dwGfxLayoutBkColor;
      public UInt32 dwParallelBkColor;
      public UInt32 dwBEditBkColor;
      public UInt32 dwCmdLineBkColor;
      public UInt32 dwPlotPrevBkColor;
      public UInt32 dwSkyGradientZenithColor;
      public UInt32 dwSkyGradientHorizonColor;
      public UInt32 dwGroundGradientOriginColor;
      public UInt32 dwGroundGradientHorizonColor;
      public UInt32 dwEarthGradientAzimuthColor;
      public UInt32 dwEarthGradientHorizonColor;
      public UInt32 dwModelCrossHairColor;
      public UInt32 dwLayoutCrossHairColor;
      public UInt32 dwParallelCrossHairColor;
      public UInt32 dwPerspectiveCrossHairColor;
      public UInt32 dwBEditCrossHairColor;
      public UInt32 dwParallelGridMajorLines;
      public UInt32 dwPerspectiveGridMajorLines;
      public UInt32 dwParallelGridMinorLines;
      public UInt32 dwPerspectiveGridMinorLines;
      public UInt32 dwParallelGridAxisLines;
      public UInt32 dwPerspectiveGridAxisLines;
      public UInt32 dwTextForeColor;
      public UInt32 dwTextBkColor;
      public UInt32 dwCmdLineForeColor;
      public UInt32 dwAutoTrackingVecColor;
      public UInt32 dwLayoutATrackVecColor;
      public UInt32 dwParallelATrackVecColor;
      public UInt32 dwPerspectiveATrackVecColor;
      public UInt32 dwBEditATrackVecColor;
      public UInt32 dwModelASnapMarkerColor;
      public UInt32 dwLayoutASnapMarkerColor;
      public UInt32 dwParallelASnapMarkerColor;
      public UInt32 dwPerspectiveASnapMarkerColor;
      public UInt32 dwBEditASnapMarkerColor;
      public UInt32 dwModelDftingTooltipColor;
      public UInt32 dwLayoutDftingTooltipColor;
      public UInt32 dwParallelDftingTooltipColor;
      public UInt32 dwPerspectiveDftingTooltipColor;
      public UInt32 dwBEditDftingTooltipColor;
      public UInt32 dwModelDftingTooltipBkColor;
      public UInt32 dwLayoutDftingTooltipBkColor;
      public UInt32 dwParallelDftingTooltipBkColor;
      public UInt32 dwPerspectiveDftingTooltipBkColor;
      public UInt32 dwBEditDftingTooltipBkColor;
      public UInt32 dwModelLightGlyphs;
      public UInt32 dwLayoutLightGlyphs;
      public UInt32 dwParallelLightGlyphs;
      public UInt32 dwPerspectiveLightGlyphs;
      public UInt32 dwBEditLightGlyphs;
      public UInt32 dwModelLightHotspot;
      public UInt32 dwLayoutLightHotspot;
      public UInt32 dwParallelLightHotspot;
      public UInt32 dwPerspectiveLightHotspot;
      public UInt32 dwBEditLightHotspot;
      public UInt32 dwModelLightFalloff;
      public UInt32 dwLayoutLightFalloff;
      public UInt32 dwParallelLightFalloff;
      public UInt32 dwPerspectiveLightFalloff;
      public UInt32 dwBEditLightFalloff;
      public UInt32 dwModelLightStartLimit;
      public UInt32 dwLayoutLightStartLimit;
      public UInt32 dwParallelLightStartLimit;
      public UInt32 dwPerspectiveLightStartLimit;
      public UInt32 dwBEditLightStartLimit;
      public UInt32 dwModelLightEndLimit;
      public UInt32 dwLayoutLightEndLimit;
      public UInt32 dwParallelLightEndLimit;
      public UInt32 dwPerspectiveLightEndLimit;
      public UInt32 dwBEditLightEndLimit;
      public UInt32 dwModelCameraGlyphs;
      public UInt32 dwLayoutCameraGlyphs;
      public UInt32 dwParallelCameraGlyphs;
      public UInt32 dwPerspectiveCameraGlyphs;
      public UInt32 dwModelCameraFrustrum;
      public UInt32 dwLayoutCameraFrustrum;
      public UInt32 dwParallelCameraFrustrum;
      public UInt32 dwPerspectiveCameraFrustrum;
      public UInt32 dwModelCameraClipping;
      public UInt32 dwLayoutCameraClipping;
      public UInt32 dwParallelCameraClipping;
      public UInt32 dwPerspectiveCameraClipping;
      public int nModelCrosshairUseTintXYZ;
      public int nLayoutCrosshairUseTintXYZ;
      public int nParallelCrosshairUseTintXYZ;
      public int nPerspectiveCrosshairUseTintXYZ;
      public int nBEditCrossHairUseTintXYZ;
      public int nModelATrackVecUseTintXYZ;
      public int nLayoutATrackVecUseTintXYZ;
      public int nParallelATrackVecUseTintXYZ;
      public int nPerspectiveATrackVecUseTintXYZ;
      public int nBEditATrackVecUseTintXYZ;
      public int nModelDftingTooltipBkUseTintXYZ;
      public int nLayoutDftingTooltipBkUseTintXYZ;
      public int nParallelDftingTooltipBkUseTintXYZ;
      public int nPerspectiveDftingTooltipBkUseTintXYZ;
      public int nBEditDftingTooltipBkUseTintXYZ;
      public int nParallelGridMajorLineTintXYZ;
      public int nPerspectiveGridMajorLineTintXYZ;
      public int nParallelGridMinorLineTintXYZ;
      public int nPerspectiveGridMinorLineTintXYZ;
      public int nParallelGridAxisLineTintXYZ;
      public int nPerspectiveGridAxisLineTintXYZ;
    };

    // To access the colours in AutoCAD, we need ObjectARX...
    //for _WIN64 uses different C++ decorator.
    [DllImport("accore.dll",
    CallingConvention = CallingConvention.Cdecl,
    EntryPoint = "?acedGetCurrentColors@@YA_NPEAUAcColorSettings@@@Z"
    )]
    static extern bool acedGetCurrentColors(
      out AcColorSettings colorSettings
    );

    [DllImport("accore.dll",
    CallingConvention = CallingConvention.Cdecl,
    EntryPoint = "?acedSetCurrentColors@@YA_NPEAUAcColorSettings@@@Z"
    )]
    static extern bool acedSetCurrentColors(
      ref AcColorSettings colorSettings
    );



    public static AcColorSettings GetCurrentColors()
    {
      var cs = new AcColorSettings();
      acedGetCurrentColors(out cs);
      return cs;
    }

    public static void SetCurrentColors(AcColorSettings cs)
    {
      acedSetCurrentColors(ref cs);
    }
  }

 

Or, you use Windows Registry API, to set the values for different settings.

 

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Autodesk\ADSKPoly\R24\POLYCAD-3001:409\Profiles\<<Unnamed Profile>>\Drawing Window]
"FontFace"="MS Sans Serif"
"FontHeight"=dword:00000008
"FontWeight"=dword:00000190
"FontPitchAndFamily"=dword:00000000
"FontItalic"=dword:00000000
"Background"=dword:00000000
"Layout background"=dword:00ffffff
"Paper background"=dword:008a8a8a
"Parallel background"=dword:00302821
"Perspective sky zenith"=dword:002d2925
"Perspective sky horizon"=dword:00ffe5e5
"Perspective ground origin"=dword:002d2925
"Perspective ground horizon"=dword:00aaa097
"Perspective sub-surface azimuth"=dword:00666666
"Perspective sub-surface horizon"=dword:00666666
"BEditBackground"=dword:009e9e9e
"Plot preview background"=dword:00ffffff
"XhairPickboxEtc"=dword:000000ff
"LayoutXhairPickboxEtc"=dword:00000000
"Parallel Xhair color"=dword:00ffffff
"Perspective Xhair color"=dword:00ffffff
"BEdit Xhair color"=dword:00000000
Message 3 of 7

Norman_Yuan
Mentor
Mentor
Accepted solution

@moogalm wrote:

Hi,

...

maybe change a couple of display settings

Like ? can you be specific ..

If you are looking color settings, there is only C++ API, you may need to pinvoke in .NET.

 

 

static void ASDkMyGroupBGColorTest(void)
{
    AcColorSettings pColorSettings; 
    acedGetCurrentColors(&pColorSettings); // Get the current colors
    pColorSettings.dwGfxModelBkColor=RGB(255,0,0);// Set the background to red
    pColorSettings.dwModelCrossHairColor=RGB(255,255,0);// set the cursor to yellow
        pColorSettings.dwParallelBkColor = RGB(255,0,0);// set the 3dParallel projection to red
    acedSetCurrentColors(&pColorSettings);
        acedColorSettingsChanged(false, true, true);  // apply the changes. //...
}

 

Or, you use Windows Registry API, to set the values for different settings.

 


"...If you are looking color settings, there is only C++ API, you may need to pinvoke in .NET..."

 

This is not technically true: with Acad .NET API one can access AutoCAD's options via Application.Preferences property, which is AcadPreperences COM object, as the links you have already provided.

 

The color settings referred by your C++ code, and definitely also be manipulated by AcadPreferences.Display property, which as AcadPreferencesDisplay, which is COM object.

 

with C#, the access is really simple:

 

dynamic preferences=Autodesk.AutoCAD.ApplicationServices.Application.Preferences;

preferences.Display.GraphicsWinModelBackgrndColor = ...;

... ...

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 7

moogalm
Autodesk Support
Autodesk Support

Yup, thanks my bad... I don't know why I felt Display is not exposed in COM.

0 Likes
Message 5 of 7

mcoH3VZV
Advocate
Advocate

Perfect. Autodesk.AutoCAD.ApplicationServices.Application.Preferences Works wonderfully.

 

I have gotten most of my settings to work. One remains. I want to not automatically save the plot/publish log file.

1. Under Plot and Publish - Plot and publish log file - Uncheck "Automatically save plot and publish log"

2. Under Plot and Publish - Plot Stamp Setings... - Advanced - Uncheck "Create a log file"

 

However, I do not see a Plot/publish option under Autodesk.AutoCAD.ApplicationServices.Application.Preferences.

 

Does it not exist? Is there another option?

 

Thanks,

 

0 Likes
Message 6 of 7

mcoH3VZV
Advocate
Advocate

I found a way to uncheck the Plot and publish log file (prfeferences.Output.AutomaticPlotLog = false)

 

But I still cannot find a way to uncheck the second box depicted by this forum: https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/Prevent-...

 

Any help to programmatically do this would be appreciated.

0 Likes
Message 7 of 7

tom.friesen
Explorer
Explorer

old thread but this is what i did with lisp which accomplishes the same as 

  1. Within AutoCAD, go into Options by typing OPTIONS on the command line or clicking the Options button at the bottom of the application menu.
  2. Click the Plot and Publish tab, then the Plot Stamp Settings button, and then the Advanced button.
  3. Deselect "Create a log file" and then click OK on all the windows.

(command "-PLOTSTAMP" "L" "N" "" "OFF" "")

 

i was actually looking for a lisp way to

  1. Within AutoCAD, go into Options by typing OPTIONS on the command line or clicking the Options button at the bottom of the application menu.
  2. Click the Plot and Publish tab,
  3. Deselect "Automatically save plot and publish log" and then click OK.

which i still haven't found. Can someone help? I'm sure its simple but I cannot yet translate your C# C++ Api discussions into something i speak

 

always learning....

0 Likes