Jump to content

Lwpolyline Length (Vertex to vertex)


srinivasarajug

Recommended Posts

Dear Friends

 

I need a one lisp program i.e. Lwpolyline total length and length between the vertex to vertex it's should be export as text file.

 

pls give the solution

 

Thank You

Vasu

Link to comment
Share on other sites

Was bored

 

(defun c:PlLen (/ i ss file ent j str)
 (vl-load-com)

 (cond ((and (setq i -1 ss (ssget '((0 . "LWPOLYLINE"))))
             (setq file (getfiled "Output File" "" "txt" 1)))
        (setq file (open file "w"))
        
        (while (setq ent (ssname ss (setq i (1+ i))))
          (setq j (1- (vlax-curve-getStartParam ent)) Str "")

          (while (<= (setq j (1+ j)) (vlax-curve-getEndParam ent))

            (setq Str
              (strcat Str
                (rtos (- (vlax-curve-getDistatParam ent j)
                           (if (zerop j) 0
                             (vlax-curve-getDistatParam ent (1- j)))) 2 2) (chr 9))))

          (write-line (strcat Str (rtos (vlax-curve-getDistatParam ent
                                          (vlax-curve-getEndParam ent)) 2 2)) file))

        (close file)))

 (princ))

Link to comment
Share on other sites

Thank u very much for given code and one more thing i need the each vertex coordinate and length in text file

 

sorry if you are feeling problem

 

Thank You

 

Vasu

Link to comment
Share on other sites

Was bored

 

(defun c:PlLen (/ i ss file ent j str)
 (vl-load-com)

 (cond ((and (setq i -1 ss (ssget '((0 . "LWPOLYLINE"))))
             (setq file (getfiled "Output File" "" "txt" 1)))
        (setq file (open file "w"))

        (while (setq ent (ssname ss (setq i (1+ i))))
          (setq j (1- (vlax-curve-getStartParam ent)) Str "")

          (while (<= (setq j (1+ j)) (vlax-curve-getEndParam ent))

            (setq Str
              (strcat Str
                (rtos (- (vlax-curve-getDistatParam ent j)
                           (if (zerop j) 0
                             (vlax-curve-getDistatParam ent (1- j)))) 2 2) (chr 9))))

          (write-line (strcat Str (rtos (vlax-curve-getDistatParam ent
                                          (vlax-curve-getEndParam ent)) 2 2)) file))

        (close file)))

 (princ))

 

Why is the first point in the answer file always zero? Sorry to be so dense.

Link to comment
Share on other sites

>> Steve,

 

You're not dense :P

 

I have formatted it in such a way that each entry in the file is the distance to each vertex in turn (from the start of the curve), hence the distance from the start vertex to the start vertex is always zero.. - I probably could have ignored this point, but I wanted the number of distances to equal the number of points... with the length being the last entry.

Link to comment
Share on other sites

>> Steve,

 

You're not dense :P

 

I have formatted it in such a way that each entry in the file is the distance to each vertex in turn (from the start of the curve), hence the distance from the start vertex to the start vertex is always zero.. - I probably could have ignored this point, but I wanted the number of distances to equal the number of points... with the length being the last entry.

 

as he utters a sigh of relief !!! thanks LM, I'm not so dizzy now.

Link to comment
Share on other sites

  • 2 years later...

Hi friends,

This is what I wanted from ages!!:)

but I nneed result that means segment lengths as stored in variables as that I can assign them as values of attributes in a block!

Can we do this!:(

 

Thanks in advance.

 

corfish

Link to comment
Share on other sites

Try this variant

(defun C:TEST ( / SegmLen ss lst)
 (defun SegmLen (e / i l)
   (repeat (setq i (fix (vlax-curve-GetEndParam e)))
     (setq l (cons (apply '- (mapcar '(lambda (x) (vlax-curve-GetDistAtParam e x)) (list i (setq i (1- i))))) l))
   )
 )
 (if
   (setq ss (ssget ":E:S" '((0 . "*POLYLINE"))))
   (progn
     (setq lst (SegmLen (ssname ss 0)))
     (princ lst) ;just to show result
     ;do whatever you want with lst variable
   )
 )
 (princ)
)

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...