Author Topic: transparent lisp command  (Read 15579 times)

0 Members and 1 Guest are viewing this topic.

Coltm16

  • Guest
transparent lisp command
« on: May 11, 2016, 08:55:54 PM »
I need some help if possible. Maybe there is an easier way. After doing a lot of research and googling, I am stumped. What I basically want is the "from" command modifier to be able to have the 'rubberband' that respects polar tracking / ortho mode. It sucks having to use inference constraints to offset at a specific angle or orthographically. Maybe I am just using _from wrong.

here was my first attempt:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:myfrom (/tmp tmp2)
  2.   (setq tmp (getpoint "\nSpecify base point"))
  3.   (setq tmp2 (getpoint tmp "\nSpecify offset: "))
  4.   )

This works fine when when using some commands like a line, and using it transparently like 'myfrom. But it blows up when using other commands or custom lisp routines and trying to invoke it transparently. Then I herd about vlax-add-cmd and tried this:

Code - Auto/Visual Lisp: [Select]
  1. (defun custom:myfrom (/ myfrompoint doc tmp tmp2)
  2.   (setq tmp (getpoint "\nSpecify base point"))
  3.   (setq tmp2 (getpoint tmp "\nSpecify offset: "))
  4.   (setq myfrompoint (mapcar '(lambda (x) (rtos x 2 16)) tmp2))
  5.   (vla-SendCommand doc (strcat "_non " (car myfrompoint) "," (cadr myfrompoint) "\n"))
  6.   )
  7.  
  8. (vlax-add-cmd "myfrom" 'custom:myfrom "myfrom" ACRX_CMD_TRANSPARENT)

But this kind of worked except the main flaw was that it did not work when I opened another drawing in the same instance of autocad. "Visual LISP command document mismatch" I tried using dummycommandreactor...etc etc.. that I found searching that supposedly fixed this bug, but the post was dated from 2000 and had no efffect.

Any clues would be appreciated.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #1 on: May 12, 2016, 01:18:13 AM »
Does this Help ??

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (vlax-add-cmd "mf" 'myfrom  "mf"  ACRX_CMD_TRANSPARENT )
  3.  
  4. (defun myfrom (/ tmp )
  5.   (setq tmp (getpoint "\nSpecify base point"))
  6.   (setq globalPt (getpoint tmp "\nSpecify offset: "))
  7.   (vla-SendCommand *acDoc* "!globalPt ")
  8. )
  9.  
  10.  



Command: l
LINE
Specify first point:
Specify next point or [Undo]:
Specify next point or [Undo]:
Specify next point or [Close/Undo]: 'mf
>>Specify base point
>>Specify offset:
Resuming LINE command.
Specify next point or [Close/Undo]: !globalPt (6899.8 6624.64 0.0)
Specify next point or [Close/Undo]:
Command: *Cancel*
« Last Edit: May 12, 2016, 01:24:14 AM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: transparent lisp command
« Reply #2 on: May 12, 2016, 08:18:49 AM »
Are you looking for a rotated (getcorner)  ?

-David
R12 Dos - A2K

Coltm16

  • Guest
Re: transparent lisp command
« Reply #3 on: May 12, 2016, 09:13:48 AM »
Sorry, I am not sure what that a rotated (getcorner) is. Here is what I am looking for:

Start the line command, before selecting your first point, shift+right click and use the command modifier "FROM". Now select the basepoint, now for the offset distance, I do not get a "rubberband" that uses polar tracking. I am "blindly" having to select the offset point angle when using direct distance input.

Contrast this with the end point of the line command. If I use the "from" command modifier on the end point, all of a sudden I get to use the rubberband w/ polar tracking when specifying the offset point.

I am trying to make a custom "from" command modifier that uses the rubberband in all circumstances.

Thank you Kdub, I think that works except when I use it during a custom routine. I get the error message "Can't reenter LISP." when tring to use !someglobalvariable. I think it is working in all circumstances if I use rtos on the point and pass it to the command line as a string, but this makes me worried about the precision of the point.

Code - Auto/Visual Lisp: [Select]
  1. (vlax-add-cmd "mf" 'myfrom  "mf"  ACRX_CMD_TRANSPARENT )
  2.  
  3.  
  4. (defun myfrom (/ tmp tmp2 tmp3)
  5.   (setq tmp (getpoint "\nSpecify base point"))
  6.   (setq tmp2 (getpoint tmp "\nSpecify offset: "))
  7.   (setq tmp3 (mapcar '(lambda (x) (rtos x 2 16)) tmp2))
  8.   (vla-SendCommand *acDoc* (strcat "_non " (car tmp3) "," (cadr tmp3) "\n"))
  9. )

Edit: It is still not working when switching between documents. I found this, but it is dated from 2000, and it does not seem to help anything.

Code - Auto/Visual Lisp: [Select]
  1. ;;; Workaround for (vlax-add-cmd) bug.
  2. ;;; by Stephan Koster
  3.  
  4. ;; Comments by JRF: This code should be
  5. ;;; run before adding any other commands with vlr-add-cmd.
  6. ;;; Otherwise, when using added commands in multiple documents
  7. ;;; (MDI mode), sometimes the commands fail with a "Visual LISP
  8. ;;; command document mismatch" error. Apparently vlax-add-cmd
  9. ;;; must be called in a document in order to activate commands
  10. ;;; in that document.
  11. (defun DummyCommand () NIL)
  12. (vlax-add-cmd "DummyCommand" 'DummyCommand)
  13. (defun AddCommandsHelper (a b)
  14. (vlax-add-cmd "DummyCommand" 'DummyCommand)
  15. )
  16. ;; Install dummy command reactor only if it's not
  17. ;; defined already
  18. (or DummyCommandReactor
  19. (setq DummyCommandReactor
  20. NIL
  21. '((:vlr-documentBecameCurrent . AddCommandsHelper))
  22. )
  23. )
  24. )
« Last Edit: May 12, 2016, 10:26:38 AM by Coltm16 »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #4 on: May 12, 2016, 12:18:49 PM »
I use this method for many years (perhaps should be improved ...)
For example you can nest multiple ALE_MidPoint functions (or similar) during a command or
in response to a Lisp function (nesting has some problem in Bricscad...)
Quote
Comando:_line
Specificare primo punto:                                 >>> [_Button("« Middle Point"...
>>First point <Lastpoint> <13.09,398.28,0>: >>> [_Button("« Middle Point"...
>>First point <Lastpoint> <13.09,398.28,0>: >>> [_Button("« Middle Point"...
>>First point <Lastpoint> <13.09,398.28,0>:
>>Second point:
>>Second point:
>>Second point: nil
Specificare punto successivo o [Annulla]:
Code: [Select]
; [_Button("« Middle Point", OsnMedio, OsnMedio)]^P$M=$(if,$(getvar,cmdactive),(ALE_MidPoint """""""ACTIVE"""""""),(ALE_MidPoint nil));
; [_Button("« Progressive Distance", OsnALE_DistPr, OsnALE_DistPr)]^P$M=$(if,$(getvar,cmdactive),(ALE_DistPr """""""ACTIVE"""""""),(ALE_DistPr nil));
Code: [Select]
; Example (no nesting - only for command line)
(setq *acDoc*  (vla-get-ActiveDocument (vlax-get-acad-object)))
(vlax-remove-cmd "mf")
(vlax-add-cmd "mp" 'Ale_MP  "mp")
(defun Ale_MP ( )
  (vla-SendCommand *acDoc* "!(ALE_MidPoint \"ACTIVE\") ")
)
;
; ALE_GetPoint - Alessi Marc'Antonio 20/02/93
; IGtBit > (1 = not null, 0 for none) same of INITGET
; KwdStr = key word ("" for none) same of INITGET
; PrmStr = prompt string, a default as <DefPnt> (nil for none)
;          will be added and a : will be added
; BasPtn = base point (nil for none)
;
; Example:
; (setq #GlVal (ALE_GetPoint 40 "" "Inser point <Lastpoint>" #GlVal #GlVal))
;
(defun ALE_GetPoint (IGtBit KwdStr PrmStr DefPnt BasPtn / InpVal DefStr ZetPnt)
  (if DefPnt
    (setq
      ZetPnt (caddr DefPnt)
      DefStr
        (strcat
          (rtos (car  DefPnt)) ","
          (rtos (cadr DefPnt)) ","
          (if ZetPnt (rtos ZetPnt) "0")
        )
      PrmStr (strcat "\n" PrmStr " <" DefStr ">: ")
      IGtBit (logand IGtBit 254)
    )
    (setq PrmStr (strcat "\n" PrmStr ": "))
  )
  (setq InpVal "NOTVALIDSTRING" IGtBit (+ IGtBit 128))
  (while
    (not
      (or
        (= 'LIST (type InpVal))
        (null InpVal)
        (if (= 'STR (type InpVal))
          (or
            (= 'LIST (type (read InpVal)))
            (wcmatch KwdStr (strcat "*" InpVal "*"))
          )
        )
      )
    )
    (initget IGtBit KwdStr)
    (setq InpVal (if BasPtn (getpoint BasPtn PrmStr) (getpoint PrmStr)))
  )
  (if InpVal
    (if (or (/= 'STR (type InpVal)) (atom (read InpVal)))
      InpVal
      (eval
        (if (= "ACTIVE" (cadr (read InpVal)))
          (subst nil "ACTIVE" (read InpVal))
          (read InpVal)
        )
      )
    )
    DefPnt
  )
)
(defun ALE_MidPoint (CmdAct / BasPtn Pnt001 CurBlp CurOrt CurOsn)
    (graphscr)
    (setq CurBlp (getvar "BLIPMODE")  CurOrt (getvar "ORTHOMODE"))
    (setvar "BLIPMODE" 1)   (setvar "ORTHOMODE" 0)
    (setq
      BasPtn   (ALE_GetPoint 40 "" ">>First point <Lastpoint>" (getvar "LASTPOINT") (getvar "LASTPOINT"))
      Pnt001   (ALE_GetPoint 41 "" ">>Second point"  nil BasPtn)
      CurOsn (getvar "OSMODE")
    )
    (setvar "OSMODE" 0)
    (setq BasPtn (polar BasPtn (angle BasPtn Pnt001) (/ (distance BasPtn Pnt001) 2.0)))
    (setvar "BLIPMODE" CurBlp) (setvar "ORTHOMODE" CurOrt) (setvar "OSMODE" CurOsn)
    (cond
      ( (and BasPtn CmdAct) (command "_NONE" BasPtn) )
      ( BasPtn )
      ( T (alert "Asso message:\nMidpoint not found."     ) (princ) )
    )
)
(defun ALE_DistPr (CmdAct / BasPtn Pnt001 DstTot CurOrt CurBlp)
    (graphscr)
    (setq CurOrt (getvar "ORTHOMODE")  CurBlp (getvar "BLIPMODE" ))
    (setvar "ORTHOMODE" 1)   (setvar "BLIPMODE" 1)
    (setq
      DstTot 0
      BasPtn (ALE_GetPoint -88 "" ">>Reference point <Lastpoint>"      (getvar "LASTPOINT") nil)
    )
    (while
      (setq Pnt001 (ALE_GetPoint -88 "" ">><Next point>/Return to quit"            nil BasPtn))
      (setq DstTot (+ DstTot (distance BasPtn Pnt001)))
      (prompt
        (strcat
          "\n>>Distance: " (rtos (distance BasPtn Pnt001)) "  Angle: "  (angtos (angle BasPtn Pnt001))
          "  Total distance: " (rtos DstTot) "\n "
        )
      )
      (grdraw BasPtn Pnt001 -1 1) (setq BasPtn Pnt001)
    )
    (setvar "ORTHOMODE" CurOrt)   (setvar "BLIPMODE"  CurBlp)
    (cond
      ( (and BasPtn CmdAct) (command "_NONE" BasPtn) (princ) )
      ( BasPtn )
      ( T (alert "Asso message:\nPoint not found."  ) (princ) )
    )
)

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: transparent lisp command
« Reply #5 on: May 12, 2016, 01:43:07 PM »
I use this method for many years (perhaps should be improved ...)
For example you can nest multiple ALE_MidPoint functions (or similar) during a command or
in response to a Lisp function (nesting has some problem in Bricscad...)
...

Hi Marc'Antonio,

For some reason this method has not been working for me since AutoCAD 2009 I think. I have the following functions I had been using for transparent zoom shortcuts. (Not all zoom functions included for clarity.) This method (originally created by Stephan Koster) used to work. Now the commands only work in the LAST document opened, with the older documents giving the same "Visual LISP command document mismatch" when switching back to them.

Without the reactor included - The commands only work in the FIRST document loaded, even though they are loaded again in acaddoc.lsp. I tested also only loading them ONCE per session and still got the same result as without the reactor. Do you or anyone else have any ideas why my method is not working anymore? I suspect it's some kind of namespace issue, but perhaps I am missing something critical.

Code - Auto/Visual Lisp: [Select]
  1. ;; function to do a zoom > window.
  2. (defun pjk-zw ( / thisdwg)
  3.         (vla-sendcommand thisdwg "'._zoom _w ")
  4.         (vlax-release-object thisdwg)
  5.         (princ)
  6. );; End Function (pjk-zw)
  7.  
  8. ;; Create a list for (pjk-AddMDICmd)
  9. (setq cmdlst
  10.    (list
  11.         ;; Zooming Commands...
  12.         (list "ZW"  'pjk-zw     "ZW" 1)
  13.    )
  14. )
  15.  
  16. ;|==============================================================================
  17.   Function Name: (pjk-AddMDICmd)
  18.   Arguments: <Command List> = List of lists in the format (list (list "<Global Command Name>" '<Function Name> "[Local Command Name]" [Cmd-Flags]))
  19.                 Sub-list Arguments:
  20.                 <Global Command Name> = String for the Name of the Command
  21.                 <Function Name> = Quoted symbol for the autolisp function to run
  22.                 [Local Command Name] = String (opt.) for the Name of the command - usually same as global name
  23.                 [Cmd-Flags] = Integer Bit Flag for Command Behaivior - Bits are as follows:
  24.                    0 = ACRX_CMD_MODAL; Command cannot be invoked while another command is active.
  25.                    1 = ACRX_CMD_TRANSPARENT; Command can be invoked while another command is active.
  26.                    2 = ACRX_CMD_USEPICKSET;When the pickfirst set is retrieved it is cleared within AutoCAD.
  27.                        Command will be able to retrieve the pickfirst set. Command cannot retrieve or set grips.
  28.                    4 = ACRX_CMD_REDRAW; When the pickfirst set or grip set is retrieved, neither will be cleared within AutoCAD.
  29.                        Command can retrieve the pickfirst set and the grip set.
  30.                        
  31.   Returns: N/A
  32.   Description:
  33.                 This command defines a list of functions as AutoCAD Commands
  34.                 that are MDI aware. First the Commands are undefined if they
  35.                 already exist in the ObjectARX environment. Then, a document
  36.                 manager reactor is established to test if another document has
  37.                 become active and redefines the commands in the active document.
  38.                 This function can only be called once for Each drawing opened to
  39.                 establish the Command list and functions. then the reactor does the
  40.                 work.
  41.  
  42.                 *** Original Author: Stephan Koster - 1999 ***
  43. ================================================================================|;
  44. (defun pjk-AddMDICmd (lst / old)
  45.    (foreach x (setq PJK:commandslist lst)
  46.       (vlax-remove-cmd (car x))
  47.    )
  48.       (if (= "PJK-Commands" (vlr-data obj))(vlr-remove obj))
  49.    )
  50.    (vlr-docmanager-reactor "PJK-Commands" '((:vlr-documentBecameCurrent . pjk-CmdRedef)))
  51.    (pjk-CmdRedef nil nil)
  52. ) ;; End Function (pjk-AddMDICmd)
  53.  
  54. ;|==============================================================================
  55.   Function Name: (pjk-CmdRedef)
  56.   Arguments:
  57.   Usage: (pjk-CmdRedef [Reactor Callback][Command Info])
  58.   Returns: A list of the results of the vlax-add-cmd call - length depends on the command list defined in PJK:Commandslist
  59.            Example: given 4 commands to be defined - '(T T T T) if all commands were defined correctly.
  60.   Description:
  61.                 This Function is a reactor callback function for (pjk-addMDIcmd),
  62.                 or can be called alone with both arguments set to NIL. If the
  63.                 global variable PJK:COMMANDSLIST is defined, it will use it
  64.                 to create AutoCAD Commands with (vlax-add-cmd).
  65.  
  66.   *** Original Author: Stephan Koster - 1999 ***
  67. ================================================================================|;
  68. (defun pjk-CmdRedef (calbck cmd)
  69.    (mapcar
  70.       (function
  71.          (lambda (x / ok)
  72.             (if (and
  73.                    (member (type (eval (cadr x))) '(SUBR USUBR EXRXSUBR))
  74.                    (setq ok (apply 'vlax-add-cmd x))
  75.                 )
  76.                 ok
  77.             )
  78.          )
  79.       )
  80.       PJK:commandslist
  81.    )
  82. ) ;; End Function (pjk-CmdRedef)
  83.  
  84. ;; define the zoom commands and reactor
  85. (pjk-AddMDICmd cmdlst)
  86.  

EDIT: NOTE: Corrected the code excerpt to show the function running at the end. Which is how it is actually - just pasted in in the wrong order.
« Last Edit: May 12, 2016, 01:51:52 PM by PKENEWELL »
"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

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #6 on: May 12, 2016, 03:57:52 PM »
Hi Marc'Antonio,
For some reason this method has not been working for me since AutoCAD 2009 I think. ...
I do not quite understand what you mean, have you tried my functions?
I am using in all versions of AutoCAD/Bricscad since it was introduced the bit 128 for initget (maybe 1990).
Try to make the two buttons:
[_Button("« Middle Point", YourIcon, YourIcon)]^P$M=$(if,$(getvar,cmdactive),(ALE_MidPoint """""""ACTIVE"""""""),(ALE_MidPoint nil));
[_Button("« Progressive Distance", YourIcon2, YourIcon2)]^P$M=$(if,$(getvar,cmdactive),(ALE_DistPr """""""ACTIVE"""""""),(ALE_DistPr nil));
and test ALE_MidPoint or ALE_DistPr inside a command or AutoLisp function.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #7 on: May 12, 2016, 05:02:10 PM »


Are you guys using a separate-namespace ??

From the docs:


With vlax-add-cmd you can define a function as an AutoCAD command, without using the c: prefix in the function name. You can also define a transparent AutoLISP command, which is not possible with a c: function.
WarningYou cannot use the command function call in a transparently defined vlax-add-cmd function. Doing so can cause AutoCAD to close unexpectedly.
The vlax-add-cmd function makes an AutoLISP function visible as an ObjectARX-style command at the AutoCAD Command prompt during the current AutoCAD session. The function provides access to the ObjectARX acedRegCmds macro, which provides a pointer to the ObjectARX system AcEdCommandStack object.
The vlax-add-cmd function automatically assigns commands to command groups. When issued from a document namespace, vlax-add-cmd adds the command to a group named doc-ID; doc-ID is a hexadecimal value identifying the document. If issued from a separate-namespace VLX, vlax-add-cmd adds the command to a group named VLC-Ddoc-ID:VLX-name, where VLX-name is the name of the application that issued vlax-add-cmd .
It is recommended that you use the vlax-add-cmd function from a separate-namespace VLX. You should then explicitly load the VLX using the APPLOAD command, rather than by placing it in one of the startup LISP files.
NoteYou cannot use vlax-add-cmd to expose functions that create reactor objects or serve as reactor callbacks.

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #8 on: May 12, 2016, 05:39:49 PM »
Coltm16,
Did you come across this in your search ?
https://www.theswamp.org/index.php?topic=34018.msg393433#msg393433

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Coltm16

  • Guest
Re: transparent lisp command
« Reply #9 on: May 12, 2016, 05:45:59 PM »
Yes I did. I still do not understand how he is overcoming the fact that this only works is the most recently opened file tab and throws the error message: "Visual LISP command document mismatch." if you try to run the transparent command in a previously opened filetab/drawing.

It seems like my clue is:
Quote
It is recommended that you use the vlax-add-cmd function from a separate-namespace VLX. You should then explicitly load the VLX using the APPLOAD command, rather than by placing it in one of the startup LISP files.

Me being a newbie, I need to figure out what a namespace.vlx file is and how it differs from a .lsp file and what exactly am I supposed to put in this vlx file. Just the add-cmd call or the transparent function also?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #10 on: May 12, 2016, 05:50:47 PM »
Yes I did. I still do not understand how he is overcoming the fact that < ... >

he is me.

I'll have a look tonight if you don't get it resolved .. about 12 hours away.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: transparent lisp command
« Reply #11 on: May 12, 2016, 06:03:53 PM »
he is me

And the walrus was Paul.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #12 on: May 12, 2016, 06:31:13 PM »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: transparent lisp command
« Reply #13 on: May 12, 2016, 06:35:00 PM »
In before "yellow matter custard".
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Coltm16

  • Guest
Re: transparent lisp command
« Reply #14 on: May 12, 2016, 07:15:46 PM »
Quote
he is me.

I'll have a look tonight if you don't get it resolved .. about 12 hours away.

Thank you, I will not have it figured out by then unless someone posts some more clues.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #15 on: May 13, 2016, 06:09:24 AM »
Sorry, I am not sure what that a rotated (getcorner) is. Here is what I am looking for:

Start the line command, before selecting your first point, shift+right click and use the command modifier "FROM". Now select the basepoint, now for the offset distance, I do not get a "rubberband" that uses polar tracking. I am "blindly" having to select the offset point angle when using direct distance input.

Contrast this with the end point of the line command. If I use the "from" command modifier on the end point, all of a sudden I get to use the rubberband w/ polar tracking when specifying the offset point.

I am trying to make a custom "from" command modifier that uses the rubberband in all circumstances.
...
AutoCAD 2013 (sorry for italian prompt):
---------- inside Command -------------
Comando: LINEA
Specificare primo punto: (ALE_From "ACTIVE")
>>Base point <Lastpoint> <508.85,1028.15,0>:
>>Offset: @25,25
Specificare punto successivo o [Annulla]:
---------- inside Command -------------

---------- nesting inside Command -------------
Comando:  LINEA
Specificare primo punto: (ALE_From "ACTIVE")
>>Base point <Lastpoint> <548.36,1019.7,0>: (ALE_From "ACTIVE")
>>Base point <Lastpoint> <548.36,1019.7,0>: (ALE_From "ACTIVE")
>>Base point <Lastpoint> <548.36,1019.7,0>: @22,22
>>Offset: @11,11
>>Offset: @33,33
>>Offset: @-55,-55
Specificare punto successivo o [Annulla]:
---------- nesting inside Command -------------

---------- inside Lisp -------------
Comando:  CIRCLETEST
Circle center <Lastpoint> <462.53,979.22,0>: (ALE_From nil)
>>Base point <Lastpoint> <462.53,979.22,0>:
>>Offset: @20,20
Circle diameter <9.41>:
---------- inside Lisp -------------

---------- nesting inside Lisp -------------
Comando: CIRCLETEST
Circle center <Lastpoint> <543.33,1047.13,0>: (ALE_From nil)
>>Base point <Lastpoint> <543.33,1047.13,0>: (ALE_From nil)
>>Base point <Lastpoint> <543.33,1047.13,0>: (ALE_From nil)
>>Base point <Lastpoint> <543.33,1047.13,0>:
>>Offset: @11,11
>>Offset: @22,22
>>Offset: @-33,-33
Circle diameter <9.88>:
---------- nesting inside Lisp -------------
Code: [Select]
; [_Button...]^P$M=$(if,$(getvar,cmdactive),(ALE_From """""""ACTIVE"""""""),(ALE_From nil));
(defun ALE_From (CmdAct / BasPtn Pnt001 CurBlp CurOrt)
    (graphscr)
    (setq CurBlp (getvar "BLIPMODE")  CurOrt (getvar "ORTHOMODE"))
    (setvar "BLIPMODE" 1)   (setvar "ORTHOMODE" 0)
    (setq
      BasPtn   (ALE_GetPoint 40 "" ">>Base point <Lastpoint>" (getvar "LASTPOINT") (getvar "LASTPOINT"))
      Pnt001   (ALE_GetPoint 41 "" ">>Offset"  nil BasPtn)
    )
    (setvar "BLIPMODE" CurBlp) (setvar "ORTHOMODE" CurOrt)
    (cond
      ( (and Pnt001 CmdAct) (command "_NONE" Pnt001) (princ) )
      ( Pnt001 )
      ( T (alert "Point not found."     ) (princ) )
    )
)

(defun C:CircleTest (/ Pnt001 EntLas SelSet)
  (setq Pnt001 (ALE_GetPoint 40 "" "Circle center <Lastpoint>" (getvar "LASTPOINT") (getvar "LASTPOINT")))
  (setq #mdist (ALE_GetDist  46 "" "Circle diameter" #mdist Pnt001))
  (command "_.CIRCLE" "_NONE" Pnt001 (/ #mdist 2.0))
  (setvar "LASTPOINT" Pnt001)
  (princ)
)

(defun ALE_GetDist (IGtBit KwdStr PrmStr DefRea BasPtn / InpVal)
  (if DefRea
    (setq
      PrmStr (strcat "\n" PrmStr " <" (rtos DefRea) ">: ")
      IGtBit (logand IGtBit 254)
    )
    (setq PrmStr (strcat "\n" PrmStr ": "))
  )
  (initget IGtBit KwdStr)
  (setq InpVal (if BasPtn (getdist BasPtn PrmStr) (getdist PrmStr)))
  (if InpVal InpVal DefRea)
)
Edit: upoint = ALE_GetPoint

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #16 on: May 13, 2016, 07:23:26 AM »

Bringing it back to minimal basics ...

The following code when compiled as a separate namespace VLX loads and runs in the document it is loaded in without error and as expected.

The command will run either :
from TAC at the command line.
from 'tac transparently during an AutoCAD command.
from 'tac transparently during a lisp function.

The VLX is listed from (vl-list-loaded-vlx)
ie -> (test-ACRX-CMD)

Code to compile :
Code - Auto/Visual Lisp: [Select]
  1. ;;; test-ACRX-CMD.LSP
  2. ;; kdub @ theSwamp 2016.05.13
  3.  
  4. ;;; Workaround for (vlax-add-cmd) bug.
  5. ;;; by Stephan Koster
  6.  
  7. ;; Comments by JRFlemming: This code should be
  8. ;;; run before adding any other commands with vlr-add-cmd.
  9. ;;; Otherwise, when using added commands in multiple documents
  10. ;;; (MDI mode), sometimes the commands fail with a "Visual LISP
  11. ;;; command document mismatch" error. Apparently vlax-add-cmd
  12. ;;; must be called in a document in order to activate commands
  13. ;;; in that document.
  14. (defun DummyCommand () NIL)
  15. (vlax-add-cmd "DummyCommand" 'DummyCommand)
  16. (defun AddCommandsHelper (a b) (vlax-add-cmd "DummyCommand" 'DummyCommand))
  17. ;; Install dummy command reactor only if it's not
  18. ;; defined already
  19. (or *DummyCommandReactor*
  20.     (setq *DummyCommandReactor*
  21.            (vlr-docmanager-reactor
  22.              NIL
  23.              '((:vlr-documentbecamecurrent . AddCommandsHelper))
  24.            )
  25.     )
  26. )
  27. ;;---------------------------------------------------------
  28.  
  29. (defun test:ACRX-CMD () (princ "TEST-COMMAND called"))
  30.  
  31. (vlax-add-cmd "tac" 'test:ACRX-CMD "tac" ACRX_CMD_TRANSPARENT)
  32. ;;---------------------------------------------------------
  33.  

Code to test:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Testtac ( /  p1 p2 )
  2.  
  3.   (setq p1 (getpoint "\nSelect a point:"))
  4.   (prompt
  5.     "\nUse 'tac during this command, before selecting the next Point."
  6.   )
  7.   (setq p2 (getpoint p1 "\nSelect another point:"))
  8.  
  9.   (princ)
  10. )
  11.  
When we load and run the Testtac command we get this, as expected.

Command: TESTTAC
Select a point:
Use 'tac during this command, before selecting the next Point.
Select another point:'tac
TEST-COMMAND called
Resuming TESTTAC command.
Select another point:(3917.36 2685.2 0.0)
Command:



Now, when we open another document, the TAC command is registered and available at the command line ..
but ;
returns
Command: TAC
; error: Visual LISP command document mismatch: tac


When we load and run the Testtac command we get this.

Command:
TESTTAC
Select a point:
Use 'tac during this command, before selecting the next Point.
Select another point:'tac
xError: Visual LISP command document mismatch: tac
Backtrace:
:ERROR-BREAK.6 "Visual LISP command document mismatch: tac"
:ARQ-CMD-CALLBACK.3 (nil 2)
Resuming TESTTAC command.
Select another point:(2643.28 3509.62 0.0)
Command:



This has been tested in AutoCAD 2016.

From my research  this Visual LISP command document mismatch has been an issue since 1999.
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vlax-add-cmd-in-mdi-mode/td-p/889283

And numerous similar queries.

Does anyone have a resolution for this problem ...
It would be nice to get some response from AutoDesk regarding this.

Regards,
Kerry.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #17 on: May 13, 2016, 07:42:23 AM »

For anyone who is more comfortable posting on the AutoDesk Discussion Forum I've started a thread here:
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/regarding-error-visual-lisp-command-document-mismatch/td-p/6324669
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Coltm16

  • Guest
Re: transparent lisp command
« Reply #18 on: May 13, 2016, 07:49:09 AM »
Kdub, thank you for your time and research. Looks like we will just try again in 17 years and see if anything has changed.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #19 on: May 13, 2016, 07:57:52 AM »

It's frustrating because I'd thought I had this working about 12 or so years ago ... I used a lot of Separate Namespace apps back then.
It might just be oldtimers syndrome.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: transparent lisp command
« Reply #20 on: May 13, 2016, 09:38:47 AM »
Hi Marc'Antonio,
For some reason this method has not been working for me since AutoCAD 2009 I think. ...
I do not quite understand what you mean, have you tried my functions?
I am using in all versions of AutoCAD/Bricscad since it was introduced the bit 128 for initget (maybe 1990).
Try to make the two buttons:
[_Button("« Middle Point", YourIcon, YourIcon)]^P$M=$(if,$(getvar,cmdactive),(ALE_MidPoint """""""ACTIVE"""""""),(ALE_MidPoint nil));
[_Button("« Progressive Distance", YourIcon2, YourIcon2)]^P$M=$(if,$(getvar,cmdactive),(ALE_DistPr """""""ACTIVE"""""""),(ALE_DistPr nil));
and test ALE_MidPoint or ALE_DistPr inside a command or AutoLisp function.

Hi Marc - Yes I tried your functions. What I specifically was attempting was the command line transparent command that you added with (vlax-add-cmd). I still have the same problem as the OP. Your buttons don't use the command line shortcut.
"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

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: transparent lisp command
« Reply #21 on: May 13, 2016, 09:45:13 AM »

It's frustrating because I'd thought I had this working about 12 or so years ago ... I used a lot of Separate Namespace apps back then.
It might just be oldtimers syndrome.

Hi kdub,

The reactor method by Stephan Kostar back in 1999 solved the problem for me and the commands I defined worked until about Acad 2009 roughly (put them on the back burner and I can't remember for sure when now it stopped working). Looks like I'll have to compile to separate namespace VLX to make them work now. Wanted to avoid that if possible.

EDIT: Oh - I see now you have the same issue even from a separate namespace VLX? Grrrr.
« Last Edit: May 13, 2016, 09:59:17 AM by PKENEWELL »
"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

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: transparent lisp command
« Reply #22 on: May 13, 2016, 10:14:51 AM »
I can see others have not been able to get a reply to this either:
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/visual-lisp-command-document-mismatch-xlax-add-cmd-error-again/m-p/3168248/highlight/true#M299317

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/custom-zoom-window/m-p/2960566/highlight/true#M295500

I have to make my own apologies for the Adesk Forums. I wasn't checking them for a long time (was working on Solidworks for a while), and didn't see these others before. Not that I could've helped - still stumped in this issue myself.  :x
"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

PKENEWELL

  • Bull Frog
  • Posts: 317
« Last Edit: May 13, 2016, 11:06:07 AM by PKENEWELL »
"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

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #24 on: May 13, 2016, 11:44:34 AM »
Hi Marc - Yes I tried your functions. What I specifically was attempting was the command line transparent command that you added with (vlax-add-cmd). I still have the same problem as the OP. Your buttons don't use the command line shortcut.
Honestly now I can not get my example with "vla-SendCommand", maybe I am way off base... 8-) I'll try again but I'm not very motivated because I saw that in Bricscad there are other problems with (vlax-add-cmd ...).

The OP not ask for command line shortcut but:
"I am trying to make a custom "from" command modifier that uses the rubberband in all circumstances."
Why you can not use a button instead of the command line?

Here is another example that is closer to the OP request (no add-cmd)
Code: [Select]
(defun ALE_Track (CmdAct / BasPtn Pnt001 CurBlp CurOrt)
    (graphscr)
    (setq CurBlp (getvar "BLIPMODE")  CurOrt (getvar "ORTHOMODE"))
    (setvar "BLIPMODE" 1)   (setvar "ORTHOMODE" 1)
    (setq
      BasPtn   (ALE_GetPoint 40 "" ">>Base point <Lastpoint>" (getvar "LASTPOINT") (getvar "LASTPOINT"))
      Pnt001   (ALE_GetPoint -88 "" ">>Distance"  nil BasPtn)
    )
    (setvar "BLIPMODE" CurBlp) (setvar "ORTHOMODE" CurOrt)
    (cond
      ( (and Pnt001 CmdAct) (command "_NONE" Pnt001) (princ) )
      ( Pnt001 )
      ( T (alert "Point not found."     ) (princ) )
    )
)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #25 on: May 13, 2016, 12:19:16 PM »
Here is the command line test:
Code: [Select]
(defun ALE_TR ( )
  (vla-SendCommand *acDoc* "!(ALE_Track \"ACTIVE\") ")
)
(vlax-add-cmd "tr" 'ALE_TR  "tr" 1)
Command: L LINE
Specify first point: 'tr
Resuming LINE command.
Specify first point: !(ALE_Track "ACTIVE")
>>Base point <Lastpoint> <139.32,394.28,0>:
>>Offset:
Specify next point or [Undo]:

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #26 on: May 13, 2016, 01:13:09 PM »
In Bricscad we need a "\n" inside "(ALE_Track \"ACTIVE\")\n" instead of space, works in AutoCAD also.

Inside Lisp we do not need "!" before:
Code: [Select]
(defun ALE_TL ( )
  (vla-SendCommand *acDoc* "(ALE_Track \"ACTIVE\")\n")
)
(vlax-add-cmd "tl" 'ALE_TL  "tl" 1)
Quote
Comando: CIRCLETEST
Circle center <Lastpoint> <191.56,101.55,0>: 'tl
Ripresa del comando CIRCLETEST.
Circle center <Lastpoint> <191.56,101.55,0>: (ALE_Track "ACTIVE")
>>Base point <Lastpoint> <191.56,101.55,0>:
>>Offset:
Circle diameter <31.6>:

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #27 on: May 13, 2016, 01:27:17 PM »
Here is the command line test:
Code: [Select]
(defun ALE_TR ( )
  (vla-SendCommand *acDoc* "!(ALE_Track \"ACTIVE\") ")
)
(vlax-add-cmd "tr" 'ALE_TR  "tr" 1)
Command: L LINE
Specify first point: 'tr
Resuming LINE command.
Specify first point: !(ALE_Track "ACTIVE")
>>Base point <Lastpoint> <139.32,394.28,0>:
>>Offset:
Specify next point or [Undo]:

Marc'Antonio

Are you saying you can get that to work in multiple documents from the command line ??

Which version of  ALE_Track are you using in AutoCAD ?

Regards,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: transparent lisp command
« Reply #28 on: May 13, 2016, 01:32:04 PM »
In Bricscad we need a "\n" inside "(ALE_Track \"ACTIVE\")\n" instead of space, works in AutoCAD also.

Inside Lisp we do not need "!" before:

Have you tried opening a 2nd drawing in the same session and testing if the command still works? That's the problem is it doesn't work if you open a 2nd drawing in the same session.

If the OP just wanted a button I don't think it would be an issue. I was under the impression that he also wanted a transparent command that you can use with ( ' ) in front of it. The whole point of my replies is that there used to be a working method for this - but it doesn't work anymore. (vlax-add-cmd) does not want to function in MDI mode.
"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

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #29 on: May 13, 2016, 06:07:41 PM »
Marc'Antonio
Are you saying you can get that to work in multiple documents from the command line ??
Which version of  ALE_Track are you using in AutoCAD ?
#1: Yes but with this version:
Code: [Select]
(defun ALE_TR ( / obj)
  (setq obj (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-SendCommand obj "!(ALE_Track \"ACTIVE\")\n")
  (vlax-release-object obj)
)
#2: this (prompt "Distance" was "Offset" but the function is the same):
Code: [Select]
(defun ALE_Track (CmdAct / BasPtn Pnt001 CurBlp CurOrt)
    (graphscr)
    (setq CurBlp (getvar "BLIPMODE")  CurOrt (getvar "ORTHOMODE"))
    (setvar "BLIPMODE" 1)   (setvar "ORTHOMODE" 1)
    (setq
      BasPtn   (ALE_GetPoint 40 "" ">>Base point <Lastpoint>" (getvar "LASTPOINT") (getvar "LASTPOINT"))
      Pnt001   (ALE_GetPoint -88 "" ">>Distance"  nil BasPtn)
    )
    (setvar "BLIPMODE" CurBlp) (setvar "ORTHOMODE" CurOrt)
    (cond
      ( (and Pnt001 CmdAct) (command "_NONE" Pnt001) (princ) )
      ( Pnt001 )
      ( T (alert "Point not found."     ) (princ) )
    )
)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #30 on: May 13, 2016, 06:09:57 PM »
Have you tried opening a 2nd drawing in the same session and testing if the command still works? That's the problem is it doesn't work if you open a 2nd drawing in the same session.

If the OP just wanted a button I don't think it would be an issue. I was under the impression that he also wanted a transparent command that you can use with ( ' ) in front of it. The whole point of my replies is that there used to be a working method for this - but it doesn't work anymore. (vlax-add-cmd) does not want to function in MDI mode.
See #1 on previous post


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #31 on: May 13, 2016, 06:40:25 PM »
This version works AutoCAD/Bricscad command line or Lisp, nesting more transparent commands only in Lisp+AutoCAD:
Code: [Select]
(defun ALE_TR ( / obj)
  (setq obj (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (eq 3 (getvar 'CMDACTIVE))
    (vla-SendCommand obj "!(ALE_Track \"ACTIVE\")\n")
    (vla-SendCommand obj "(ALE_Track nil)\n")
  )
  (vlax-release-object obj)
)
The only problem in Bricscad is vlax-remove-cmd get error if cmd is not definited also with vl-catch-all-apply:
(vl-catch-all-apply 'vlax-remove-cmd (list "tr"))

Is too late in Italy, good nigth.  :-)

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #32 on: May 13, 2016, 10:36:44 PM »
Hi Marc'Antonio,

Can you confirm you are able to
open a new drawing, load your routines, run the commands.
then,
open a new drawing in the same session and load the necessary files, then run the commands.
then,
switch to the first drawing in the session and run the commands.

ie: typical MDI operations.

if you can do this without error could you advise the load sequence/procedure for the files you are using (into the initial and subsequent drawings) please.

Are you compiling as VLX ? if so what are you compiling and with which switches ?


I'm ignoring for the moment that you are using a 'command' function in your code.
From the Help docs for vlax-add-cmd :

Caution: You cannot use the command function call in a transparently defined vlax-add-cmd function. Doing so can cause AutoCAD to close unexpectedly.


Thanks
Regards,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #33 on: May 14, 2016, 01:33:13 AM »
Hi Marc'Antonio, can you confirm you are able to open a new drawing, load your routines, run the commands.
Yes.

Quote
then, open a new drawing in the same session and load the necessary files, then run the commands.
Yes.

Quote
then, switch to the first drawing in the session and run the commands. ie: typical MDI operations.
if you can do this without error could you advise the load sequence/procedure for the files you are using (into the initial and subsequent drawings) please.
Yes, but, at this moment, ONLY if I reload ALE_AddCommand.lsp (see below).

Quote
Are you compiling as VLX ? if so what are you compiling and with which switches?
Sorry, not tested.  :-(

Code: [Select]
; ALE_AddCommand.lsp
;
(vlax-remove-cmd "tr")
(vlax-add-cmd "tr" 'ALE_TR  "tr" 1)
;
(defun ALE_TR ( / obj) ; version 1.00
  (setq obj (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (eq 3 (getvar 'CMDACTIVE))
    (vla-SendCommand obj "!(ALE_Track \"ACTIVE\")\n")
    (vla-SendCommand obj "(ALE_Track nil)\n")
  )
  (vlax-release-object obj)
)

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #34 on: May 14, 2016, 02:02:59 AM »

Thanks,
So you haven't solved the problem. Having to reload the file each time we access a drawing that we've accessed previously in the same session is not an 'ideal' situation.

Thanks again for the time and effort.

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #35 on: May 14, 2016, 02:18:36 AM »

Thanks,
So you haven't solved the problem. Having to reload the file each time we access a drawing that we've accessed previously in the same session is not an 'ideal' situation.

Thanks again for the time and effort.
Perhaps it is a step more toward the solution... Until now only in Bricscad works, any ideas?  :idea:

Code: [Select]
; ALE_AddCommand.lsp ; version 1.01 - modified for Bricscad
;
; AutoCAD : need to be reloaded if switch to existing drawing where is already loaded
;
; Bricscad: does not need to be reloaded
;
;
(if (= (getvar "PRODUCT") "Bricscad")
  (vlax-add-cmd "tr" 'ALE_TR  "tr" 1)
  (progn
    (vlax-remove-cmd "tr")
    (vlax-add-cmd "tr" 'ALE_TR  "tr" 1)
  )
)
;
(defun ALE_TR ( / obj) ; version 1.00
  (setq obj (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (eq 3 (getvar 'CMDACTIVE))
    (vla-SendCommand obj "!(ALE_Track \"ACTIVE\")\n")
    (vla-SendCommand obj "(ALE_Track nil)\n")
  )
  (vlax-release-object obj)
)

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: transparent lisp command
« Reply #36 on: May 14, 2016, 02:33:29 AM »
Just to poke a stick in the sand for posterity ...

\\kwb_Archive\e_develop\_INFO\_Storage\Vital_LISP_Help_3x\Apps\Vital_LISP\VILL30\SAMPLES\RCTR-TST.lsp
Tuesday, ‎July ‎1, ‎1997, ‏‎07:40:42

That is from Vital Lisp 3.0 before AutoDesk purchased it from Basis.

It worked then ... perhaps :)

Code - Auto/Visual Lisp: [Select]
  1. ;;;;;;; start-up initialisation
  2.  
  3. ;;; Prevent code re-loading
  4. (setq *VILL-NEW-FULL-INIT* NIL)
  5.  
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7. (vlax-add-cmd "rctr-tst" 'rctr-tst)
  8.  
  9.  
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; register application
  11.  
  12. (vlax-regapp
  13.   (strcat "SOFTWARE\\Basis Software\\Vital Lisp\\"
  14.           (_vill-version)
  15.           "\\rctr-tst" )
  16.   '("rctr-tst")
  17.   13
  18.   )
  19.  
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; print information
  21.  
  22. (princ "\n; Type RCTR-TST to start test\n")
  23.  
  24. ;;EOF
  25.  
  26.  
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #37 on: May 14, 2016, 05:41:52 AM »
Thanks,
So you haven't solved the problem. Having to reload the file each time we access a drawing that we've accessed previously in the same session is not an 'ideal' situation.
Thanks again for the time and effort.
I do not really like reactors but this seems to work (see attachments):
Code: [Select]
(and
  (/= (getvar "PRODUCT") "Bricscad")
  (not #DocumentReactor)
  (setq #DocumentReactor
    (vlr-docmanager-reactor
       nil
     '(
        (:vlr-documenttobeactivated . ALE_LoadAddCommand)
        (:vlr-documenttobedestroyed . ALE_CleanReactor)
      )
    )
  )
)
;
(defun ALE_LoadAddCommand (r d)
; (print ">>Loading ALE_AddCommand<<")
  (load "Z:/Temp/ALE_AddCommand.lsp");modify this
  (princ)
)
(defun ALE_CleanReactor (r d)
  (mapcar 'VLR-remove (list #DocumentReactor))
  (setq #DocumentReactor nil)
  (princ)
)

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: transparent lisp command
« Reply #38 on: May 16, 2016, 10:36:00 AM »
I do not really like reactors but this seems to work (see attachments):

Marc'Antonio,

WOW! I applied your method to my original functions i.e. removing the commands with (vlax-remove-cmd) before redefining them with (vlax-add-cmd) within the ":vlr-documenttobeactivated" reactor and IT WORKS! What I cannot understand is I have tried to employ this previously, but from within the same (mapcar) loop and I caused an error. Apparently it seems to work if the (mapcar) loops are separated.

THANK YOU!!!  :-D

So here's my modified code from the original method:

Code - Auto/Visual Lisp: [Select]
  1. ;|==============================================================================
  2.   Function Name: (pjk-AddMDICmd)
  3.   Arguments: <Command List> = List of lists in the format (list (list "<Global Command Name>" '<Function Name> "[Local Command Name]" [Cmd-Flags]))
  4.                 Sub-list Arguments:
  5.                 <Global Command Name> = String for the Name of the Command
  6.                 <Function Name> = Quoted symbol for the autolisp function to run
  7.                 [Local Command Name] = String (opt.) for the Name of the command - usually same as global name
  8.                 [Cmd-Flags] = Integer Bit Flag for Command Behaivior - Bits are as follows:
  9.                    0 = ACRX_CMD_MODAL; Command cannot be invoked while another command is active.
  10.                    1 = ACRX_CMD_TRANSPARENT; Command can be invoked while another command is active.
  11.                    2 = ACRX_CMD_USEPICKSET;When the pickfirst set is retrieved it is cleared within AutoCAD.
  12.                        Command will be able to retrieve the pickfirst set. Command cannot retrieve or set grips.
  13.                    4 = ACRX_CMD_REDRAW; When the pickfirst set or grip set is retrieved, neither will be cleared within AutoCAD.
  14.                        Command can retrieve the pickfirst set and the grip set.
  15.                        
  16.   Usage: (pjk-AddMDICmd <Command List>)
  17.   Returns: N/A
  18.   Description:
  19.                 This command defines a list of functions as AutoCAD Commands
  20.                 that are MDI aware. First the Commands are undefined if they
  21.                 already exist in the ObjectARX enviroment. Then, a document
  22.                 manager reactor is established to test if another document has
  23.                 become active and redefines the commands in the active document.
  24.                 This function can only be called once for Each drawing opened to
  25.                 establish the Command list and functions. then the reactor does the
  26.                 work.
  27.                 *** Original Author: Stephan Koster - 1999 ***
  28. ================================================================================|;
  29. (defun pjk-AddMDICmd (lst / old)
  30.         (foreach x (setq PJK:commandslist lst)
  31.                 (vlax-remove-cmd (car x))
  32.         )
  33.       (if (= "PJK-Commands" (vlr-data obj))(vlr-remove obj))
  34.    )
  35.    (vlr-docmanager-reactor "PJK-Commands" '((:vlr-documentBecameCurrent . pjk-CmdRedef)))
  36.         (pjk-CmdRedef nil nil)
  37. ) ;; End Function (pjk-AddMDICmd)
  38.  
  39. ;|==============================================================================
  40.   Function Name: (pjk-CmdRedef)
  41.   Arguments:
  42.   Usage: (pjk-CmdRedef [Reactor Callback][Command Info])
  43.   Returns: A list of the results of the vlax-add-cmd call - length depends on the command list defined in PJK:Commandslist
  44.            Example: given 4 commands to be defined - '(T T T T) if all commands were defined correctly.
  45.   Description:
  46.                 This Function is a reactor callback function for (pjk-addMDIcmd),
  47.                 or can be called alone with both arguments set to NIL. If the
  48.                 global variable PJK:COMMANDSLIST is defined, it will use it
  49.                 to create AutoCAD Commands with (vlax-add-cmd).
  50.   *** Original Author: Stephan Koster - 1999 ***
  51.    Update 5/16/2016: Added (mapcar) loop to undefined the commands prior to redefining them. This corrects an issue that
  52.                                caused the original function not to work correctly since AutoCAD 2009 (I think).
  53.                                THANKS to Marc'Antonio Alessi for the method!
  54. ================================================================================|;
  55. (defun pjk-CmdRedef (calbck cmd)
  56.    (mapcar
  57.       (function
  58.          (lambda (x)
  59.             (vlax-remove-cmd (car x))
  60.          )
  61.       )
  62.       PJK:commandslist
  63.    )
  64.    (mapcar
  65.       (function
  66.          (lambda (x / ok)
  67.             (if (and
  68.                    (member (type (eval (cadr x))) '(SUBR USUBR EXRXSUBR))
  69.                    (setq ok (apply 'vlax-add-cmd x))
  70.                          )
  71.                 ok
  72.                 )
  73.          )
  74.       )
  75.       PJK:commandslist
  76.    )
  77. ) ;; End Function (pjk-CmdRedef)
  78.  

Test Code:

Code - Auto/Visual Lisp: [Select]
  1. ;|==============================================================================
  2.   Function Name: (pjk-zw)
  3.   Arguments: NONE
  4.   Usage: (pjk-zw)
  5.   Description:
  6.                 ActiveX Zoom Command to emulate Zoom > Window. This
  7.                 function definition is used to define the "ZW" command
  8.                 with (pjk-addmdicmd)
  9. ================================================================================|;
  10. (defun pjk-zw ( / thisdwg)
  11.         (vla-sendcommand thisdwg "'._zoom _w ")
  12.         (vlax-release-object thisdwg)
  13.         (princ)
  14. ) ;; End Function (pjk-zw)
  15.  
  16. ;; Add the command(s) using (pjk-addMDICmd)
  17. (pjk-AddMDICmd
  18.    (list (list "ZW"  'pjk-zw     "ZW" 1))
  19. )
  20.  
"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

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: transparent lisp command
« Reply #39 on: May 16, 2016, 04:52:44 PM »
I do not really like reactors but this seems to work (see attachments):

Marc'Antonio,

WOW! I applied your method to my original functions i.e. removing the commands with (vlax-remove-cmd) before redefining them with (vlax-add-cmd) within the ":vlr-documenttobeactivated" reactor and IT WORKS! What I cannot understand is I have tried to employ this previously, but from within the same (mapcar) loop and I caused an error. Apparently it seems to work if the (mapcar) loops are separated.

THANK YOU!!!  :-D
...
Prego!  :-) :-) :-)

hawstom

  • Newt
  • Posts: 22
  • AutoCAD Civil 3D, Mesa, AZ, USA
Re: transparent lisp command
« Reply #40 on: March 08, 2017, 03:40:39 PM »
I just verified this does work.  Extensive testing in AutoCAD 2016.  Multiple cases and scenarios are listed below with conclusions at the very end.

Code - Auto/Visual Lisp: [Select]
  1. ;|==============================================================================
  2.   Function Name: (pjk-AddMDICmd)
  3.   Arguments: <Command List> = List of lists in the format (list (list "<Global Command Name>" '<Function Name> "[Local Command Name]" [Cmd-Flags]))
  4.                 Sub-list Arguments:
  5.                 <Global Command Name> = String for the Name of the Command
  6.                 <Function Name> = Quoted symbol for the autolisp function to run
  7.                 [Local Command Name] = String (opt.) for the Name of the command - usually same as global name
  8.                 [Cmd-Flags] = Integer Bit Flag for Command Behaivior - Bits are as follows:
  9.                    0 = ACRX_CMD_MODAL; Command cannot be invoked while another command is active.
  10.                    1 = ACRX_CMD_TRANSPARENT; Command can be invoked while another command is active.
  11.                    2 = ACRX_CMD_USEPICKSET;When the pickfirst set is retrieved it is cleared within AutoCAD.
  12.                        Command will be able to retrieve the pickfirst set. Command cannot retrieve or set grips.
  13.                    4 = ACRX_CMD_REDRAW; When the pickfirst set or grip set is retrieved, neither will be cleared within AutoCAD.
  14.                        Command can retrieve the pickfirst set and the grip set.
  15.                        
  16.   Usage: (pjk-AddMDICmd <Command List>)
  17.   Returns: N/A
  18.   Description:
  19.                 This command defines a list of functions as AutoCAD Commands
  20.                 that are MDI aware. First the Commands are undefined if they
  21.                 already exist in the ObjectARX enviroment. Then, a document
  22.                 manager reactor is established to test if another document has
  23.                 become active and redefines the commands in the active document.
  24.                 This function can only be called once for Each drawing opened to
  25.                 establish the Command list and functions. then the reactor does the
  26.                 work.
  27.                 *** Original Author: Stephan Koster - 1999 ***
  28. ================================================================================|;
  29. ;|
  30. (defun pjk-AddMDICmd (lst / old)
  31.         (foreach x (setq PJK:commandslist lst)
  32.                 (vlax-remove-cmd (car x))
  33.         )
  34.    (foreach obj (cdar (vlr-reactors :vlr-docmanager-reactor))
  35.       (if (= "PJK-Commands" (vlr-data obj))(vlr-remove obj))
  36.    )
  37.    (vlr-docmanager-reactor "PJK-Commands" '((:vlr-documentBecameCurrent . pjk-CmdRedef)))
  38.         (pjk-CmdRedef nil nil)
  39. ) ;; End Function (pjk-AddMDICmd)
  40. |;
  41. ;|==============================================================================
  42.   Function Name: (pjk-CmdRedef)
  43.   Arguments:
  44.   Usage: (pjk-CmdRedef [Reactor Callback][Command Info])
  45.   Returns: A list of the results of the vlax-add-cmd call - length depends on the command list defined in PJK:Commandslist
  46.            Example: given 4 commands to be defined - '(T T T T) if all commands were defined correctly.
  47.   Description:
  48.                 This Function is a reactor callback function for (pjk-addMDIcmd),
  49.                 or can be called alone with both arguments set to NIL. If the
  50.                 global variable PJK:COMMANDSLIST is defined, it will use it
  51.                 to create AutoCAD Commands with (vlax-add-cmd).
  52.   *** Original Author: Stephan Koster - 1999 ***
  53.    Update 5/16/2016: Added (mapcar) loop to undefined the commands prior to redefining them. This corrects an issue that
  54.                                caused the original function not to work correctly since AutoCAD 2009 (I think).
  55.                                THANKS to Marc'Antonio Alessi for the method!
  56. ================================================================================|;
  57. ;|
  58. (defun pjk-CmdRedef (calbck cmd)
  59.    (mapcar
  60.       (function
  61.          (lambda (x)
  62.             (vlax-remove-cmd (car x))
  63.          )
  64.       )
  65.       PJK:commandslist
  66.    )
  67.    (mapcar
  68.       (function
  69.          (lambda (x / ok)
  70.             (if (and
  71.                    (member (type (eval (cadr x))) '(SUBR USUBR EXRXSUBR))
  72.                    (setq ok (apply 'vlax-add-cmd x))
  73.                          )
  74.                 ok
  75.                 )
  76.          )
  77.       )
  78.       PJK:commandslist
  79.    )
  80. ) ;; End Function (pjk-CmdRedef)
  81. |;
  82. (defun c:vt () (alert "This is a test of VLX private."))
  83. (vl-acad-defun 'vte)
  84. (defun vte () (alert "This is a test of VLX export non-command."))
  85. (vl-acad-defun 'c:vtec)
  86. (defun c:vtec () (alert "This is a test of VLX export command."))
  87. ;;; Test results:  2017-03-08 Compiled to VLX with optimize and link.  
  88. ;;; Drag into dwg 1: All the above worked
  89. ;;; Open dwg 2.  None work.
  90. ;;; Drag into dwg 2. All work.
  91. ;|
  92. (vlax-add-cmd "VT" 'c:vt)
  93. (vlax-add-cmd "VTE" 'vte)
  94. (vlax-add-cmd "VTEC" 'c:vtec)
  95. |;
  96. ;;; Added above declarations.
  97. ;;; Test results:  2017-03-08 Compiled to VLX with optimize and link (and separate namespace).  
  98. ;;; Drag into dwg 1: All worked including (command "vtec") etc.
  99. ;;; Drag into dwg 2: All give "; error: Visual LISP command document mismatch:"
  100. ;|
  101. (pjk-AddMDICmd
  102.   (list
  103.     (list "VT"  'c:vt)
  104.     (list "VTE"  'vte)
  105.     (list "VTEC"  'c:vtec)
  106.   )
  107. )
  108. |;
  109. ;;; Added above from https://www.theswamp.org/index.php?topic=51409.msg565523#msg565523
  110. ;;; Test results: 2017-03-08
  111. ;;; Compiled to VLX with optimize and link (and separate namespace).
  112. ;;; Drag into dwg 1: All worked.
  113. ;;; Opened dwg 2.  None worked.  Dragged in.  All worked.
  114. ;;; Switched to dwg 1: All worked!
  115. (defun vtp ()(alert "This was supposed to be private"))
  116. (defun vtpc () (vtp))
  117. ;;; Added above to test private functions
  118. ;;; Test results 2017-03-08
  119. ;;; Drag into dwg 1: All previous worked.  vtp and vtpc didn't work.  Yay!
  120. ;;; Switch to dwg 2: All same behavior.  No extra load needed.  One load works in all docs.
  121. ;;; Open dwg 3: ; error: Visual LISP command document mismatch: VT
  122. ;;; Load vlx: All works as desired.
  123. ;;; Add vlx to Appload Startup suite.  Restart AutoCAD. Caused AutoCAD crash on restart.
  124. ;;; Commented out pjk functions, reverting to vlax-add-cmd.
  125. ;;; Started AutoCAD.  All worked as desired.  
  126. ;;;   Opened drawing 2.  ; error: Visual LISP command document mismatch: VTE etc.
  127. ;;
  128. ;;; Reverted to pjk functions.  Restarted AutoCAD.  Worked in dwg1.  Worked in dwg2.
  129. ;;;  Switched to dwg 1. All worked.
  130. ;;; Removed both pjk and vlax-add-cmd calls.  Left vlx in startup suite.  
  131. ;;;  vl-acad-defun works (privates were private and publics were public).
  132. ;;; Removed vlx from startup suite.  Caused AutoCAD crash on restart (just like when I added it).
  133. ;;; On restart, dragged vlx into one drawing after another. All works as desired.(vtP)
  134. ;;; Conclusion: To control exporting exposing Visual Lisp functions, use a single VLX.
  135. ;;;  To export the commands to *native" AutoCAD commands (command "My_command"),
  136. ;;;  use the PJK functions and load in each drawing.
  137.  
Not so terse now.  You may not feel so clever in 6 months or years.  http://lisp-lang.org/style-guide/
hawsedc.com, and autocad.wikia.com

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: transparent lisp command
« Reply #41 on: April 04, 2017, 06:35:31 PM »
Hi Hawstom,

Thanks for the test work. Enlightening! I generally just make code for my own use so I sometimes don't test scenarios that I am not using.
"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