Jump to content

Distribute vertices along a polyline with a specific length interval


samifox

Recommended Posts

Hi

I search the net for a lisp for adding or distributing verticesalong a polyline, but I couldn’t find something that is close enough to what I need.

I simply need to add vertices along a polyline by defining alength between them. Exactly as the measure command does to a poly , but insteadof dots I need it to be vertices

Thanks

Shay

Link to comment
Share on other sites

(Defun c:demo ()
 (if (and (setq pline (car (entsel "\nSelect Polyline:")))
          (eq (cdr (assoc 0 (entget pline))) "LWPOLYLINE")
          (setq int (getdist "\nEnter Interval:"))
          (setq in int)
     )
   (while (Setq pt (vlax-curve-getPointAtDist pline int))
     (setq ppt (vlax-curve-getparamatpoint pline pt))
     (vlax-invoke
       (vlax-ename->vla-object pline)
       'AddVertex
       (1+ (fix ppt))
       (list (car pt) (Cadr pt))
     )
     (setq int (+ int in))
   )
 )
)

Link to comment
Share on other sites

(Defun c:demo ()
 (if (and (setq pline (car (entsel "\nSelect Polyline:")))
          (eq (cdr (assoc 0 (entget pline))) "LWPOLYLINE")
          (setq int (getdist "\nEnter Interval:"))
          (setq in int)
     )
   [b][color=red](while (Setq pt (vlax-curve-getPointAtDist pline int))
     (setq ppt (vlax-curve-getparamatpoint pline pt))
     (vlax-invoke
       (vlax-ename->vla-object pline)
       'AddVertex
       (1+ (fix ppt))
       (list (car pt) (Cadr pt))
     )
     (setq int (+ int in))
   )
 )
)
[/color][/b]

 

hello

 

im analyzing your code , i need help with the second paragraph just after the "while loop".

 

 

how vlax-curve-getPointAtDist and vlax-curve-getparamatpoint are being used here?

 

Thanks

Shay

 

  • Like 1
Link to comment
Share on other sites

hi

 

this code ask the user for interval and than distribute verts along the poly, but the interval is not quite precise because its being rounded by the fix() every iteration.

im trying to implement this code in my project but this problem cannot be solved in this way.

 

can someone post a code that does the same but with respect to all decimal digits and without rounding off?

 

Thanks

Shay

Link to comment
Share on other sites

The function fix on this particular code pertains to the segment number samifox. a point after the fact.

 

Show me and post a sample drawing where the result is not precise and lets see what we can do to "fix" the code (pun intended)

 

:)

Link to comment
Share on other sites

code ask for point a and b and for polylines, than it sends points a and b to be divided and returns what is the segment length and the number of segments. than it adds verts as the number of the segments and (suppose to) distribute them in segment length interval

 

you can see the xlines are distribute correctly but the verts are not. i want the verts to be distribute exactly as the xlines

 

Thanks

Shay

 

 

(vl-load-com)
(defun c:m ()
 (setq userData (wl:getUserData))
 (setq proData (extractSegment userData 6.0 8.0))
 (drawVers userData proData)
)

(defun wl:getUserData (/ ptst pten)
 (if (setq ptst (getpoint "\nStart point of path: "))
   (if    (setq pten (getpoint ptst "\nEndpoint of path: "))
     (progn
   ;(setq ptst (trans ptst 1 0) pten (trans pten 1 0))
   (setq wall (getPoly wall "\nSelect Wall eleveation line")) 
   (setq front (getPoly front "\nSelect Front eleveation line"))
   (setq back (getPoly back "\nSelect Back eleveation line"))
   (setq exist (getPoly exist "\nSelect Exist eleveation line"))
   (list
     (cons 10 ptst)
     (cons 11 pten)
     (cons 41 (distance ptst pten))
     (cons 51 wall)
     (cons 52 front)
     (cons 53 back)
     (cons 54 exist)
   ) ;_list

     ) ;_progn
   ) ;_if endpt
 ) ;_if strp
) ;_defun


