Author Topic: transparent lisp command  (Read 15557 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.