TheSwamp

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

Title: polyline at 60m
Post 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 split-it into segments of 50m and add point at the end of the segments?

In advanced Thank You!

B.R.,
Marius
Title: Re: polyline at 60m
Post by: mjfarrell on November 18, 2009, 10:48:16 AM
have you looked at using the DIVIDE or MEASURE commands?
Title: Re: polyline at 60m
Post by: CAB on November 18, 2009, 11:01:31 AM
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?
Title: Re: polyline at 60m
Post by: TimSpangler on November 18, 2009, 11:03:19 AM
How about a making a block then insert it / rotate it / explode it?
Title: Re: polyline at 60m
Post by: CAB on November 18, 2009, 11:27:23 AM
Just to add points to a pline.
Code: [Select]
(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 (vl-remove-if-not '(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)
)
Title: Re: polyline at 60m
Post by: mjfarrell on November 18, 2009, 12:16:26 PM
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.
Title: Re: polyline at 60m
Post by: mcn on November 18, 2009, 09:51:26 PM
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.
Title: Re: polyline at 60m
Post by: CAB on November 18, 2009, 11:17:07 PM
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.
Title: Re: polyline at 60m
Post by: mcn on November 19, 2009, 03:13:43 AM
Well, Start& end is enough.
Title: Re: polyline at 60m
Post by: CAB on November 19, 2009, 08:27:13 AM
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)
Title: Re: polyline at 60m
Post by: mcn on November 19, 2009, 09:31:57 AM
Only 50m long.
yes End to end, as you mentioned

Thanks.
Title: Re: polyline at 60m
Post by: CAB on November 19, 2009, 10:49:18 AM
The only drawback with this routine is that plines end to end will have two points at the vertex.
Can you live with that?
Code: [Select]
(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 (vl-remove-if-not '(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)
Title: Re: polyline at 60m
Post by: CAB on November 19, 2009, 10:58:59 AM
On second thought, maybe this will resolve the extra points issue.
Code: [Select]
(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 (vl-remove-if-not '(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 (vl-position 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)
Title: Re: polyline at 60m
Post by: mcn on November 20, 2009, 03:10:44 AM
Thanks, it's working, but what about a big pline to be splited at 50m and then add the points?
Title: Re: polyline at 60m
Post by: CAB on November 20, 2009, 09:20:21 AM
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?
Title: Re: polyline at 60m
Post by: DEVITG on November 22, 2009, 06:52:39 PM
What about , you upload a sample dwg?