Message 1 of 25
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
How to iterate each segments of a 2d polyline to get properties using lisp? Thanks
Solved! Go to Solution.
Hi
How to iterate each segments of a 2d polyline to get properties using lisp? Thanks
Solved! Go to Solution.
@prgmdl hi,
Check this GP command. of course there are numerous ways to do it but this is the simple and this is the way to iterate any selected objects in AutoCAD (lines, circles, texts...)
first you retrieve (store in 'ss') the objects with (ssget) than you iterate them by
calling (ssname ss i) where 'i' is the index number of the object in 'ss'
enjoy
Moshe
; iterating 2d polylines for getting it's properties
(defun c:gp (/ ss i ename elist)
(if (setq ss (ssget '((0 . "lwpolyline"))))
(progn
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i))
(setq ename (ssname ss i))
(setq elist (entget ename))
(terpri)
(princ elist)
); repeat
); progn
); if
(princ)
); c:gp
hi, I can't seem to can't get the property of an individual segment of the polyline using this, or am I missing something?
@prgmdl ,
Probably you are, the code i gave you is generic should work in any AutoCAD version (including LT 2024 and up)
if you change the code, then post what you are have.
what property of the polyline you looking?
Moshe
Use
(dumpallproperties (car (entsel)))
to see all the properties you have available.
Here's an example to get a list of bulges:
(defun c:bulges ( / ent idx) (setq ent (car (entsel)) idx 0) (repeat (fix (getpropertyvalue ent "EndParam")) (terpri) (princ idx) (princ ": ") (print (getpropertyvalue ent "vertices" idx "Bulge")) (setq idx (1+ idx))) (princ) )
(defun c:gp (/ ss i ename elist)
(if (setq ss (ssget '((0 . "lwpolyline"))))
(progn
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i))
(setq ename (ssname ss i))
(setq ent (entget ename))
(setq prop (assoc 43 ent))
(princ (rtos (cdr prop) 2 2))
)
)
)
(princ)
)
A "global" width is the same for the entire polyline.
(getpropertyvalue (car (entsel)) "ConstantWidth")
... as for segments, it's define by "StartWidth" and "EndWidth". Those are property names that you can use in the code posted before.
I agree that we need to know more about what you mean by the "properties" of a Polyline segment. Presumably not what are usually called "properties" -- Layer, color, linetype, etc. -- which are those of the overall Polyline, so there's no point in going by segments. You can get the coordinates of vertices in several ways as already suggested. But since you ask about segments, width(s) and bulge factors are by segments, but do you want, for example, a list of the lengths of all segments? And/or something else?
there are situations when joining polylines of different ConstantWidth to be joined and I'd like to check each like this example
So, you would like to check if StartWidth matches the EndWidth per segment?
Possibly like this
(defun c:Widthcheck ( / ent idx w1 w2) (setq ent (car (entsel)) idx 0) (repeat (fix (getpropertyvalue ent "EndParam")) (setq w1 (getpropertyvalue ent "vertices" idx "StartWidth")) (setq w2 (getpropertyvalue ent "vertices" idx "EndWidth")) (if (equal w1 w2 1e-3) (princ (strcat "\n" (itoa (1+ idx)) ": " (rtos w1))) (princ (strcat "\n" (itoa (1+ idx)) ": " (rtos w1) " vs. "(rtos w2)))) (setq idx (1+ idx))) (princ) )
the whole idea i was trying to do is similar to LM Advanced Polyoutline but out-process, and extract the constantwidth to generate individual surfaces. I am having some issues on some polylines that have varying constantwidth as shown here.
which originally generated from this
@prgmdl wrote:
I want to get the value of the Global width property of the individual segments of a polyline
... if a segment is of the same starting and ending width....
What do you want done with it once you get it? If you just want to see it, you can simply select the Polyline, and in the Geometry category in the Properties palette, pick "Current vertex" and it will show the first one with an X marker, and the starting and ending widths of the segment downstream from there. Pick in the up/down arrows to move through the vertices.
You can easily see whether the Start and End segment widths are the same [the segment has constant width].
And if they are not?
If you want something done with the information [such as to apply it within some AutoLisp function], all the Start and End segment widths are available in the Polyline's entity data.