Selection set is only using the last selected entity to compare if statement conditions

Selection set is only using the last selected entity to compare if statement conditions

Woon22
Contributor Contributor
3,357 Views
26 Replies
Message 1 of 27

Selection set is only using the last selected entity to compare if statement conditions

Woon22
Contributor
Contributor

Hello,

 

I am pretty new to lisp and have created a few programs for my work. One program I use creates holes within a rectangle by creating a boundary within an area then storing the len and wid and creating holes within. There are basically a bunch of cond statements that compare the hole distance and then creates more holes if the spacing is exceeded. I want to be able to use a selection set to select all of the rectangles at once and then apply the cond statements to each rectangle and create all the holes at once. I have the selection stored and all and the code extracts the values I need from the selection set so that I can create the pattern, however the issue I am having is that the cond. statements only apply to the last rectangle in the selection set (I believe that the selection set order is based on creation order if selected with a window). I think that every time a new len and wid of the rectangle is defined it overwrites the previous data and does not execute the conditional statements until the last entity is selected. I am wondering if anyone has any thoughts on how I could approach this problem? I know that I can create new variables within the code to match the number of entities within the selection set (I have a while loop that I am pretty sure makes sure the code is executed before the next selected entity is created). I could store a new version of len and wid for each selected entity say len1 and wid1 using read and set, but I don't know how to use the cond statement to compare a newly stored variable without literally copying and pasting all of the cond statements. 

 

For example:

 

(cond ((and (> wid1 len1)(< len 8.5)(< wid 8.5)
(entmake (list (cons 0 "CIRCLE")(cons 10 holex3y1)(cons 40 0.25)(cons 62 2)))
(entmake (list (cons 0 "CIRCLE")(cons 10 holex3y2)(cons 40 0.25)(cons 62 2)))
)
)
)

 

Is it possible to compare (widx) and (lenx) x being the current entity in the selection set that I need the program to evaluate?

