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

Conditional plug-in load

7 REPLIES 7
Reply
Message 1 of 8
DouceDeux
763 Views, 7 Replies

Conditional plug-in load

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.

7 REPLIES 7
Message 2 of 8
Alfred.NESWADBA
in reply to: DouceDeux

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 8


@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

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

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 8
jeff
in reply to: DouceDeux

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
Message 7 of 8
DouceDeux
in reply to: jeff

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?

Message 8 of 8

 

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.

 

 

 

 

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