.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Determine if Mechanical interfaces are loaded

7 REPLIES 7
Reply
Message 1 of 8
glanard
689 Views, 7 Replies

Determine if Mechanical interfaces are loaded

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

7 REPLIES 7
Message 2 of 8
Balaji_Ram
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

Message 3 of 8
glanard
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,

Message 4 of 8
Balaji_Ram
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

Message 5 of 8
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 8
Alexander.Rivilis
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

 

?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 7 of 8
glanard
in reply to: Alfred.NESWADBA

@Alfred / Mario,

 

First of all, thanks... but, this is not reliable for me Smiley Sad.

 

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" Woman Happy, but If you try manually to use a CIVIL command, you will get something like "unknown command" Woman Surprised.

 

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 😉

 

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,

Message 8 of 8
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost