Jump to content

Recommended Posts

Posted

I Want Required lisp Export Data of 3DPolyLine To CSV "Chainage" And "Elevation"

This lisp Proposed use for Cross Section.

Posted

Here is a pline co-ords example it will make a list of x y z points its up to you what you want to do next.

 

(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy (I numb xy)
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 3))
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)

; program starts here

(setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
(co-ords2xy)


Posted
Here is a pline co-ords example it will make a list of x y z points its up to you what you want to do next.

 

(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy (I numb xy)
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 3))
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)

; program starts here

(setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
(co-ords2xy)


 

Thank you sir for replay, But I want lisp file 3Dpolyline to Distance And E

Total Topography Center line.dwg

Required Sample.CSV

Posted

Not sure if this is what you need sanju2323

 

(Defun c:demo (/ csvfile cnt sn i a)
 (if (and
(= (getvar 'DwgTitled) 1)
(setq ss (ssget "_:S:E" '((0 . "POLYLINE"))))
     )
   (progn
     (setq csvfile_ (strcat (getvar 'DWgprefix)
		    (vl-filename-base (getvar 'dwgname))
		    ".csv"
	    )
     )
     (setq csvfile (open csvfile_ "w"))
     (write-line "Distance,Elevation" csvfile)
     (setq cnt 0 sn  (ssname ss 0))
(setq param (fix (vlax-curve-getEndParam sn)))
(repeat	(1+ param)
  (write-line
    (strcat
      (rtos (vlax-curve-getdistatparam sn cnt) 2 
      ","
      (rtos (last (vlax-curve-getpointatparam sn cnt)) 2 4)
    )
    csvfile
  )
  (setq cnt (1+ cnt))
)
     (close csvfile)
     (startapp "notepad" csvfile_)
   )
 )
)

Posted
Not sure if this is what you need sanju2323

 

(Defun c:demo (/ csvfile cnt sn i a)
 (if (and
   (= (getvar 'DwgTitled) 1)
   (setq ss (ssget "_:S:E" '((0 . "POLYLINE"))))
     )
   (progn
     (setq csvfile_ (strcat (getvar 'DWgprefix)
               (vl-filename-base (getvar 'dwgname))
               ".csv"
           )
     )
     (setq csvfile (open csvfile_ "w"))
     (write-line "Distance,Elevation" csvfile)
     (setq cnt 0 sn  (ssname ss 0))
   (setq param (fix (vlax-curve-getEndParam sn)))
   (repeat    (1+ param)
     (write-line
       (strcat
         (rtos (vlax-curve-getdistatparam sn cnt) 2 
         ","
         (rtos (last (vlax-curve-getpointatparam sn cnt)) 2 4)
       )
       csvfile
     )
     (setq cnt (1+ cnt))
   )
     (close csvfile)
     (startapp "notepad" csvfile_)
   )
 )
)

 

 

This Lisp Error shown as

" ; error: no function definition: VLAX-CURVE-GETENDPARAM"

Posted

@ Sanju Enter (vl-load-com) at the command Prompt

and Try again with pBe Codes

Posted
Not sure if this is what you need sanju2323

 

Maybe the OP's request is for horizontal distances (see posted dwg/csv).

 

:)

 

;Copyright  © pBe 
(Defun c:demo (/ csvfile cnt sn i a hyp h progr)
   (vl-load-com)
   (if (and
           (= (getvar 'DwgTitled) 1)
           (setq ss (ssget "_:S:E" '((0 . "POLYLINE")(-4 . "&=") (70 . )))
       )
       (progn
           (setq csvfile_
                    (strcat
                        (getvar 'DWgprefix)
                        (vl-filename-base (getvar 'dwgname))
                        ".csv"
                    )
           )
           (setq csvfile (open csvfile_ "w"))
           (write-line "Distance,Elevation" csvfile)
           (setq cnt 0 sn  (ssname ss 0) progr 0.)
           (setq param (fix (vlax-curve-getEndParam sn)))
           (repeat (1+ param)
               (if (> cnt 0)
                   (progn
                       (setq hyp (- (vlax-curve-getdistatparam sn cnt) (vlax-curve-getdistatparam sn (- cnt 1))))
                       (setq h (- (last (vlax-curve-getpointatparam sn cnt)) (last (vlax-curve-getpointatparam sn (- cnt 1)))))                       
                       (setq progr (+ progr (sqrt (- (* hyp hyp) (* h h)))))
                   )
                   (progn
                       (setq hyp (vlax-curve-getdistatparam sn cnt))
                       (setq h (last (vlax-curve-getpointatparam sn cnt)))
                       (setq progr 0.)
                   )
               )                          
               (write-line
                   (strcat
                       (rtos progr 2 7)
                       ","
                       (rtos (last (vlax-curve-getpointatparam sn cnt)) 2 4)
                   )
                   csvfile
               )
               (setq cnt (1+ cnt))
           )
           (close csvfile)
           (startapp "notepad" csvfile_)
       )
   )
   (princ)
)

Posted (edited)
Maybe the OP's request is for horizontal distances (see posted dwg/csv).

:)

 

:o . Whoa! You are right GP_

 

...
(progn
                       (setq hyp (- (vlax-curve-getdistatparam sn cnt) (vlax-curve-getdistatparam sn (- cnt 1))))
                       (setq h (- (last (vlax-curve-getpointatparam sn cnt)) (last (vlax-curve-getpointatparam sn (- cnt 1)))))                       
                       (setq progr (+ progr (sqrt (- (* hyp hyp) (* h h)))))
                   ....

 

Nice solution :thumbsup:

 

Here's another approach

 

(Defun c:demo2  (/ csvfile cnt sn i a b)
     (if (and
               (= (getvar 'DwgTitled) 1)
               (setq ss (ssget "_:S:E" '((0 . "POLYLINE")(-4 . "&=") (70 . )))
               )
           (progn
                 (setq csvfile_
                            (strcat (getvar 'DWgprefix)
                                    (vl-filename-base
                                          (getvar 'dwgname))
                                    ".csv"
                                    )
                       )
                 (setq csvfile (open csvfile_ "w"))
                 (write-line "Distance,Elevation" csvfile)
                 (setq cnt 0.0
                       a   nil
                       b   nil)
                 (setq pts (vlax-get
                                 (vlax-ename->vla-object (ssname ss 0))
                                 'Coordinates))
                 (while pts
                       (setq a   (cons (list (car pts) (cadr pts))
                                       a)
                             b   (Cons (caddr pts) b)
                             pts (cdddr pts)))
                 (Setq b    (reverse b) p '(0.0 0.0))
                 (mapcar (function (lambda (p1 p2 z)
                                          (write-line  (Strcat
                                               (rtos (setq cnt  (+ (distance p1 p2) cnt)) 2 7)
                                               ","
                                               (rtos z 2 4)
                                               )
                                                csvfile
                                                )
                                                    )
                                          )
                                    (cons p (setq a (reverse a)))
                                    (cons p (cdr a))
                       		b)
                (close csvfile)
                 (startapp "notepad" csvfile_)
                 )
           )
     (princ)
     )
(vl-load-com)
     

Edited by pBe
  • 6 years later...
Posted
(Defun c:demo2  (/ csvfile cnt sn i a b)
     (if (and
               (= (getvar 'DwgTitled) 1)
               (setq ss (ssget "_:S:E" '((0 . "POLYLINE")(-4 . "&=") (70 . )))
               )
           (progn
                 (setq csvfile_
                            (strcat (getvar 'DWgprefix)
                                    (vl-filename-base
                                          (getvar 'dwgname))
                                    ".csv"
                                    )
                       )
                 (setq csvfile (open csvfile_ "w"))
                 (write-line "Distance,Elevation" csvfile)
                 (setq cnt 0.0
                       a   nil
                       b   nil)
                 (setq pts (vlax-get
                                 (vlax-ename->vla-object (ssname ss 0))
                                 'Coordinates))
                 (while pts
                       (setq a   (cons (list (car pts) (cadr pts))
                                       a)
                             b   (Cons (caddr pts) b)
                             pts (cdddr pts)))
                 (Setq b    (reverse b) p '(0.0 0.0))
                 (mapcar (function (lambda (p1 p2 z)
                                          (write-line  (Strcat
                                               (rtos (setq cnt  (+ (distance p1 p2) cnt)) 2 7)
                                               ","
                                               (rtos z 2 4)
                                               )
                                                csvfile
                                                )
                                                    )
                                          )
                                    (cons p (setq a (reverse a)))
                                    (cons p (cdr a))
                       		b)
                (close csvfile)
                 (startapp "notepad" csvfile_)
                 )
           )
     (princ)
     )
(vl-load-com)

I get error

; error: extra right paren on input
_$ 

Posted
     (princ)
     )
) ; this is missing code not tested further
(vl-load-com)

 

Posted

; error: extra right paren on input
_1$ 

Even same error after adding missing  ")"

(startapp "notepad" csvfile_)
                 )
           )
     (princ)
     )
  )
(vl-load-com)
Posted

(setq ss (ssget "_:S:E" '((0 . "POLYLINE")(-4 . "&=") (70 . ? ))))

Posted

This is likely a byproduct of the "upgrade" to the forum software - I imagine the code should read:

(setq ss (ssget "_:S:E" '((0 . "POLYLINE")(-4 . "&=") (70 . 8))))

When the forum software was updated, all occurrences of "8)" in all code snippets were removed.

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