(defun getPoly (ent msg)
 (if (setq ent (car (entsel msg)))
   (if    (eq (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
     ent
   ) ;_if
   (alert "\nThe selected object is not a polyline")
 ) ;_if
) ;_defun

;_______________________________________________________________________________________________________

(defun extractSegment (userData minv maxv / ptst pten d n6 n8 n1 n2 n k stpt enpt)
 (setq ptst (cdr (assoc 10 userData)))
 (setq pten (cdr (assoc 11 userData)))
 (setq d (cdr (assoc 41 userData)))


                   ;getiing unrestricted devition
 (setq n6 (/ d 6.0))
 (setq n8 (/ d 8.0))

(cond 
       ( (equal n6 1.0 1e-15);what is 1e-15???
         (setq n 1.0)
       )
       ( (and (null n) (> n6 1.0))
         (setq n1 (fix n8) n2 (+ (fix n6) 1))
         (repeat (+ (- n2 n1) 1)
           (if (<= 6.0 (if (/= n1 0) (/ d (float n1)) 0.0) 8.0)
             (setq n n1)
             (if (null n) (setq n nil))
           )
           (setq n1 (1+ n1))
         )
       )
       ( (< n6 1.0)
         (setq n nil)
       )
 )
 (if n
   (progn
     (setq k -1.0)
     (repeat (fix n)
       (setq stpt (mapcar '+ ptst (mapcar '* (mapcar '/ (mapcar '- pten ptst) (list n n n)) (list (setq k (1+ k)) k k))))
       (setq enpt (mapcar '+ stpt (mapcar '/ (mapcar '- pten ptst) (list n n n))))
       (entmake (list '(0 . "LINE") '(62 . 1) (cons 10 stpt) (cons 11 enpt) (list 210 0.0 0.0 1.0)))
   (command "xline" "V" stpt "")
     )
   )
   (prompt "\nOriginal line couldn't be divided into lines with 6-8 units lengths criteria")
 )
 
 (list
   (cons 81 n)
   (cons 82 (distance stpt enpt) )
   )
 
)

;_______________________________________________________________________________________________________

(Defun drawVers    (userData proData)

 (setq wall (cdr (assoc 51 userData)))
 (setq front (cdr (assoc 52 userData)))
 (setq back (cdr (assoc 53 userData)))
 (setq exist (cdr (assoc 54 userData)))

 (setq seglen (cdr (assoc 82 proData)) )
 (setq segcnt (cdr (assoc 81 proData)) )
 (setq in segcnt)

 
(while (Setq pt (vlax-curve-getPointAtDist wall seglen))
     (setq ppt (vlax-curve-getparamatpoint wall pt))
     (vlax-invoke
       (vlax-ename->vla-object wall)
       'AddVertex
       (1+ (fix ppt))
       (list (car pt) (Cadr pt))
     )
     (setq seglen (+ seglen in))
   )

)

Link to comment
Share on other sites

I don't get it samifox. what exactly does it do?

 

im my dally work i do all the steps the code does. they are all predictable so they can be coded.

 

im working in a construction firm, so the architect give us his drawing with the wall and the elevation in front and in the back of the wall. our work is to measure the distance between the front and the back elevation and contract a base wall underground to hold the wall.

 

so the code ask the wall distance and the front and back lines, than divide the distance into smaller segments , by dividing that i know what is each segment length and how many segment there are.

 

than i want to distribute vertices along the back and front lines so i can know the Y of each elevation on each segment,

 

if i know the info i can than program how to draw and under what conditions

 

hope its clear

 

the problem:

 

for some reason the verts are not distribute correctly, the segment length should be the interval but its not

 

maybe if you can explain to me the second paragraph (RED) of your code it will help me to troubleshot it

 

Thanks

Shay

Link to comment
Share on other sites

First glance. Osnaps

 

There's a reason why i'm asking for a sample drawing or an [image if you prefer], so that we wont be postings questions and answers back and forth. Understanding what you are trying to do will make it easier for us here to give you the appropriate solution.

 

Anyhoo...

 

maybe if you can explain to me the second paragraph (RED) of your code it will help me to troubleshot it

 

Like i 've said. FIX had nothing to do with the interval value.. [not directly that is].

 

I'll suggest you read up on vlax-curve-getPointAtDist and vlax-curve-getparamatpoint on the help file and tell me what part of that you're having trouble understanding.

Link to comment
Share on other sites

The code works great PBE

I don't have an immediate use for it but it does work just fine when I tested it

Thanks

~Greg

(Defun c:demo ()
 (if (and (setq pline (car (entsel "\nSelect Polyline:")))
          (eq (cdr (assoc 0 (entget pline))) "LWPOLYLINE")
          (setq int (getdist "\nEnter Interval:"))
          (setq in int)
     )
   (while (Setq pt (vlax-curve-getPointAtDist pline int))
     (setq ppt (vlax-curve-getparamatpoint pline pt))
     (vlax-invoke
       (vlax-ename->vla-object pline)
       'AddVertex
       (1+ (fix ppt))
       (list (car pt) (Cadr pt))
     )
     (setq int (+ int in))
   )
 )
)

Link to comment
Share on other sites

(Defun c:demo ()   (if (and (setq pline (car (entsel "\nSelect Polyline:")))            (eq (cdr (assoc 0 (entget pline))) "LWPOLYLINE")            (setq int (getdist "\nEnter Interval:"))            (setq in int)       )     [color=red][b](while (Setq pt (vlax-curve-getPointAtDist pline int))       (setq ppt (vlax-curve-getparamatpoint pline pt))       (vlax-invoke         (vlax-ename->vla-object pline)         'AddVertex         (1+ (fix ppt))         (list (car pt) (Cadr pt))       )       (setq int (+ int in))     )[/b][/color]   ) )

 

thanks for your timr dude

 

here the lines i dont understand (RED)

 

 

  1. after getting the poly id and interval info you assign in to int why?
  2. (than the while loops until nill)
  3. pt get the first point according to the interval
  4. ppt than get the distance up to this point
  5. than you invoke conversion and the call AddVertex
  6. than you advance ppt by 1 , why?
  7. than you make a list of the entity, why?

(its open to everyone:) )

 

Thanks

Shay

Link to comment
Share on other sites

samifox, after examining your code, me think you should change

 

(setq in segcnt)

 

to

 

(setq in seglen)

 

After, you should test your code again...

 

M.R.

Link to comment
Share on other sites

Mario...do you know you are my king!!!

 

Thank for reading thru all the thread

 

You make my day

 

God bless you

shay

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...