PDA

View Full Version : Selection Set


BoKirra
2009-04-20, 03:51 AM
Hi ALL,
Supposed I want to select a set of circles which radius = 50.
Then I subtract a solid (Entity1) with this selection set of circles.
It worked fine with AutoCAD 2005.
Now I found there is an error on command prompt in 2009 version:
; error: bad argument type: lselsetp nil
The following is what I have:

(command "circle" Point_0 "d" 100)
(setq Entity_0 (entlast))
(command "-array" Entity_0 "" "P" IPoint 4 "" "")
(setq SSet (ssget "_W" Point1 Point2 (list (cons 0 "CIRCLE") (cons 40 50))))
(setq SSL (sslength SSet))
(setq CNT 0)
(repeat SSL
(setq SSN (ssname SSet CNT))
(command "extrude" SSN "" Length)
(command "subtract" Entity1 "" "l" "")
(setq CNT (1+ CNT))
); ent of repeat

What is wrong?

Your helps are much appreciated.

steve.ashton
2009-04-20, 08:00 AM
Make sure that the points Point1 & Point2 are defined. I was getting the same error message until I defined a location for these points. The error message is from the sslength trying to return the length of the sset which is still nil as the ssget wasn't finding the circles.

irneb
2009-04-20, 01:10 PM
I'd suggest a while loop instead of a repeat:(setq CNT 0)
(while (< CNT (sslength SSet))
...
...
(setq CNT (1+ CNT))
)This way is the selection set is empty (< CNT (sslength SSet)) will return nil and the loop will stop. The repeat loop expects an integer, but if the selection set is empty (sslength ...) returns nil ... thus the loop will fail.

BoKirra
2009-04-21, 12:46 AM
Make sure that the points Point1 & Point2 are defined. I was getting the same error message until I defined a location for these points. The error message is from the sslength trying to return the length of the sset which is still nil as the ssget wasn't finding the circles.
Thanks, mate.
I've double checked that Point1 & Point2 have been defined correctly.
And it worked perfectly until I loaded it to 2009 version.
I haven't modified this code since it was written.
:cry:

BoKirra
2009-04-21, 12:55 AM
I'd suggest a while loop instead of a repeat:(setq CNT 0)
(while (< CNT (sslength SSet))
...
...
(setq CNT (1+ CNT))
)This way is the selection set is empty (< CNT (sslength SSet)) will return nil and the loop will stop. The repeat loop expects an integer, but if the selection set is empty (sslength ...) returns nil ... thus the loop will fail.
Thanks for your help, again.:)
Is this OK?

(command "circle" Point_0 "d" 100)
(setq Entity_0 (entlast))
(command "-array" Entity_0 "" "P" IPoint 4 "" "")
(setq SSet (ssget "_W" Point1 Point2 (list (cons 0 "CIRCLE") (cons 40 50))))
(setq CNT 0)
(while (< CNT (sslength SSet))
(setq SSN (ssname SSet CNT))
(command "extrude" SSN "" Length)
(command "subtract" Entity1 "" "l" "")
(setq CNT (1+ CNT))
); end of while

I still receive the same error message when I loaded it.:cry:
Is any problem in this line? I can't see it.

(setq SSet (ssget "_W" Point1 Point2 (list (cons 0 "CIRCLE") (cons 40 50))))

Again, I am sure that Point1 & Point2 have been defined correctly.

irneb
2009-04-21, 06:48 AM
Sorry, just checked, the sslength gives an error on an empty selection set. So you need to check for that as well. Another thing, maybe 2009 is very strict about numerical types in ssget. Try changing the radius to a floating point instead of an integer:(command "circle" Point_0 "d" 100)
(setq Entity_0 (entlast))
(command "-array" Entity_0 "" "P" IPoint 4 "" "")
(setq SSet (ssget "_W" Point1 Point2 (list (cons 0 "CIRCLE") (cons 40 50.0))))
(setq CNT 0)
(while (and SSet (< CNT (sslength SSet)))
(setq SSN (ssname SSet CNT))
(command "extrude" SSN "" Length)
(command "subtract" Entity1 "" "l" "")
(setq CNT (1+ CNT))
); end of whileThis should at least take care of the error message, so your code can continue. However, it seems it's not selecting anything. Can you possibly compare and enget of one of these circles between 2005/9. Maybe there is an undocumented change?

