PDA

View Full Version : Help relating to selection and selection sets

csgohjmj
2004-09-17, 07:38 AM
1) What is the function to use in order to return only the subentity of a complex object?
For eg, if you pick a polyline, it will return the line data at the pick point.

2) Is it possible to use ssget and its filter list to create a selection set of all objects crossing and inside the polygon and if the object is a complex object, it returns only the subentities within the crossing polygon?

Thanks.

csgoh

2004-09-17, 11:57 AM
Csgohjmj,
1) What kind of complex objects are you referring to? For polylines, only old style polylines such as 3dmeshes and 3dpoly's are considered complex objects. Lightweight polylines don't have subentities. If the line data is merely a matter of vertices then there's an example of retrieving line data here (http://theswamp.org/phpBB2/viewtopic.php?t=467&start=0), - look for the function getSegment.

2) Yes, it's possible. I believe there was a thread on polylines used as WP or CP selection on this forum. But again, what kind of complex objects are you looking to return. Is it vertices of old style polylines or block subents?

csgohjmj
2004-09-17, 01:30 PM
Hi Stig;
I am actually referring to 3dpolylines and lwpolylines.
Thanks.

csgoh

2004-09-17, 03:35 PM
Okie

1) The getSegment function mentioned above will get segment data from both 2D and 3D polylines. I take it that with "line" data you mean vertices comprising a segment?

2) When you say subentities within the crossing polygon, which data are you interested in? If it is merely vertices of 3Dpoly's and lwpoly's then this might get you started:

getCoordinates is a simple example of extracting coordinates from both kinds of polylines (I'm sure there are cleaner and faster methods out there than this)

crossPolygon will use a polyline as a CP selection by calling getCoordinates and pass the coordinates to an SSGET "_CP" function. Beware that self-intersecting polylines will always cause SSGET to return nil.

C:INPOLY will call crossPolygon to get a selection set and run through each member. If a member is a polyline, it'll call getCoordinates to extract the coordinates. The return value is a list of coordinates lists of plines found within the pline. Is that what you're after?

If at all usable then take what you can use, or at least add some error handling. These are just quickly written samples of some generic ideas without much error handling.

(defun getCoordinates (obj / coords coordlst objname)
(defun getCoords (obj)
(vlax-safearray->list
(vlax-variant-value (vla-get-coordinates obj))))

(cond ((member (setq objname (vla-get-objectName obj))
'("AcDb3dPolyline" "AcDbPolyline"))
(setq coordlst (getCoords obj))
(while coordlst
(cond ((= objname "AcDb3dPolyline")
(setq coords (cons (list (car coordlst) (cadr coordlst)
coordlst (cdddr coordlst)))
((setq coords (cons (list (car coordlst) (cadr coordlst)) coords)
coordlst (cddr coordlst)))
)
)
)
)
(reverse coords)
)

(defun crossPolygon (/ ent vertices sset)
(and (setq ent (car (entsel)))
(member (cdr (assoc 0 (entget ent))) '("POLYLINE" "LWPOLYLINE"))
(setq vertices (getCoordinates (vlax-ename->vla-object ent)))
(setq sset (ssget "_CP" vertices))
(ssdel ent sset)
)
sset
)

(defun C:inPoly (/ lst ss a coords)
(cond ((setq ss (crossPolygon))
(setq a 0)
(repeat (sslength ss)
(if (setq coords (getCoordinates (vlax-ename->vla-object (ssname ss a))))
(setq lst (cons coords lst)))
(setq a (1+ a))
)
)
)
(reverse lst)
)