Change layers when command is finished!

Change layers when command is finished!

Anonymous
Not applicable
1,172 Views
9 Replies
Message 1 of 10

Change layers when command is finished!

Anonymous
Not applicable

 

(defun C:TH ()

 

(setq A (getpoint "\n Specify first corner of rectangle: "))
(initget (+ 1 2 4))
(setq B (getreal "\n Specify length: "))
(initget (+ 1 2 4))
(setq C (getreal "\n Specify width: "))


(initget (+ 1 2 4))
(setq L1 (getreal "\n Offset from the left side: "))
(initget (+ 1 4))
(setq L2 (getreal "\n Offset from first circle: "))


(initget (+ 1 2 4))
(initget 0 "Piasu Ponchi")
(setq F (getreal "\n Specify diameter or [Piasu/Ponchi]: "))

 

(setvar "cmdecho" 0)
(setq osv (getvar "osmode"))
(setvar "osmode" 0)

 

(setq A2 (polar A 0 B))
(setq A3 (polar A2 (/ pi 2) C))
(setq A4 (polar A (/ pi 2) C))

(setq A5 (polar A 0 L1))
(setq C1 (polar A5 (/ pi 2) (/ C 2)))
(setq C2 (polar C1 0 L2))


(command "CLAYER" "11")
(command ".pline" A A2 A3 A4 "close")
(setvar "regenmode" 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (= (numberp F) T)
(command ".circle" C1 "_d" F "" ".circle" C2 "_d" F "")
(progn
(cond
((eq F "Piasu") ((command "CLAYER" "66") (command ".point" C1 "" ".point" C2 "") (command "CLAYER" "11")))
((eq F "Ponchi") ((command "CLAYER" "33") (command ".point" C1 "" ".point" C2 "") (command "CLAYER" "11")))
)
)
(setvar "osmode" osv)
(setvar "cmdecho" 1)
)
)

------------------------------------------
Draw rectangle with 2 holes (2 points), when I choose Piasu(a point) it will make a point with layer 66(mylayer), and Ponchi(a point) it will make a point with layer 33(mylayer), I have tried my codes but it is error at create (Piasu and Ponchi), After change to layer 33 or 66 it will set currentlayer is 11. Is there wrong with my lisp?

0 Likes
Accepted solutions (1)
1,173 Views
9 Replies
Replies (9)
Message 2 of 10

Sea-Haven
Mentor
Mentor
Accepted solution

Look at the iniget it uses a character to allow shorthand entry like p you have 2 "P" try 

 

 