Any thoughts on this would be greatly appreciated (I can post example portions of the code as well but figured I'd get the issue fleshed out in writing before that). Thanks!  

Woon22_0-1644166778494.png

 

0 Likes
Accepted solutions (1)
3,358 Views
26 Replies
Replies (26)
Message 21 of 27

devitg
Advisor
Advisor

@Woon22 

Without any permission, I dare to add the way to handle  all polys at the Panel Layer .

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/selection-set-is-only-using-the-last-selected-entity-to-compare/td-p/10932021

; multi holes in rectang 

; By AlanH Feb 2022 [email protected]

;; modify by devitg , to select all polys at layer Panel
;; draw red circles 


(defun c:recholes-dv ( /
ACAD-OBJ
acRed
ADOC
AH:GETVALSM
ANS
CIRC-OBJ
CLAYER
COLS
DIST1
DIST2
HDIST
HOFF
LEN
MAXG
MAXPOINT
MINPOINT
MODEL
NUM
OLDSNAP
POINTMAX
POINTMIN
POLY-ENT-SS
POLY-OBJ-SS
PT
PT1
RAD
ROWS
SELECTIONSETS
VDIST
VOFF
WID





                      )
  (VL-LOAD-COM)
  (SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD 
  (SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
  (SETQ MODEL (VLA-GET-MODELSPACE ADOC))
  (SETQ SELECTIONSETS (VLA-GET-SELECTIONSETS ADOC))

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values" "vertical offset" 5 4 "2.75" "Horizontal offset" 5 4 "1.50" "Max space " 5 4 "24" "Radius" 5 4 "0.2188")))

(setq voff (atof (nth 0 ans))
hoff (atof (nth 1 ans))
maxg (atof (nth 2 ans))
rad (atof (nth 3 ans))
)

  (setq clayer (getvar 'clayer))
  (setvar 'clayer "HOLES")

;(setq obj (vlax-ename->vla-object (car (entsel "pick object "))))

(setq poly-ent-ss (ssget "_X"   '((0 . "LWPOLYLINE")
                               (100 . "AcDbEntity")
                               (67 . 0)
                               (410 . "Model")
                               (8 . "Panel")
                               (100 . "AcDbPolyline")
;;;                               (90 . 4)
;;;                               (70 . 1)
                             )
   ))

(setq poly-obj-ss (VLA-GET-ACTIVESELECTIONSET adoc))

 (VLAX-FOR obj poly-obj-ss 

(vla-GetBoundingBox obj 'minpoint 'maxpoint)
(setq pointmin (vlax-safearray->list minpoint))
(setq pointmax (vlax-safearray->list maxpoint))

(setq len (- (car pointmax)(car pointmin)) wid (- (cadr pointmax)(cadr pointmin)))

(setq dist1  (- len (* 2.0 hoff)) dist2 (- wid (* 2 voff)))

(setq rows (/ dist2 maxg))
(if (> rows 1.0)
(progn
(setq rows (+ (fix rows) 1))
(setq vdist (/ dist2 rows))
(setq rows (+ rows 1))
)
(progn
(setq vdist (- wid (* 2.0 voff)))
(setq rows 2)
)
)

(setq cols (/ dist1 maxg))
(if (> cols 1.0)
(progn
(setq cols (+ (fix cols) 1))
(setq hdist (/ dist1 cols))
(setq cols (+ cols 1))
)
(setq cols 1)
)

(setq pt1 (mapcar '+ pointmin (list hoff voff 0.0)))
(setq pt pt1)

(setq num 0)
(repeat rows
(setq num (+ num 1))
(repeat cols
(command "circle" pt rad)
(setq circ-obj (vlax-ename->vla-object (entlast)))	 
 (vla-put-color circ-obj acred) 
(setq pt (mapcar '+ pt (list hdist 0.0 0.0)))
)
(setq pt (mapcar '+ pt1 (list 0.0 (* vdist num )  0.0)))
)
 ) ;end VLAX-FOR  
(setvar 'osmode oldsnap)
 (setvar 'clayer clayer)  
(princ)
   
)

(c:recholes-dv)
;|«Visual LISP© Format Options»
(100 2 1 2 T " " 100 6 0 0 1 nil T nil T)
;*** DO NOT add text below the comment! ***|;

 

 

0 Likes
Message 22 of 27

Sea-Haven
Mentor
Mentor

Nearly everyone that wants multiple asks after code supplied. You can use the While function very simple press Enter to stop

 

2 changes

 

 

 

 

(setq obj (vlax-ename->vla-object (car (entsel "pick object "))))

(while (setq  ent (entsel "\npick rectang or Enter to exit "))
(setq obj (vlax-ename->vla-object (car  ent)))
)

(c:recholes)


) ; end while
)
(c:recholes)

 

 

 

I would also suggest get Notepad++ its a great editor for lisp and has a detect lisp so shows bracket links very handy in big code.

 

0 Likes
Message 23 of 27

Woon22
Contributor
Contributor

Thank you, 

 

I've been using Ultraedit and I don't mind it though I don't really know how to use it too well to help me out. It automatically helps me be adding parenth and showing if there is a break in the parenth. It also highlights most of the lisp functions

0 Likes
Message 24 of 27

Woon22
Contributor
Contributor

Thank you for your input, I will see what I can learn from your modification. 

0 Likes
Message 25 of 27

devitg
Advisor
Advisor

@Woon22 , since my early LISPer time, I wonder why users don't USE the VLIDE , ACAD native editor.

 

 

 

0 Likes
Message 26 of 27

john.uhden
Mentor
Mentor

@Woon22 ,

I think it's a matter of that with which you get comfortable plus little things that make your editing easier.

I prefer TextPad for a number of reasons, the first of which is that I think it was Michael Puckett who recommended it, and who gave us the syntax file for showing AutoCAD function names in a different color.

God bless him (RIP).

John F. Uhden

0 Likes
Message 27 of 27

Woon22
Contributor
Contributor

I tried to get Vlide but somewhere in the installation process I got tripped up and couldn't figure out what I was missing. I believe I downloaded visual studio community version and I couldn't find the vlide extension.

0 Likes