Or maybe there's some inaccuracies, in which case a "fuzzy" compare in the ssget would be needed:(setq SSet (ssget "_W" Point1 Point2
(list (cons 0 "CIRCLE")
(-4 . ">=") (cons 40 49.9)
(-4 . "<=") (cons 40 50.1)
)
)
)If all else fails, create a list using entlast just after you create the circle. Then after the array, while entnext gives an entity add it to the list. Now you should have a list of enames instead of a selection set. Still using a counter & while loop, sslength now changes to length, and ssname changes to nth.

BoKirra
2009-04-22, 02:03 AM
Thanks, irneb.
I can't test it on 2005 because I've removed it from my PC.
I now found the other symptom.
The problem only happens when the drawing is in Isometric display mode and an error message given:

; error: bad argument type: lselsetp nil

It works fine without any error message when drawing is in normal 2D display mode (TOP view). :roll:
I found this today.
Could you please test the following code? Thanks again.

(defun DEG (A)
(* pi (/ A 180.0))
) ; defun
(defun C:3Dmodel (/ IPoint Point1 Point2 Point3 Point4 Point5
Entity1 Entity2 Entity3 Entity4 CNT SSet SSN)
(setq IPoint (getpoint "\nSelect Insert Point: "))
(setq Point1 (polar IPoint (DEG 90) 500.0)
Point2 (polar IPoint (DEG 180) 750.0)
Point3 (polar Point2 (DEG 270) 750.0)
Point4 (polar Point3 (DEG 0) 1500.0)
Point5 (polar Point4 (DEG 90) 1500.0)
) ;end of setq
(command "circle" IPoint "d" 1500.0)
(setq Entity1 (entlast))
(command "extrude" Entity1 "" 25.0)
(setq Entity2 (entlast))
(command "circle" Point1 "d" 100.0)
(setq Entity3 (entlast))
(command "-array" Entity3 "" "P" IPoint 4 "" "")
;===================================================
(setq SSet (ssget "_W" Point3 Point5 (list (cons 0 "CIRCLE") (cons 40 50.0))))
(setq CNT 0)
(while (and SSet (< CNT (sslength SSet)))
(setq SSN (ssname SSet CNT))
(command "extrude" SSN "" 25.0)
(command "subtract" Entity2 "" "l" "")
(setq CNT (1+ CNT))
); end of while
;===================================================
(setq Entity4 (entlast))
(command "chprop" Entity4 "" "la" "Mech_01" "")
(princ)
) ; end of program

steve.ashton
2009-04-22, 02:35 AM
I tried it in 2010 and worked fine when in plan, but not when viewed from other angles.

Appears to be a problem selecting the circles after array. Why not just draw all 4 circles individually and extrude rather than using array.

BoKirra
2009-04-22, 03:28 AM
I tried it in 2010 and worked fine when in plan, but not when viewed from other angles.
Appears to be a problem selecting the circles after array.
Yes, that is what I have in 2009. Thanks, mate.
Why not just draw all 4 circles individually and extrude rather than using array.
It was subtracted from another code & it has been simplified when posting.

I just realised that your first reply possibly was in the right direction.
I mean, the points defined must be 3D points.
So something needs to be done for IPoint in the code.
Am I in the right track?
If so, how to fix it?
Thanks again.

steve.ashton
2009-04-22, 11:11 AM
Although I haven't done 3D programming before, even programming for 2D I try to avoid using selection tools that require point selection as you often have problems with selecting the wrong items. I have done a rough version drawing individual items and only using entlast to select. this seems to work ok.


(defun DEG (A)
(* pi (/ A 180.0))
) ; defun
(defun C:3Dmodel (/ IPoint Point1 Point2 Point3 Point4 Point5
Entity1 Entity2 Entity3 Entity4 CNT SSet SSN)
(setq IPoint (getpoint "\nSelect Insert Point: "))
(setvar "osmode" 0)
(setq Point1 (polar IPoint (DEG 90) 500.0)
Point2 (polar IPoint (DEG 180) 750.0)
Point3 (polar Point2 (DEG 270) 750.0)
Point4 (polar Point3 (DEG 0) 1500.0)
Point5 (polar Point4 (DEG 90) 1500.0)
) ;end of setq
(command "circle" IPoint "d" 1500.0)
(setq Entity1 (entlast))
(command "extrude" Entity1 "" 25.0)
(setq Entity2 (entlast))
(command "circle" Point1 "d" 100.0)
(command "extrude" (entlast) "" 25.0)
(command "subtract" Entity2 "" "l" "")
(command "circle" (polar ipoint (deg 180) 500.0) "d" 100.0)
(command "extrude" (entlast) "" 25.0)
(command "subtract" Entity2 "" "l" "")
(command "circle" (polar ipoint (deg 0) 500.0) "d" 100.0)
(command "extrude" (entlast) "" 25.0)
(command "subtract" Entity2 "" "l" "")
(command "circle" (polar ipoint (deg 270) 500.0) "d" 100.0)
(command "extrude" (entlast) "" 25.0)
(command "subtract" Entity2 "" "l" "")

(setq Entity4 (entlast))
(command "chprop" Entity4 "" "la" "Mech_01" "")
(princ)
) ; end of program

