• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 20
    Registered: ‎09-29-2006

    Determine if Mechanical interfaces are loaded

    127 Views, 7 Replies
    12-13-2012 07:53 AM

    Hi,

     

    As a part of an other recent topic (Interop 32/64 COM - Acad Mechanical), I would like to have an answer to this:

     

    In VB.NET, how can I easily be sure to be in a Mechanical AutoCAD with every specific interfaces loaded (SymBBAuto, AcadmAuto...)?

     

    I tried to get specific system variable like "AMVER" but this does not work.

    I tried a "Try... Catch" while using "GetInterfaceObject", but this does not work at any time... sometimes I got fatal errors.

     

    Note:

    I don't want to use the caption of the AutoCAD window, it is not enough reliable for me.

    I don't want to use the profile name, it is not enough reliable for me too.

     

    So what?

     

    Any Idea?

     

    Thanks

    Please use plain text.
    ADN Support Specialist
    Balaji_Ram
    Posts: 351
    Registered: ‎03-21-2011

    Re: Determine if Mechanical interfaces are loaded

    12-17-2012 07:06 AM in reply to: glanard

    Hello,

     

    Here is a code snippet from a reply that my colleague provided to a similar query.

    To determine if it is AutoCAD Mechanical you can check for the Acmdictionary in NOD 

     

    [CommandMethod("GetFileType")]
    static public void getFileType()
    {
    	string str = "Plain AutoCAD (not AutoCAD Mechanical or Mechanical Desktop)";
    
    	Database db = Application.DocumentManager.MdiActiveDocument.Database;
    
    	Transaction tr = db.TransactionManager.StartTransaction();
    
    	DBDictionary dbd = tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead) as DBDictionary;
    
    	try
    	{
    		ObjectId oid = dbd.GetAt("AcmDictionary"); 
    
    		str = "AutoCAD Mechanical";
    	}
    	catch {}
    
    	tr.Dispose();
    
    	System.Windows.Forms.MessageBox.Show("This is a " + str + " file.");
    }

     Hope this helps.



    Balaji
    Developer Technical Services
    Autodesk Developer Network

    Please use plain text.
    Contributor
    Posts: 20
    Registered: ‎09-29-2006

    Re: Determine if Mechanical interfaces are loaded

    12-17-2012 09:02 AM in reply to: glanard

    Hi Mister,

     

    I know this dictionary but, in fact, that's not what I'm looking for.

     

    With this code, you know the drawing document is a Mechanical one, not the application!

     

    Well, I give you all my solution: I just check if some specific Mechanical's ARX are loaded.

    It's a guarantee for me when I use  "GetInterfaceObject" for SymBBAuto, AcadmAuto... not to have any error.

     

    Best regards,

    Please use plain text.
    ADN Support Specialist
    Balaji_Ram
    Posts: 351
    Registered: ‎03-21-2011

    Re: Determine if Mechanical interfaces are loaded

    12-19-2012 03:31 AM in reply to: glanard

    Sorry, my knowledge of AutoCAD Mechanical is limited.

     

    You may try posting your question in the AutoCAD Mechanical discussion group or other experts in this forum might know it.



    Balaji
    Developer Technical Services
    Autodesk Developer Network

    Please use plain text.
    *Expert Elite*
    Posts: 6,431
    Registered: ‎06-29-2007

    Re: Determine if Mechanical interfaces are loaded

    12-19-2012 04:14 AM in reply to: glanard

    Hi,

     

    look to >>>this thread<<< from Mario and his found soultion for Civil3D, maybe you can adopt it for Mech.

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    Re: Determine if Mechanical interfaces are loaded

    12-19-2012 10:15 AM in reply to: glanard

    glanard wrote:
    With this code, you know the drawing document is a Mechanical one, not the application!

     

    What about:

    Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.Product
    Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.Program

     

    ?


    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.
    Contributor
    Posts: 20
    Registered: ‎09-29-2006

    Re: Determine if Mechanical interfaces are loaded

    12-19-2012 12:39 PM in reply to: alfred.neswadba

    @Alfred / Mario,

     

    First of all, thanks... but, this is not reliable for me :smileysad:.

     

    I don't know CIVIL but I suppose it is exactly like MECHANICAL.

     

    What you can try is :

    - Start AutoCAD, in <<VANILLA>> profile.

    - Change the profile to your <<CIVIL>> one.

    - Your code will say: "Civil is running" :womanhappy:, but If you try manually to use a CIVIL command, you will get something like "unknown command" :womansurprised:.

     

    You know, when you develop an application that has to be deployed on thousands of computers and used daily by many users all over the world, you must be prepared to everything :smileywink:

     

    As I said previously, even with a "Try... Catch", you can sometimes get a fatal error on the GetInterfaceObject.

    That's why we are looking to be sure, BEFORE, to be in the correct release.

     

    @Alexander,

    I tried your code, it was a good idea... but there is absolutely no difference when you start AuoCAD and AutoCAD Mechanical.

     

    So, I stay on my solution: checking if some specific Mechanical ARX are loaded.

     

    Thanks all,

     

    Regards,

    Please use plain text.
    *Expert Elite*
    Posts: 6,431
    Registered: ‎06-29-2007

    Re: Determine if Mechanical interfaces are loaded

    12-20-2012 02:08 AM in reply to: glanard

    Hi,

     

    the solution Mario created was to step through the loaded assemblies, in his case he looks for an assembly that is specific to Civil3D and is only loaded when Civil3D-modules are loaded (not loaded when you start "Civil3D as AutoCAD").

     

    IMHO you have the same chance for Mech, just start Mech, list all assemblies that are loaded and then compare it to a profile that does not load the Mech-functionality. I guess you will see by the name of the assembly which one are specific to Mech. And if you see that this specific assembly is loaded, then your app knows that it can use Mech-API without errors.

     

    HTH, - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.