About subtract command

About subtract command

saitoib
Advocate Advocate
552 Views
2 Replies
Message 1 of 3

About subtract command

saitoib
Advocate
Advocate

Hi all.

I have asked how to use the presspull command in Autolisp before, but was not able to solve the problem.
I gave up on using the presspull command.


Then I tried to use rextrude and subtract to achieve the same behavior.
However, it does not work.
In the following code, It cannot subtract the second circle.
Why is this?
Please help me.

(defun c:test1 (/ th ss nn id )
	(command "rectang" "0,0" "100,100")
	(command "circle" "50,50" "10")
	(command "circle" "20,20" "5")
	
	(setq th 5)
	(setq ss (ssget "X" (list (cons 0 "LWPOLYLINE"))))
	(setq id (ssname ss 0))
	(_set_solid id th)
)
(defun _set_solid (id th / pts panel iss inn iid did)
	(setq pts (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget id)))
	(setq pts (mapcar 'cdr pts))
	
	(command "copy" id "" '(0 0 0) '(0 0 0))
	(command "extrude" (entlast) "" th)
	(setq panel (entlast))
	
	(setq iss (ssget "WP" pts))
	(setq inn (sslength iss))
	(setq i 0)
	(repeat inn
		(setq iid (ssname iss i))
		(command "copy" iid "" '(0 0 0) '(0 0 0))
		(command "extrude" iid "" th)
		(setq did (entlast))
		(command "subtract" panel "" did "")
		(setq panel (entlast))
		(setq i (1+ i))
	)
)
Saitoib
0 Likes
Accepted solutions (1)
553 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant
Accepted solution

Substracting an entity from the original solid just modifies the solid (= same ename), not creates new. That line took a circle created by the copy command. Sou should be able to see that by tracing your code step by step, see THIS 

 

(defun c:test1 (/ th ss nn id )

  (command "rectang" "0,0" "100,100")
  (command "circle" "50,50" "10")
  (command "circle" "20,20" "5")
  
  (setq th 5)
  (setq ss (ssget "X" (list (cons 0 "LWPOLYLINE"))))
  (setq id (ssname ss 0))
  (_set_solid id th)
  )
(defun _set_solid (id th / pts panel iss inn iid did)
  (setq pts (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget id)))
  (setq pts (mapcar 'cdr pts))
  
  (command "copy" id "" '(0 0 0) '(0 0 0))
  (command "extrude" (entlast) "" th)
  (setq panel (entlast))
  
  (setq iss (ssget "WP" pts))
  (setq inn (sslength iss))
  (setq i 0)
  (repeat inn
    (setq iid (ssname iss i))
    (command "copy" iid "" '(0 0 0) '(0 0 0))
    (command "extrude" iid "" th)
    (setq did (entlast))
    (command "subtract" panel "" did "")
    ;(setq panel (entlast))
    (setq i (1+ i))
    )
  )

 

0 Likes
Message 3 of 3

saitoib
Advocate
Advocate

Oh
In the case of extrude, it changes to a new entity, so I was mistaken.
In the case of subtract, it stays the same, right?
Solved.

 

Thank you very much.

Saitoib
0 Likes