Author Topic: transparent lisp command  (Read 15581 times)

0 Members and 1 Guest are viewing this topic.

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) )
    )
)