;|==============================================================================
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 (setq PJK:commandslist lst)
(vlax-remove-cmd (car x))
)
(foreach obj (cdar (vlr-reactors :vlr-docmanager-reactor))
(if (= "PJK-Commands" (vlr-data obj))(vlr-remove obj))
)
(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 ***
Update 5/16/2016: Added (mapcar) loop to undefined the commands prior to redefining them. This corrects an issue that
caused the original function not to work correctly since AutoCAD 2009 (I think).
THANKS to Marc'Antonio Alessi for the method!
================================================================================|;
;|
(defun pjk-CmdRedef (calbck cmd)
(mapcar
(function
(lambda (x)
(vlax-remove-cmd (car x))
)
)
PJK:commandslist
)
(mapcar
(function
(lambda (x / ok)
(if (and
(member (type (eval (cadr x))) '(SUBR USUBR EXRXSUBR))
(setq ok (apply 'vlax-add-cmd x))
)
ok
)
)
)
PJK:commandslist
)
) ;; End Function (pjk-CmdRedef)
|;
(defun c:vt
() (alert "This is a test of VLX private.")) (defun vte
() (alert "This is a test of VLX export non-command.")) (defun c:vtec
() (alert "This is a test of VLX export command.")) ;;; Test results: 2017-03-08 Compiled to VLX with optimize and link.
;;; Drag into dwg 1: All the above worked
;;; Open dwg 2. None work.
;;; Drag into dwg 2. All work.
;|
(vlax-add-cmd "VT" 'c:vt)
(vlax-add-cmd "VTE" 'vte)
(vlax-add-cmd "VTEC" 'c:vtec)
|;
;;; Added above declarations.
;;; Test results: 2017-03-08 Compiled to VLX with optimize and link (and separate namespace).
;;; Drag into dwg 1: All worked including (command "vtec") etc.
;;; Drag into dwg 2: All give "; error: Visual LISP command document mismatch:"
;|
(pjk-AddMDICmd
(list
(list "VT" 'c:vt)
(list "VTE" 'vte)
(list "VTEC" 'c:vtec)
)
)
|;
;;; Added above from https://www.theswamp.org/index.php?topic=51409.msg565523#msg565523
;;; Test results: 2017-03-08
;;; Compiled to VLX with optimize and link (and separate namespace).
;;; Drag into dwg 1: All worked.
;;; Opened dwg 2. None worked. Dragged in. All worked.
;;; Switched to dwg 1: All worked!
(defun vtp
()(alert "This was supposed to be private")) ;;; Added above to test private functions
;;; Test results 2017-03-08
;;; Drag into dwg 1: All previous worked. vtp and vtpc didn't work. Yay!
;;; Switch to dwg 2: All same behavior. No extra load needed. One load works in all docs.
;;; Open dwg 3: ; error: Visual LISP command document mismatch: VT
;;; Load vlx: All works as desired.
;;; Add vlx to Appload Startup suite. Restart AutoCAD. Caused AutoCAD crash on restart.
;;; Commented out pjk functions, reverting to vlax-add-cmd.
;;; Started AutoCAD. All worked as desired.
;;; Opened drawing 2. ; error: Visual LISP command document mismatch: VTE etc.
;;
;;; Reverted to pjk functions. Restarted AutoCAD. Worked in dwg1. Worked in dwg2.
;;; Switched to dwg 1. All worked.
;;; Removed both pjk and vlax-add-cmd calls. Left vlx in startup suite.
;;; vl-acad-defun works (privates were private and publics were public).
;;; Removed vlx from startup suite. Caused AutoCAD crash on restart (just like when I added it).
;;; On restart, dragged vlx into one drawing after another. All works as desired.(vtP)
;;; Conclusion: To control exporting exposing Visual Lisp functions, use a single VLX.
;;; To export the commands to *native" AutoCAD commands (command "My_command"),
;;; use the PJK functions and load in each drawing.