Conditional plug-in load

Conditional plug-in load

Anonymous
Not applicable
1,304 Views
7 Replies
Message 1 of 8

Conditional plug-in load

Anonymous
Not applicable

Hello!

 

I'm trying to get my plug-in to successfully load its commands only if certain parameters are met like a prefix in the DWG file name. (I know I would have to use GETSYSTEMVARIABLE("DWGNAME") )  I haven't been able to implement a restriction successfully.

 

Also, is there a way to load a plug-in only within the scope of a document and not the entire AutoCAD executable?

This way, if the user has open document A and it's not a valid document of use of the plug-in, he won't be able to use the commands, but if he loads document B with a valid format (name prefix), the plug-ing will automatically load for the document B intance only. Is this possible?

(Working with AutoCAD 2010 and .net 3.5)

 

P)lease let me know if it's not possible under that configureation but it is for other configurations.

 

Thanks in advance.

0 Likes
1,305 Views
7 Replies
Replies (7)
Message 2 of 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I haven't been able to implement a restriction successfully

Not beautiful, but possible: if the test fails (so your DLL should not be loaded) you can raise an unhandled exception within the INITIALIZE part of your DLL (e.g. do a division by 0 or access a file that does not exist or ...., but without try-catch).

 

>> to load a plug-in only within the scope of a document

AFAIK no.

But you may test at your commands if a restriction-test fails or succeeds, then execute the internal of your command or bypass it.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 3 of 8

DiningPhilosopher
Collaborator
Collaborator

@Alfred.NESWADBA wrote:

Hi,

 

>> I haven't been able to implement a restriction successfully

Not beautiful, but possible: if the test fails (so your DLL should not be loaded) you can raise an unhandled exception within the INITIALIZE part of your DLL (e.g. do a division by 0 or access a file that does not exist or ...., but without try-catch).

 


Sorry, that won't work. Throwing an exception in Initialize() does not prevent the plug-in assembly from loading, because it is already loaded at that point. After that, there is nothing the OP could do to register the commands when he does want them to be available.

Message 4 of 8

DiningPhilosopher
Collaborator
Collaborator

I'm afraid there's no simple (or difficult) way to do what you ask.

 

The easiest way to accomplish it is to simply check the active document when the command(s) are issued.

 

It would probably be better to do that, because it wouldn't leave the user wondering why commands are not available in one document but are in others, with no explaination.

Message 5 of 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Sorry, that won't work. Throwing an exception in Initialize()

>> does not prevent the plug-in assembly from loading

Yes and sorry, you are absolutly right, I was to focused on the "commands not working". With my solution AutoCAD would have to be restarted to get it running (that's what I use for protection as it's then more difficult to debug). But in this case (when the correct drawing is activated afterwards) the command should work.

I would then suggest to let the command be enabled, but within each command first the test should be done if the command should act in that case or not, if not I would send a message for "why it's not working here".

 

Thx for correction!

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 6 of 8

jeff
Collaborator
Collaborator

Once a document meets the requirements and it is loaded then the commands should be avialable to all documents.

 

You can also find your answers @ TheSwamp
0 Likes
Message 7 of 8

Anonymous
Not applicable
String prefix = "MyCompanyName";
if ( !((String)GETSYSTEMVARIABLE("DWGNAME")).Contains(prefix) )
{
  //Send command load failure message
  return;
}

 

So I guess do it this way for each command?

0 Likes
Message 8 of 8

DiningPhilosopher
Collaborator
Collaborator

 

Application.DocumentManager.MdiActiveDocument.Name returns the current drawing's filename.

 

If you don't want the command to run in a given document, display a message telling the user that, rather than making it look like an error or failure to load the plug-in, that is, unless you enjoy being bombarded with support requests.

 

 

 

 

0 Likes