(initget 0 "Piasu pOnchi")
(setq F (getreal "\n Specify diameter or [Piasu/ponchi]: ")

 

 

 dont need (initget + 1 2 4)  as reset next line

 

 

 

(defun C:TH ( / a b c l1 l2 c1 c2 osv curl)

(defun las (la / )(setvar 'clayer la))

(setq curl (getvar 'clayer))
(setq osv (getvar 'osmode))

(setq A (getpoint "\n Specify first corner of rectangle: "))
(initget (+ 1 2 4))
(setq B (getreal "\n Specify length: "))
(initget (+ 1 2 4))
(setq C (getreal "\n Specify width: "))


(initget (+ 1 2 4))
(setq L1 (getreal "\n Offset from the left side: "))
(initget (+ 1 4))
(setq L2 (getreal "\n Offset from first circle: "))


;(initget (+ 1 2 4))
(initget 0 "Piasu pOnchi")
(setq F (getreal "\n Specify diameter or [Piasu/pOnchi]: "))

;(setvar "cmdecho" 0)

(setvar 'osmode 0)

(setq A2 (polar A 0 B))
(setq A3 (polar A2 (/ pi 2) C))
(setq A4 (polar A (/ pi 2) C))

(setq A5 (polar A 0 L1))
(setq C1 (polar A5 (/ pi 2) (/ C 2)))
(setq C2 (polar C1 0 L2))


(las "11")
(command ".pline" A A2 A3 A4 "close")
(setvar "regenmode" 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(cond  
((= (numberp F) T)(command ".circle" C1 "_d" F ".circle" C2 "_d" F))
((= (strcase F) "PIASU")(las "66")(command ".point" C1 ".point" C2 )(las "11"))
((= (strcase F) "PONCHI")(las "33")(command ".point" C1 ".point" C2 )(las "11"))
)
(setvar 'osmode osv)
;(setvar 'cmdecho 1)
(princ)
(las curl)
)

(c:th)

 

 

 

For me I use library routines for input happy to provide the code to match.

screenshot297.png

0 Likes
Message 3 of 10

pbejse
Mentor
Mentor

@Anonymous wrote:

Draw rectangle with 2 holes (2 points), when I choose Piasu(a point) it will make a point with layer 66(mylayer), and Ponchi(a point) it will make a point with layer 33(mylayer), I have tried my codes but it is error at create (Piasu and Ponchi), After change to layer 33 or 66 it will set currentlayer is 11. Is there wrong with my lisp?


Not sure why don't you just continue and reply to this topic --> There is something wrong with my lisp? 

 

0 Likes
Message 4 of 10

Anonymous
Not applicable

Thank you very much for your reply, It works for me!
Can you show me the codes for showing the dialog box (library routines) that you attached?

0 Likes
Message 5 of 10

Anonymous
Not applicable

I am sorry for this one, If I using the old one, It may be complicated. And Thank you very much for your support one again! ^^

0 Likes
Message 6 of 10

Sea-Haven
Mentor
Mentor

This includes the dcl entry, it uses the two library lisps they just need to be saved to a directory that is in your support path. Normally where you have all your lisps. Any problems just post.

 

; th by Alanh Nov 2020

(defun C:TH ( / a1 b c l1 l2 c1 c2 osv curl)

(defun las (la / )(setvar 'clayer la))

(if (tblsearch "layer" "33")
(princ)
(command "-layer" "m" "11" "m" "33" "M" "66" "")
)
(setq curl (getvar 'clayer))
(setq osv (getvar 'osmode))

(setq A1 (getpoint "\n Specify first corner of rectangle: "))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values" "Enter length " 8 7  "100" "Enter width" 8 7 "100" "Offset left" 8 7 "10" "Offset circle " 8 7 "10")))
(setq B (atof (nth 0 ans))
	C (atof (nth 1 ans))
	L1 (atof (nth 2 ans))
	l2 (atof (nth 3 ans))
)

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not but)(setq but 1))
(ah:butts but "V"   '("Select option " "  Enter Dia" "  Piasu "  "  Ponchi"))

(setvar 'osmode 0)

(setq A2 (polar A1 0.0 B))
(setq A3 (polar A2 (/ pi 2) C))
(setq A4 (polar A1 (/ pi 2) C))
(setq A5 (polar A1 0.0 L1))
(setq C1 (polar A5 (/ pi 2) (/ C 2)))
(setq C2 (polar C1 0.0 L2))


(las "11")
(command ".pline" A1 A2 A3 A4 "close")
(setvar "regenmode" 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(cond  
((= but 1) (setq f (atof (nth 0 (AH:getvalsm (list "Enter value" "Enter Dia " 8 7  "10")))))(command ".circle" C1 "_d" F ".circle" C2 "_d" F))
((= but 2)(las "66")(command ".point" C1 ".point" C2 )(las "11"))
((= but 3)(las "33")(command ".point" C1 ".point" C2 )(las "11"))
)

(setvar 'osmode osv)
(las curl)

(princ)
)

(c:th)
0 Likes
Message 7 of 10

Anonymous
Not applicable

Thank you for your help! I tested but it does not works! 

"error: LOAD failed:Multi Getvals.lsp"

0 Likes
Message 8 of 10

Sea-Haven
Mentor
Mentor

The multi getvals and multi radio buttons are seperate lisps and do not have to live inside all you lisps that you want to use these "LIBRARY" routines. 

 

To solve a few different ways.

 

Simplest is to make sure where you have saved them is in Autocad's lisp search path. Options, Files, Support file search path, use the Add option and choose the directory where they are saved. Also add to Trusted Locations.

 

screenshot299.png

 

Change the "Load" to include where the lisp file is located.

eg (if (not AH:getvalsm)(load "d:\\mylisps\\library\\Multi Getvals.lsp")) same for radio buttons.

 

Using Appload add to the "Start up suite" the two lisps.

 

Last resort for me not the preferred method, copy the two lisps into the top of the code.

 

 

0 Likes
Message 9 of 10

Anonymous
Not applicable

Thank you very much!

0 Likes
Message 10 of 10

Sea-Haven
Mentor
Mentor

Can you please let me know got it working ? Which method for future users of the Multi lisps.

0 Likes