Jump to content

How to select objects to perform 'subtract' command


detailer2012

Recommended Posts

Hello,

Is there a simple way to select 3D objects so I can perform the "subtract" command within a lisp routine?  I'm trying to write a routine that produces some basic 3D objects.  In this particular case, just a simple purlin cleat with several holes.  I don't have too much trouble in creating the 2D image (rectangular plate and circles within for holes), and I can extrude 2D image to desired thickness too.  My difficulty is trying to select extruded circles and rectangle independently to perform subtraction command.  I’ve used the crossing selection with ssget to select 2D images for extrusion but I’d prefer to use an alternate selection method to avoid potentially selecting other objects in model.  I haven't included any attempt to "subtract" objects in the routine below.

I’m open to a completely new alternative too.  I’ve tried just making 3D blocks for regularly used cleats but these don’t behave well when I "solprof" the model to produce drawings.

 

Thanks in advance 

(defun c:PC ()

  (setq a (getreal"\nenter purlin depth 100, 150, 200 or 250mm "));Nominate purlin depth
  (setq b (getpoint "\nEnter base point of cleat"));Nominate bottom centre of cleat 
  (setq r1 (polar b (dtr 0)37.5));Calculate bottom RHS of cleat (rectangle)
  (setq r2 (polar b (dtr 180)37.5));Calculate bottom LHS of cleat (rectangle)
    
;Open if statement to verify user input is acceptable
  
  (if (or(= a 100)(= a 150)(= a 200)(= a 250))

;Open cond statement to determine correct cleat geometry with respect to purlin depth entered by user
	(cond ((= a 100)(setq r3 (polar r2 (dtr 90)105))(setq r4 (polar r1 (dtr 90)105));Geometry for 100mm purlin
	      (setq c1 (polar b (dtr 90)40))(setq c2 (polar b (dtr 90)80))(rect))
          ((= a 150)(setq r3 (polar r2 (dtr 90)145))(setq r4 (polar r1 (dtr 90)145));Geometry for 150mm purlin
	      (setq c1 (polar b (dtr 90)55))(setq c2 (polar b (dtr 90)115))(rect))
  	      ((= a 200) (setq r3 (polar r2 (dtr 90)195)) (setq r4 (polar r1 (dtr 90)195));Geometry for 200mm purlin
	      (setq c1 (polar b (dtr 90)55)) (setq c2 (polar b (dtr 90)165))(rect))
	      ((setq r3 (polar r2 (dtr 90)245))(setq r4 (polar r1 (dtr 90)245));Geometry for 250mm purlin
	      (setq c1 (polar b (dtr 90)55))(setq c2 (polar b (dtr 90)215))(rect));Else condition of 'cond' statement
	      
	 );cond
    
      (prompt "\nYou have chosen an invalid purlin size");Else condition of 'if' statement

  );if
  
   (princ)
);defun
(princ)

;==============================================
;define sub function to evaluate cleat geometry
(defun rect ()
  (command "_.rectangle" r3 r1 "");Outline of cleat plate
  (command "_.circle" c1 9 "");Outline of lower cleat hole
  (command "_.circle" c2 9 "");Outline of upper cleat hole
  (setq s1 (ssget "c" r3 r1));Window selection to select item to extrude
  (command "_.extrude" s1 "" 8 "");Extrude cleat items
  
  (princ)
  )

;=========================================
;degrees to radians function
(defun DTR (a)

(* PI (/ a 180.0))
);defun
;=========================================
Link to comment
Share on other sites

Redo this (defun rect ()

 

If you make rectang and extrude (setq ent1 (entlast))

make circle extrude  (setq ent2 (entlast))

make circle extrude  (setq ent3 (entlast))

Subtract ent1 

objects ent2 ent3 ""

 

image.thumb.png.8e36a83f9fe47c2b2de71fcc3fc68062.png

 

Dcl is Multi Radio Buttons.lsp (setq ans (ah:butts but "V"   '("Choose purlin depth" "100" "150" "200" "250mm "))) Multi radio buttons.lsp

Edited by BIGAL
Link to comment
Share on other sites

15 hours ago, detailer2012 said:

 I haven't included any attempt to "subtract" objects in the routine below.

I’m open to a completely new alternative too

 

$0.05 try entmakex , then you don't need to select circle

 

1. LWPOLYLINE with (list r1 r2 r3 r4 r1) & closed (70 . 1)

2. CIRCLE with radius (cons 40 c1)

3. CIRCLE with radius (cons 40 c2)

4. (setq lst (list mkpoly mkcirc1 mkcirc2) )

 

(defun rectx ( l / s1 sx s0 e)
    (foreach x '(s1 sx s0) (set x (ssadd)))
    (foreach en	l ; (list mkpoly mkcirc1 mkcirc2)
      (ssadd en s1)
      (command "_.extrude" s1 "" 8 "")
      (ssadd (entlast) sx)
      )
    (setq e (ssname sx 0))
    (ssadd e s0)
    (ssdel e sx)
    (command "_.subtract" s0 "" sx "")
    (entlast)
    )

 

*note: not frequent command user,  i assume ACAD command extrude & subtract  accept pickset thus ssadd 

 

you may try vla- functions 

vla-addextrudedsolid for extrude

vla-boolean for subtract

 

you don't need to put (rect) in every expression in cond

eg:  (cond ((= a 100) bla bla (rect)) ((= a 150) bla bla (rect)) ( blb bla ...(rect) ))

 

inside your defun C:PC snippet,

remove  (rect)  

 

use progn , entmakex after cond then (rectx lst) 

(progn

(cond (..)(..) ) ; your cond without (rect)

; start entmakex snippet
;(setq mkpoly (entmakex <add code here> )
;(setq mkcirc1 (entmakex <add code here> )
;(setq mkcirc2 (entmakex <add code here> )

(setq lst (list mkpoly mkcirc1 mkcirc2 ))
(rectx lst)

)

p/s: pseudo snippet, entmakex try it yourself, reply if you hit the wall :)

 

 

 

 

Edited by hanhphuc
pseudo comment & about vla-
Link to comment
Share on other sites

Thanks to everyone for their reply.  Great information and plenty to go on with.   I hadn’t been aware of the DCL interface option at all, so I’m pretty keen to see what else I can use it for now too.

I’ll definitely take on board all the tips and suggestions.  They’ve opened up a bunch of ideas for other things I can now too which is cool.

Thanks again!

Link to comment
Share on other sites

No worries, there are a few more library dcl's by me in download and RLX has posted some cool library ones as well. Others like Lee-mac, list dcl are worth getting a copy of Lee has two versions a single,  a pick and add to new list when you want more than 1 answer.

Link to comment
Share on other sites

Awesome.  Thanks BigAl.  I'm at risk of spending too much time developing/personalising my software and not doing enough work now.  Hahaha!  It's all worthwhile though for sure.  It's enjoyable, and it increases productivity without a doubt.  Thanks to you and other like minded people it's possible!

Link to comment
Share on other sites

FWIW 

 

(defun opt? (% msg / $)
  (ai_sysvar '(("DYNMODE" . 3)))
  (initget 1 (vl-string-translate "/" " " %))
  (setq $ (getkword (strcat "\n" msg " [" % "] : ")))
  (ai_sysvar nil)
  $
  )

eg: %=keyword slash "/" delimited

   (setq a (atoi (opt? "100/150/200/250" "Enter purlin depth mm")))     
   

select mouse double-click as BCAD 

or down-arrow key ⬇️ to show radio button (ACAD only?)

 

 

 

 

Edited by hanhphuc
link
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...