.NET

Reply
Active Contributor
DouceDeux
Posts: 46
Registered: ‎09-04-2012
Message 1 of 8 (331 Views)

Conditional plug-in load

331 Views, 7 Replies
12-26-2012 07:53 AM

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.

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

Re: Conditional plug-in load

12-26-2012 02:08 PM 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
-------------------------------------------------------------------------
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 8 (278 Views)

Re: Conditional plug-in load

12-28-2012 11:52 PM in reply to: Alfred.NESWADBA

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.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 4 of 8 (277 Views)

Re: Conditional plug-in load

12-28-2012 11:55 PM in reply to: DouceDeux

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.

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

Re: Conditional plug-in load

12-29-2012 04:47 AM in reply to: DiningPhilosopher

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
-------------------------------------------------------------------------
Valued Mentor
jeff
Posts: 331
Registered: ‎05-12-2009
Message 6 of 8 (218 Views)

Re: Conditional plug-in load

01-03-2013 12:34 PM 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
Active Contributor
DouceDeux
Posts: 46
Registered: ‎09-04-2012
Message 7 of 8 (198 Views)

Re: Conditional plug-in load

01-04-2013 05:48 AM 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?

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 8 of 8 (195 Views)

Re: Conditional plug-in load

01-04-2013 06:40 AM in reply to: DouceDeux

 

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.

 

 

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.