Bruno.Valsecchi
2009-04-22, 12:00 PM
Or simply (extrude before array)

(defun C:3Dmodel (/ IPoint js_add js_remove e_name)
(initget 1)
(setq
IPoint (getpoint "\nSelect Insert Point: ")
js_add (ssadd)
js_remove (ssadd)
)
(command "_.circle" "_none" IPoint "_d" 1500.0)
(command "_.extrude" (entlast) "" 25.0)
(setq js_add (ssadd (entlast) js_add))
(command "_.circle" "_none" (polar IPoint (* pi 0.5) 500.0) "_d" 100.0)
(command "_.extrude" (entlast) "" 25.0)
(setq js_remove (ssadd (entlast) js_remove))
(setq e_name (entlast))
(command "_.-array" (entlast) "" "_Polar" "_none" IPoint 4 (angtos (* pi 2)) (angtos (* pi 0.5)) "_yes")
(while (setq e_name (entnext e_name)) (setq js_remove (ssadd e_name js_remove)))
(command "_.subtract" js_add "" js_remove "")
;(command "_.chprop" (entlast) "" "_Layer" "Mech_01" "")
(princ)
)

irneb
2009-04-22, 12:53 PM
I think you guys are correct, using a ssget gives some weird results when in a 3d view. Seeing as you're also using points for the ssget, these points are then translated to view-ucs ... so the circles may fall outside the selected rectangle.

Here's your same code, just not using any SSGET. As I've suggested previously just use entnext instead:(defun DEG (A)
(* pi (/ A 180.0))
) ; defun
(defun C:3Dmodel (/ IPoint Point1 Point2 Point3 Point4 Point5 Entity1 Entity2 Entity3 Entity4 CNT SSet SSN EData)
(setq IPoint (getpoint "\nSelect Insert Point: "))
(setq Point1 (polar IPoint (DEG 90) 500.0)
Point2 (polar IPoint (DEG 180) 750.0)
Point3 (polar Point2 (DEG 270) 750.0)
Point4 (polar Point3 (DEG 0) 1500.0)
Point5 (polar Point4 (DEG 90) 1500.0)
) ;end of setq
(command "circle" IPoint "d" 1500.0)
(setq Entity1 (entlast))
(command "extrude" Entity1 "" 25.0)
(setq Entity2 (entlast))
(command "circle" Point1 "d" 100.0)
(setq Entity3 (entlast))
(command "-array" Entity3 "" "P" IPoint 4 "" "")
;| Replace this
;===================================================
(setq SSet (ssget "_W" Point3 Point5 (list (cons 0 "CIRCLE") (cons 40 50.0))))
(setq CNT 0)
(while (and SSet (< CNT (sslength SSet)))
(setq SSN (ssname SSet CNT))
(command "extrude" SSN "" 25.0)
(command "subtract" Entity2 "" "l" "")
(setq CNT (1+ CNT))
) ; end of while
;===================================================
|; ;With this
(setq SSN Entity3)
(while (and SSN (setq EData (entget SSN)) ;Get its DXF data
(= "CIRCLE" (cdr (assoc 0 EData))) ;Check if it's a circle
) ;_ end of and
(command "extrude" SSN "" 25.0)
(command "subtract" Entity2 "" "l" "")
(setq SSN (entnext SSN)) ;Get the next entity
) ;_ end of while
(setq Entity4 (entlast))
(command "chprop" Entity4 "" "la" "Mech_01" "")
(princ)
) ; end of programSeems to work fine for me in 2008 in any view, even using orbital views (not exact isometric). While the SSGET method does not perform anything while in NW, SE, etc. views.

BoKirra
2009-04-23, 12:43 AM
Thanks a lot.
Again, glad to learn from you guys. :lol: :lol: :lol: