Author Topic: Custom startup routine in MDI mode  (Read 2024 times)

0 Members and 1 Guest are viewing this topic.

laidbacklarry

  • Guest
Custom startup routine in MDI mode
« on: June 22, 2012, 01:45:28 PM »
Our application has a custom startup routine which loads a Project Manager which, among other things, presents a list of all Projects and, upon selection of a Project presents a list of Drawings in that project folder. Until about 3 years ago our app ran only in SDI mode. Our user base currently uses all versions of ACAD from 2002 through 2013 (the original app was written for ACAD Release 9). Support for MDI mode was added primarily because we were porting the app to Bricscad which only ran in MDI mode at that time.

The problem: Our startup routine works fine in SDI mode for all versions of ACAD and MDI mode for 2002 through 2007 plus 2011. It fails in MDI mode for 2008, 2009, 2010, 2012, and 2013. I suspect the solution is some sort of reactor, but I have zero experience with reactors (although I've written more than 20,000,000 million lines of AutoLisp code), so I'm not sure where to start.

One clue is that while the cursor is immediately available in SDI mode, it takes some time for it to become available in the troublesome versions in MDI mode. Any help would be appreciated.

BlackBox

  • King Gator
  • Posts: 3770
Re: Custom startup routine in MDI mode
« Reply #1 on: June 22, 2012, 01:53:39 PM »

At the risk of tempting fate...

Would it be possible for you to post, even an generalized copy, of your source code so others may be able to better help you to diagnose the problem?

Given that your code is successfully working in multiple MDI versions already, without the use of reactors, they (reactors) should not be necessary from what I understand of your situation. Take from this what you will.
"How we think determines what we do, and what we do determines what we get."

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Custom startup routine in MDI mode
« Reply #2 on: June 22, 2012, 02:06:17 PM »
@ Laidbacklarry

Here is a bit of code I have been using for a long time for make MDI aware commands. Thanks to Stephan Koster back in 1999:

Code: [Select]
;|==============================================================================
  Function Name: (pjk-AddMDICmd)
  Arguments: <Command List> = List of lists in the format (list (list "<Global Command Name>" '<Function Name> "[Local Command Name]" [Cmd-Flags]))
                Sub-list Arguments:
                <Global Command Name> = String for the Name of the Command
                <Function Name> = Quoted symbol for the autolisp function to run
                [Local Command Name] = String (opt.) for the Name of the command - usually same as global name
                [Cmd-Flags] = Integer Bit Flag for Command Behaivior - Bits are as follows:
                   0 = ACRX_CMD_MODAL; Command cannot be invoked while another command is active.
                   1 = ACRX_CMD_TRANSPARENT; Command can be invoked while another command is active.
                   2 = ACRX_CMD_USEPICKSET;When the pickfirst set is retrieved it is cleared within AutoCAD.
                       Command will be able to retrieve the pickfirst set. Command cannot retrieve or set grips.
                   4 = ACRX_CMD_REDRAW; When the pickfirst set or grip set is retrieved, neither will be cleared within AutoCAD.
                       Command can retrieve the pickfirst set and the grip set.
                       
  Usage: (pjk-AddMDICmd <Command List>)
  Returns: N/A
  Description:
This command defines a list of functions as AutoCAD Commands
that are MDI aware. First the Commands are undefined if they
already exist in the ObjectARX enviroment. Then, a document
manager reactor is established to test if another document has
become active and redefines the commands in the active document.
This function can only be called once for Each drawing opened to
establish the Command list and functions. then the reactor does the
work.
*** Original Author: Stephan Koster - 1999 ***
================================================================================|;

(defun pjk-AddMDICmd (lst / old)
(foreach x lst
(vlax-remove-cmd (car x))
(if (setq old (assoc (strcase (car x)) PJK:commandslist))
(setq PJK:commandslist (subst (cons (strcase (car x)) x) old PJK:commandslist))
(setq PJK:commandslist (cons (cons (strcase (car x)) x) PJK:commandslist))
)
)
(if (not PJK:addcmdreactor)
(setq PJK:addcmdreactor
(vlr-docmanager-reactor "PJK-Commands" '((:vlr-documentBecameCurrent . pjk-cmdredef)))
)
)
(pjk-CmdRedef nil nil)
);; End Function (pjk-AddMDICmd)

;|==============================================================================
  Function Name: (pjk-CmdRedef)
  Arguments:
  Usage: (pjk-CmdRedef [Reactor Callback][Command Info])
  Returns: A list of the results of the vlax-add-cmd call - length depends on the command list defined in PJK:Commandslist
           Example: given 4 commands to be defined - '(T T T T) if all commands were defined correctly.
  Description:
This Function is a reactor callback function for (pjk-addMDIcmd),
or can be called alone with both arguments set to NIL. If the
global variable PJK:COMMANDSLIST is defined, it will use it
to create AutoCAD Commands with (vlax-add-cmd).
  *** Original Author: Stephan Koster - 1999 ***
================================================================================|;

(defun pjk-CmdRedef (calbck cmd / return ok)
(foreach x PJK:commandslist
(if (and
(member (type (eval (caddr x))) '(SUBR USUBR EXRXSUBR))
(setq ok (apply 'vlax-add-cmd (cdr x)))
)
(setq return (cons ok return))
)
)
return
);; End Function (pjk-CmdRedef)

Is this what you are looking for?
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

laidbacklarry

  • Guest
Re: Custom startup routine in MDI mode
« Reply #3 on: June 22, 2012, 02:18:52 PM »
@RenderMan

Didn't expect anything so fast. Going out for a while but will throw a short pseudo code together later. One other clue: The startup routine (the Project Manager) only fails on the initial load of AutoCAD. Thereafter, the startup routine works fine whether SDI or MDI. So, for now, an informational dialog is displayed reminding users that in MDI mode, for certain versions of ACAD, the Project Manager must be initially loaded manually - gotta click on the toolbutton...

BlackBox

  • King Gator
  • Posts: 3770
Re: Custom startup routine in MDI mode
« Reply #4 on: June 22, 2012, 02:22:21 PM »
Again, more information is needed to know for sure, but given that the application functions properly for all versions after the AutoCAD application has initialized, perhaps something as simple as an AUTOLOAD statement in AcadDoc.lsp would help to resolve the problem... Just a guess on my part.
« Last Edit: June 22, 2012, 02:31:26 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."