.NET

.NET

Reply
Contributor
glanard
Posts: 20
Registered: ‎09-29-2006
Message 1 of 8 (245 Views)

Determine if Mechanical interfaces are loaded

245 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

ADN Support Specialist
Balaji_Ram
Posts: 746
Registered: ‎03-21-2011
Message 2 of 8 (222 Views)

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

Contributor
glanard
Posts: 20
Registered: ‎09-29-2006
Message 3 of 8 (218 Views)

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,

ADN Support Specialist
Balaji_Ram
Posts: 746
Registered: ‎03-21-2011
Message 4 of 8 (207 Views)

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

*Expert Elite*
Alfred.NESWADBA
Posts: 9,562
Registered: ‎06-29-2007
Message 5 of 8 (202 Views)

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
-------------------------------------------------------------------------
Moderator
Alexander.Rivilis
Posts: 1,450
Registered: ‎04-09-2008
Message 6 of 8 (194 Views)

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

Contributor
glanard
Posts: 20
Registered: ‎09-29-2006
Message 7 of 8 (186 Views)

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,

*Expert Elite*
Alfred.NESWADBA
Posts: 9,562
Registered: ‎06-29-2007
Message 8 of 8 (170 Views)

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
-------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.