Use OR in an IF? (if (setq name (or

Use OR in an IF? (if (setq name (or

Anonymous
Not applicable
1,268 Views
10 Replies
Message 1 of 11

Use OR in an IF? (if (setq name (or

Anonymous
Not applicable

Hello,

 

I am using the code below to select by dynamic block name. It specifies one dynamic block name. I would like to specify a bunch. I am not a lisp expert and I have tried this a number of ways. Is it possible to use or this way? Or should I use a loop with a counter? 

 

(defun c:sb (/ e name n out ss)
(vl-load-com)
(if (setq name "Place Your Dynamic Block Name";;;Use this Without User input
;name (getstring T "\nEnter Block name: ");;;Use this With User input
ss (ssget "_X" '((0 . "INSERT")))
n -1
out (ssadd)
)
(while (setq e (ssname ss (setq n (1+ n))))
(if (= :vlax-true (vla-get-IsDynamicBlock (vlax-ename->vla-object e)))
(if (= (strcase (vla-get-Effectivename (vlax-ename->vla-object e))) (strcase name))
(ssadd e out)
)
)
)
)
(if (/= 0 (sslength out))(sssetfirst nil out)(princ (strcat "No Dynamic Block found by the Name - " name)))
(princ)
)

 

0 Likes
Accepted solutions (1)
1,269 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....

(if (setq name "Place Your Dynamic Block Name";;;Use this Without User input

;name (getstring T "\nEnter Block name: ");;;Use this With User input
….

(if (= (strcase (vla-get-Effectivename (vlax-ename->vla-object e))) (strcase name))
….


 

Try replacing this much:

 

(if (setq name "Place Your Dynamic Block Name";;;Use this Without User input

;name (getstring T "\nEnter Block name: ");;;Use this With User input
….

 

with this:

 

(if

  (setq name

    "BlockName1,BlockName2,BlockName3" ;;;Use this Without User input

;   (getstring T "\nEnter Block name(s) with comma separators: ") ;;;Use this With User input

    ….

 

and replacing this:

(if (= (strcase (vla-get-Effectivename (vlax-ename->vla-object e))) (strcase name))

 

with this:

 

(if (wcmatch (strcase (vla-get-Effectivename (vlax-ename->vla-object e))) (strcase name))

Kent Cooper, AIA
0 Likes
Message 3 of 11

Sea-Haven
Mentor
Mentor

if you look at www.lee-mac.com he has  a select from list lisp, so you could have 20 block names and just pick which ones you want to use at any time.

0 Likes
Message 4 of 11

Anonymous
Not applicable

Kent, thank you for the quick reply. 

 

I tried your suggestion and the script runs, but not as intended.

 

If I enter a list of blocks (Block1, Block2, Block3), running the script will select only Block1, and not Block2 or Block3.

 

If the first blockname is not available (I remove Block1 from the drawing), AutoCAD returns "No Dynamic Block found by the Name - Block1, Block2, Block3"

 

 

0 Likes
Message 5 of 11

Anonymous
Not applicable

Hello sea.haven,

 

Which program exactly are you talking about? http://www.lee-mac.com/programs.html

0 Likes
Message 6 of 11

dbhunia
Advisor
Advisor

Don't place "space" after comma 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 7 of 11

Anonymous
Not applicable

Thank you Debashis! 

0 Likes
Message 8 of 11

ronjonp
Mentor
Mentor

You could also target you selection a bit better so you're not looking at everything. Also changed the check to property-available-p 🙂

(defun c:sb (/ e name n o out ss)
  (if (setq name "blockname[1-3]"
	    ss	 (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat name ",`*U*"))))
	    n	 -1
	    out	 (ssadd)
      )
    (while (setq e (ssname ss (setq n (1+ n))))
      (if (and (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'effectivename)
	       (wcmatch (strcase (vla-get-effectivename o)) (strcase name))
	  )
	(ssadd e out)
      )
    )
  )
  (if (/= 0 (sslength out))
    (progn (sssetfirst nil out) (princ (strcat (itoa (sslength out)) " " name " blocks found...")))
    (princ (strcat "No Dynamic Block found by the Name - " name))
  )
  (princ)
)
(vl-load-com)

 

0 Likes
Message 9 of 11

Anonymous
Not applicable

The next step to this is finding where this list of blocks intersects with each other, and then placing a specific "warning" block at that intersection point. 

 

I found this script that does pretty much what I want but combining them is proving to be an issue!

 

https://lispbox.wordpress.com/2017/08/16/insert-block-at-intersections/

0 Likes
Message 10 of 11

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... finding where this list of blocks intersects with each other ... placing a specific "warning" block at that intersection point. .... this script that does pretty much what I want ....


 

I was interested to find in a quick test that the 'intersectwith' method used in that routine works with Blocks.  But what it finds is intersections of their bounding box edges.  So these two Blocks [the white parts] would be considered to intersect by that standard, because their bounding boxes [dashed grey] do, even though their drawn contents do not:

bbint.PNG

Is that acceptable?  What is the nature of the geometry of the Blocks you would be working with?

 

[A further complication is that if a Block is at a non-orthogonal rotation, its bounding box gets unnaturally larger than the area you would want it to represent -- think of the bounding box at zero rotation being "part of the Block" and the Block's bounding box at non-orthogonal rotations being the bounding box of that rotated rectangle.]

Kent Cooper, AIA
0 Likes
Message 11 of 11

Anonymous
Not applicable

I am dealing with electrical boxes mounted using ladder brackets. The user can specify the location of the faceplate, and then use dynamic stretching to adjust the height of the ladder bracket.

 

electrical.PNG

 

I think I can manipulate the blocks so that their boundary is tight (extend the orange in a bit). The main concern is on the overlap of the mounting parts at top and bottom, which I think will be captured by this method.

 

All of this work will be done without rotation, so the second part of your response is not an issue.

0 Likes