TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mcn on November 18, 2009, 10:46:24 AM

Dear All,
I have one project in which i have to draw polylines and points.
The length of a polyline must be 50m and after one polyline i have to put a point.
There is a lisp for this?
or a lisp to select the line and then to splitit into segments of 50m and add point at the end of the segments?
In advanced Thank You!
B.R.,
Marius

have you looked at using the DIVIDE or MEASURE commands?

Marius,
Are the polylines one object with 50m segments or separate plines 50m long?
Is the point object required at the beginning & end of the pline or just at 50m?

How about a making a block then insert it / rotate it / explode it?

Just to add points to a pline.
(defun c:AddPoints (/ ent elst pts)
(while
(cond
((null (setq ent (car (entsel "\nSelect pline."))))
(princ "\nMissed, Try again.")
)
((equal (assoc 0 (entget ent)) '(0 . "LWPOLYLINE")) nil)
(t (princ "\nError Not a ployline. Try again."))
)
)
(setq elst (entget ent)
pts (mapcar 'cdr (vlremoveifnot '(lambda (x) (= 10 (car x))) elst))
)
(mapcar
(function
(lambda (pt)
(entmake
(list (cons 0 "POINT")
(cons 6 "BYLAYER")
(cons 8 "0") ; layer, comment out for current layer
(cons 10 pt)
(cons 62 256)
)
)
)
)
pts
)
(princ)
)

or if all it is a a straight polyline segment (assuming no arcs); one could
draw the polyline, place a point on one end.
select both objects, and make a group out of them...then copy the group as many time as was required...
or without making a group..select the objects...grab hold of one of the grips....hit the SPACEBAR to switch from the STRETCH command, into the COPY command, and then copy as many as was required...
however if it a continuous polyline with arcs...that is in need of a point at a specified distance I would use Divide, or Measure command.

Marius,
Are the polylines one object with 50m segments or separate plines 50m long?
Is the point object required at the beginning & end of the pline or just at 50m?
CAB,
the plines should be separate objects 50m long each segment.
The point is required on both sides beginning and end.

How are you placing them? Picking start & end point or start point & angle or other method?
The routine I posted will add points to existing plines picked one at a time. It may be modified to get them via selection set.

Well, Start& end is enough.

I can change the lisp to select plines but a filter should be used:
Only specific layers?
Only 50m long?
Only one segment?
Will they every be touching each other? (end to end)

Only 50m long.
yes End to end, as you mentioned
Thanks.

The only drawback with this routine is that plines end to end will have two points at the vertex.
Can you live with that?
(defun c:AddPoints (/ i ss ent elst pts)
;; get only LW plines with 2 vertices
(princ "\nSelect pline.")
(setq ss (ssget '((0 . "LWPOLYLINE") (90 . 2))))
(setq i 1)
(while (setq ent (ssname ss (setq i (1+ i))))
(setq elst (entget ent)
pts (mapcar 'cdr (vlremoveifnot '(lambda (x) (= 10 (car x))) elst))
)
;; ignore if not equal to 50 units
(if (equal (distance (car pts) (cadr pts)) 50.0 0.01)
(mapcar
(function
(lambda (pt)
(entmake
(list (cons 0 "POINT")
(cons 6 "BYLAYER")
(cons 8 "0") ; layer, comment out for current layer
(cons 10 pt)
(cons 62 256)
)
)
)
)
pts
)
)
)
(princ)
)
(princ "\nAddPoints loaded, Enter AddPoints to run.")
(princ)

On second thought, maybe this will resolve the extra points issue.
(defun c:AddPoints (/ i ss ent elst pts ptsOld)
;; get only LW plines with 2 vertices
(princ "\nSelect pline.")
(setq ss (ssget '((0 . "LWPOLYLINE") (90 . 2))))
(setq i 1)
(while (setq ent (ssname ss (setq i (1+ i))))
(setq elst (entget ent)
pts (mapcar 'cdr (vlremoveifnot '(lambda (x) (= 10 (car x))) elst))
)
;; ignore if not equal to 50 units
(if (equal (distance (car pts) (cadr pts)) 50.0 0.01)
(mapcar
(function
(lambda (pt)
(if (not (vlposition pt ptsOld))
(progn
(entmake
(list (cons 0 "POINT")
(cons 6 "BYLAYER")
(cons 8 "0") ; layer, comment out for current layer
(cons 10 pt)
(cons 62 256)
)
)
(setq ptsOld (cons pt ptsOld))
)
)
)
)
pts
)
)
)
(princ)
)
(princ "\nAddPoints loaded, Enter AddPoints to run.")
(princ)

Thanks, it's working, but what about a big pline to be splited at 50m and then add the points?

Questions:
Do you need a vertex at 50m and a point? If so remove any other vertex?
Will the pline be exactly multiples of 50m?

What about , you upload a sample dwg?