Author Topic: How to check if a command is available  (Read 4746 times)

0 Members and 1 Guest are viewing this topic.

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
How to check if a command is available
« on: July 11, 2011, 06:29:44 AM »
Is it possible to check if a certain command is available in AutoCAD, using .NET? Something like IsCommand or CommandAvailable? I've searched for things like this but did not find a solution. Afterall AutoCAD has this information because all available commands can be seen via the commandline in a popup or with the TAB key.

If there is such a function, is that also the best way to determine if Civil3D is loaded? To check for certain commands, or is a better way to look at the loaded assemblies? Or is there some command like IsCivilLoaded or something?
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

kaefer

  • Guest
Re: How to check if a command is available
« Reply #1 on: July 11, 2011, 11:07:16 AM »
Is it possible to check if a certain command is available in AutoCAD, using .NET? Something like IsCommand or CommandAvailable?

The name's Autodesk.AutoCAD.Internal.Utils.IsCommandNameInUse(string).

Quote
I've searched for things like this but did not find a solution. Afterall AutoCAD has this information because all available commands can be seen via the commandline in a popup or with the TAB key.

...and there seems to be no way of getting at this information like the ARX command does, except by p/invoke, possibly.

This whole command business is highly fragmented when viewed from .Net. We could check the loaded assemblies for CommandClassAttributes (reasonably fast) and for implementations of ICommandLineCallable (extremely slow), but that gives only the commands that are defined therein. Then we have things like (VL-LIST-EXPORTED-FUNCTIONS)...

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How to check if a command is available
« Reply #2 on: July 11, 2011, 11:19:46 AM »
I am not sure about Civil3D, but with AutoCAD MEP
If you open AutoCAD MEP as AutoCAD(Vanilla CAd)
The MEP commands will show up in popup but return "Unknown command" if ran.

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: How to check if a command is available
« Reply #3 on: July 11, 2011, 12:13:59 PM »
Ah, I was looking in the right area :-) I thought already it was somewhere in Internal.Utils. I did some tests with IsCommandActive and so but could not figure out how to use it. Now I see the light...

When I test Internal.Utils.IsCommandNameInUse I get CommandTypeFlags.NoneCmd if the command is not available, and CommandTypeFlags.ARXCmd if the command was created by a loaded .NET tool. Thanks for the tip, it helped me a lot! :-)

Concerning Civil3D, I'll do some tests to see if this is also the solution to check if C3D is loaded. I assume there is a difference with Civil3D as AutoCAD, like MEP.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to check if a command is available
« Reply #4 on: July 11, 2011, 12:36:27 PM »
Could you check to see if the Civil3D arx is loaded?  Or, even simpler, check the profile name (presuming you don't use user-specific profile naming)?
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: How to check if a command is available
« Reply #5 on: July 12, 2011, 08:28:51 AM »
@dgorsman: Checking the profile name is a bad thing :-) It's very easy to rename one, but also through the versions of Civil3D the preinstalled profile names are or might be different.

I've checked the loaded assemblies in Civil3D as AutoCAD and Civil3D Metric and this is the list of loaded assemblies in Civil3D:

