• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Contributor
    Posts: 40
    Registered: ‎09-04-2012

    Conditional plug-in load

    215 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.

    Please use plain text.
    *Expert Elite*
    Posts: 6,455
    Registered: ‎06-29-2007

    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
    -------------------------------------------------------------------------
    Please use plain text.
    Valued Mentor
    Posts: 306
    Registered: ‎05-06-2012

    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.

    Please use plain text.
    Valued Mentor
    Posts: 306
    Registered: ‎05-06-2012

    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.

    Please use plain text.
    *Expert Elite*
    Posts: 6,455
    Registered: ‎06-29-2007

    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
    -------------------------------------------------------------------------
    Please use plain text.
    Mentor
    Posts: 241
    Registered: ‎05-12-2009

    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
    Please use plain text.
    Active Contributor
    Posts: 40
    Registered: ‎09-04-2012

    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?

    Please use plain text.
    Valued Mentor
    Posts: 306
    Registered: ‎05-06-2012

    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.

     

     

     

     

    Please use plain text.