Lukepeanuts 发表于 2022-7-5 17:04:35

Lisp: Copy in the space and pa

Im working in my second lisp. Its a very simple series of commands: with some objects rotate in a random space, the idea is to put the ucs with a face of the objects, copy them, return in the world ucs and paste the original objets oriented in the world ucs.
 
My first lisp was this:
 

(DEFUN c:CW ( / P1 P2 P3 ) (SETQ P1 (GETPOINT "\nSelect first UCS point")) (SETQ P2 (GETPOINT "\nSelect second UCS point")) (SETQ P3 (GETPOINT "\nSelect third UCS point")) ;click the 3 ucs points                 (command "_ucs" "_3p" "_non" P1 "_non" P2 "_non" P3) ; rotate the ucs in the objects plane        (command "_select" pause ) ; select objects to copy                 (command "_copyclip" "_p" "" )        (command "_ucs" "_w") ; return in world ucs                 (command "_pasteclip" ) ; paste objects in the world ucs(PRINC) )
 
but the paste objets is not close to the insert point of the paste command. To solve it i was thinking to use the "copybase" command in this way:
 

(DEFUN c:CW1 ( / P1 P2 P3 P4 P5 ) (SETQ P1 (GETPOINT "\nSelect first UCS point")) (SETQ P2 (GETPOINT "\nSelect second UCS point")) (SETQ P3 (GETPOINT "\nSelect third UCS point")) ;click the 3 ucs points (SETQ P4 (GETPOINT "\nSelect base point of the copy objects")) ;click the base point                (command "_ucs" "_3p" "_non" P1 "_non" P2 "_non" P3) ; rotate the ucs in the objects plane        (command "_select" pause ) ; select objects to copy                 (command "_copybase" "_non" P4 "_p" "" )        (command "_ucs" "_w") ; return in world ucs(SETQ P5 (GETPOINT "\nSelect base point to paste the objects")) ;click the base point                 (command "_pasteclip" "_non" P5 ) ; paste objects in the world ucs(PRINC) )
 
but when i paste the objects are invisible and i paste them in a custom position in the layer (also if its asking me the base point in the copybase command.
 
Im a rookie, i must forgive something, so i will be glad for any help.

Lee Mac 发表于 2022-7-5 17:28:57

A coordinate transformation is required:

(defun c:cw2 ( / bpt pt1 pt2 pt3 sel )   (and (setq sel (ssget))      (setq pt1 (getpoint "\nSpecify 1st UCS point: "))      (setq pt2 (getpoint "\nSpecify 2nd UCS point: "))      (setq pt3 (getpoint "\nSpecify 3rd UCS point: "))      (setq bpt (getpoint "\nSpecify basepoint: "))      (setq bpt (trans bpt 1 0))      (command            "_.ucs" "_3p" "_non" pt1 "_non" pt2 "_non" pt3            "_.copybase" "_non" (trans bpt 0 1) sel ""            "_.ucs" "_w"            "_.pasteclip" "\\"      )   )   (princ))

Lukepeanuts 发表于 2022-7-5 18:03:42

 
thanks a lot, i will study the transormation.
If you could also answer me about some doubts about your lisp i willa appreciate a lot:
 
1 - at the beginning you put an (and) with all inside. Why? The meaning?
2 - I was repeating a (command) with all my autocad commads, and you only put one for all. With only one (command), works better or is it only a way to do it more compact?
3 - The pasteclip command is with a "\\" that i dont understand. Also because i dont see a getpoint to insert the paste. What will it happen if i will put another command below the pasteclip?

Lee Mac 发表于 2022-7-5 18:08:30

 
Please see the explanation in this post.
 
 
There may be a negligible improvement to performance by reducing the number of command expressions, but ultimately, only one command expression is required and so there is no need for more.
 
 
The backslash (note that a single backslash is represented by "\\" in AutoLISP, as "\" is an Escape Character) is the macro operator for "pause for user input"; you can alternatively use the 'pause' symbol, but this is not a protected symbol and thus has the potential to be redefined.
页: [1]
查看完整版本: Lisp: Copy in the space and pa