"mscorlib.dll" 
"AcdbMgd.dll" 
"mscorlib.dll" 
"System.dll" 
"msvcm90.dll" 
"System.Xml.dll" 
"System.Drawing.dll"
"PresentationFramework.dll" 
"WindowsBase.dll" 
"PresentationCore.dll" 
"AdApplicationFrame.dll" 
"AdWindows.dll" 
"PresentationFramework.Aero.dll" 
"acmgd.dll" 
"System.Core.dll" 
"System.Configuration.dll"
"AcWindows.dll" 
"AcWindows.resources.dll" 
"AcCui.dll" 
"aecmgdreverse.dll" 
"AecRibbon.dll" 
"AcMapResourceManagement.dll" 
"AmbercoreEngine.dll" 
"AmberCore.IsdCodecAPI.Core.dll" 
"Redland.NET.dll" 
"AcMapSurveyMan.dll" 
"Autodesk.Gis.Map.SurveyUI.dll" 
"System.Windows.Forms.dll" 
"Autodesk.Gis.Map.Survey.dll" 
"Autodesk.Map.Platform.Core.dll" 
"OSGeo.MapGuide.PlatformBase.dll"
"OSGeo.MapGuide.Foundation.dll" 
"OSGeo.MapGuide.Geometry.dll" 
"Autodesk.Gis.Map.Survey.Resource.dll"
"AcMapRibbonWrapper.dll" 
"Autodesk.Gis.Map.Shared.dll"
"AeccMgdReverse.dll" 
"AeccUiWindows.dll" 
"AeccUiWindows.resources.dll" 
"Microsoft.VisualBasic.dll"
"flAcadLib2011_x64.dll" 
"flNlcsLib.dll" 
"System.Web.dll"
"Autodesk.AutoCAD.Interop.dll" 
"ManagedMC3.dll" 
"AcLayer.dll" 
"AcLayer.resources.dll" 
"Accessibility.dll"


Only in Civil3D are these extra:

"aecmgdreverse.dll" 
"AecRibbon.dll" 
"AmbercoreEngine.dll" 
"AmberCore.IsdCodecAPI.Core.dll" 
"AeccMgdReverse.dll" 
"AeccUiWindows.dll" 
"AeccUiWindows.resources.dll" 


It also might differ if the Toolspace is loaded or not and if people have messed around with the civil3d.cui as Enterprise menu.

I assume the best way to check if Civil3D is loaded to check if the command TOOLSPACE is available. In Civil3D as AutoCAD it is not available.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to check if a command is available
« Reply #6 on: July 12, 2011, 10:23:57 AM »
Pardon, Civil3D is only on my periphery here   :-)  Isn't there an ARX for Civil3D that gets loaded to support the core program?  Or is it all DLL-based?  The reason I ask is virtually all programs I've seen include at least one core ARX that can be tested for.  Many load it explicity from the desktop shortcut through an /ld argument, at start-up through registry flags (something else to test), or through an acad.rx file.  When they are "run as AutoCAD" they just omit the ARX load.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

kaefer

  • Guest
Re: How to check if a command is available
« Reply #7 on: July 12, 2011, 01:10:49 PM »
[...] virtually all programs I've seen include at least one core ARX that can be tested for.

Did you just say it could be as simple as this?

Code: [Select]
            bool IsAECLoaded = SystemObjects.DynamicLinker.GetLoadedModules().Contains("AecBase.dbx".ToLower());
That would cover vanilla vs. AEC-based vertical (which is Architecture and MEP, here).

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: How to check if a command is available
« Reply #8 on: July 12, 2011, 01:19:51 PM »
AecBase.dbx is also loaded in Civil3D via the /ld switch. Testing this one only gives the result it is a vertical. I stick with the solution to test a Civil3D command, unless there is a better, faster or less resource consuming function :-)
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How to check if a command is available
« Reply #9 on: August 21, 2011, 07:09:27 AM »
Hi,

I don't know so much about 'vertical', but I needed to evaluate if the current AutoCAD is Vanilla (inside MEP) or MEP.
I found a way trying to create instance of the AutoCAD.Aec.ApplicationServices.DrawingSetupVariables class.

Code: [Select]
ObjectId dsvId = DrawingSetupVariables.GetInstance(db, false);
 if (dsvId != ObjectId.Null)
{
    ....
}
Speaking English as a French Frog

LE3

  • Guest
Re: How to check if a command is available
« Reply #10 on: August 21, 2011, 12:43:14 PM »
Or when autocad it is launched it is saved in the registry from where it was launched:

HKEY_CURRENT_USER/software/autodesk/dwgcommon/shellex/apps/The_civil3d_GUID_goes_here

And extract from there the GUID and that will tell you if civil3d is the one running or use OpenLaunch key, etc.

HTH.-