Jump to content

Recommended Posts

Posted

Hi guys,

I would need a lisp for exporting to csv or txt file 2d polyline vertices from a cross section based on the picks:

1. pick the chainage

2. pick the 0.0 offset line

3. pick the reference level line

4. pick the reference level elevation text

5. pick the polyline for exporting vertices

 

The lisp would calculate offsets and elevations comparing to picked 0.0 offset line and given reference level.

 

the data exported to csv/txt file would have structure like this:

 

chainage

offset on the left;elevation

(...)

offset on the right;elevation

(...)

 

for example:

25+500

-5.0;212.22

-3.0;200.50

1.1;205.69

4.6;202.37

 

Does anybody have a code which could be used for developing such workflow?

Posted

Its called Civ3d or Civil site design or Magnet or probably others any decent civil design software can do export of road design reports.

 

As a lisp answer the simplest is to read the cross section text its normally two rows so pretty easy, pick chainage text, select row, select row, all done.

Posted

The problem is I have pure DWG drawing, those are not cross sections from "active" road corridor model so cannot use it in Civil3D or other software to extrude reports.

As for your second advice it is not a solution cause in the rows you got usually TOP surface levels, and what I need is to export ANY polyline on the cross section (like specific pavement layers etc. which are of course lower than TOP surface), that's the intention here.

 

I found is a lisp which exports polyline to txt file, but it I have no idea how to set a Local UCS and export the vertices in a reference to new level (Local UCS) - the export always goes in a reference to Wold UCS...

; ----------------------------------------------------------------------
;             (Export LWPOLYLINE Vertices & Points to File)
;            Copyright (C) 2000 DotSoft, All Rights Reserved
;                   Website: http://www.dotsoft.com
; ----------------------------------------------------------------------
; DISCLAIMER:  DotSoft Disclaims any and all liability for any damages
; arising out of the use or operation, or inability to use the software.
; FURTHERMORE, User agrees to hold DotSoft harmless from such claims.
; DotSoft makes no warranty, either expressed or implied, as to the
; fitness of this product for a particular purpose.  All materials are
; to be considered ‘as-is’, and use of this software should be
; considered as AT YOUR OWN RISK.
; ----------------------------------------------------------------------

(defun c:ptexport ()
  (setq sset (ssget '((-4 . "<OR")(0 . "POINT")
                      (0 . "LWPOLYLINE")(-4 . "OR>"))))
  (if sset
    (progn
      (setq itm 0 num (sslength sset))
      (setq fn (getfiled "Point Export File" "" "txt" 1))
      (if (/= fn nil)
        (progn
          (setq fh (open fn "w"))
          (while (< itm num)
            (setq hnd (ssname sset itm))
            (setq ent (entget hnd))
            (setq obj (cdr (assoc 0 ent)))
            (cond
              ((= obj "POINT")
                (setq pnt (cdr (assoc 10 ent)))
                (princ (strcat (rtos (car pnt) 2 8) ","
                               (rtos (cadr pnt) 2 8) ","
                               (rtos (caddr pnt) 2 8)) fh)
                (princ "\n" fh)
              )
              ((= obj "LWPOLYLINE")
                (if (= (cdr (assoc 38 ent)) nil)
                  (setq elv 0.0)
                  (setq elv (cdr (assoc 38 ent)))
                )
                (foreach rec ent
                  (if (= (car rec) 10)
                    (progn
                      (setq pnt (cdr rec))
                      (princ (strcat (rtos (car pnt) 2 8) ","
                                     (rtos (cadr pnt) 2 8) ","
                                     (rtos elv 2 8)) fh)
                      (princ "\n" fh)
                    )
                  )
                )
              )
              (t nil)
            )
            (setq itm (1+ itm))
          )
          (close fh)
        )
      )
    )
  )
  (princ)
)

(princ "\nPoint Export loaded, type PTEXPORT to run.")
(princ)

 

Posted
3 hours ago, jackson5 said:

 

I found is a lisp which exports polyline to txt file, but it I have no idea how to set a Local UCS and export the vertices in a reference to new level (Local UCS) - the export always goes in a reference to Wold UCS...

 

not sure  what  is your cross section view

  

(defun c:mu (/ p y ) ; move ucs
  (princ "\nCurrent UCS origin : ")
  (while (not (and (princ (getvar 'ucsorg))(setq p (getpoint "\nSpecify base point at datum level line & zero offset line: "))
		   (setq y (getreal "\nEnter known reference level elevation (datum) : "))
		   (vl-cmdf "_.UCS" "MOVE" (mapcar '- p (list 0.0 y 0.0)))
		   )
	      )
    )
   (princ (strcat "\nX=0.00 Y="(rtos y 2 2) ) )
  (princ)
  ) 

example you have a level datum line = 100.00, you pick at cross section X&Y axis as base, i.e:  X should be 0.0 , Y= level elevation 100.00


Command: mu

Current UCS origin : (-61.6464 134.407 0.0) 
Specific base point at datum level line & zero offset line :  user picked 
Enter known reference level elevation (datum) : 100

X=0.00 Y=100.00

 

Then you can check the polyline  coordinates by command ID or LIST, (The X value -ve LHS & +ve RHS , Y=elevation level )

or export the  coordinates to EXCEL using LISP etc..

 

Posted (edited)

Thanks for the tip

I tried to combine those two codes. I set new UCS origin (also tried to check the coordinates of polyline using LIST command - they are of course referenced to new UCS) but the rest of the code somehow considers the global UCS while exporting to file - where's the problem?

; ----------------------------------------------------------------------
;             (Export LWPOLYLINE Vertices & Points to File)
;            Copyright (C) 2000 DotSoft, All Rights Reserved
;                   Website: http://www.dotsoft.com
; ----------------------------------------------------------------------
; DISCLAIMER:  DotSoft Disclaims any and all liability for any damages
; arising out of the use or operation, or inability to use the software.
; FURTHERMORE, User agrees to hold DotSoft harmless from such claims.
; DotSoft makes no warranty, either expressed or implied, as to the
; fitness of this product for a particular purpose.  All materials are
; to be considered ‘as-is’, and use of this software should be
; considered as AT YOUR OWN RISK.
; ----------------------------------------------------------------------


(defun c:ptexport ()

;(defun c:mu (/ p y ) ; move ucs
  (princ "\nCurrent UCS origin : ")
  (while (not (and (princ (getvar 'ucsorg))(setq p (getpoint
"\nSpecify base point at datum level line & zero offset line:
"))
		   (setq y (getreal "\nEnter known reference level elevation
(datum) : "))
		   (vl-cmdf "_.UCS" "MOVE" (mapcar '- p (list 0.0 y 0.0)))
		   )
	      )
    )
   (princ (strcat "\nX=0.00 Y="(rtos y 2 2) ) )
  (princ)
;  ) 

  (setq sset (ssget '((-4 . "<OR")(0 . "POINT")
                      (0 . "LWPOLYLINE")(-4 . "OR>"))))

  (if sset
    (progn
      (setq itm 0 num (sslength sset))
      (setq fn (getfiled "Point Export File" "" "txt" 1))
      (if (/= fn nil)
        (progn
          (setq fh (open fn "w"))
          (while (< itm num)
            (setq hnd (ssname sset itm))
            (setq ent (entget hnd))
            (setq obj (cdr (assoc 0 ent)))
            (cond
              ((= obj "POINT")
                (setq pnt (cdr (assoc 10 ent)))
                (princ (strcat (rtos (car pnt) 2 8) ","
                               (rtos (cadr pnt) 2 8) ","
                               (rtos (caddr pnt) 2 8)) fh)
                (princ "\n" fh)
              )
              ((= obj "LWPOLYLINE")
                (if (= (cdr (assoc 38 ent)) nil)
                  (setq elv 0.0)
                  (setq elv (cdr (assoc 38 ent)))
                )
                (foreach rec ent
                  (if (= (car rec) 10)
                    (progn
                      (setq pnt (cdr rec))
                      (princ (strcat (rtos (car pnt) 2 8) ","
                                     (rtos (cadr pnt) 2 8) ","
                                     (rtos elv 2 8)) fh)
                      (princ "\n" fh)
                    )
                  )
                )
              )
              (t nil)
            )
            (setq itm (1+ itm))
          )
          (close fh)
        )
      )
    )
  )
  (princ)
)

(princ "\nPoint Export loaded, type PTEXPORT to run.")
(princ)

 

Edited by jackson5
Posted (edited)
10 hours ago, jackson5 said:

Thanks for the tip

I tried to combine those two codes. I set new UCS origin (also tried to check the coordinates of polyline using LIST command - they are of course referenced to new UCS) but the rest of the code somehow considers the global UCS while exporting to file - where's the problem?

 

 


dxf 10  in WCS , to transform example : (trans pt 0 1)

 

(vl-load-com)
(defun c:ptexport (/ *error* ss fn f sep en vo pt) ; export lwpoly vertices ucs coordinates

  (defun *error* (msg)
    (if	f (close f) ) ) ;minimal trap
  
  (if (and (setq ss (ssget '((0 . "POINT,LWPOLYLINE"))))
	   (setq sep (list '(sep l) '(substr (apply 'strcat (mapcar ''((x) (strcat sep (rtos x 2 3))) l)) (+ 1 (strlen sep )) ))
		 fn  (strcat (getvar 'tempprefix) "xyz.csv")
		 f   (open fn "w")
		 )
	   (repeat (setq i (sslength ss))
	     (setq en (ssname ss (setq i (1- i)))
		   vo (vlax-ename->vla-object en)
		   pt (vlax-get vo 'coordinates)
		   )
	     (if (= (length pt) 3)
	       (write-line (sep ","(trans pt 0 1)) f)
	       (while pt
		 (write-line
		   (setq str (sep "," (trans (list (car pt) (cadr pt) (vla-get-elevation vo)) en 1)))
		   f
		   )
		 (setq pt (cddr pt))
		 )
	       )
	      t
	     )
	   )
    (progn (if f (close f))
;;;	   (startapp "notepad" fn)
           (vl-cmdf "_.SHELL" (strcat "CLIP < " fn))
           (alert "Clipboard ready, [Ctrl+V] paste into EXCEL/WORD docs etc.. ")
	   )
    (vl-cmdf "_.START"
	     "https://www.cadtutor.net/forum/topic/66243-export-cross-section-polyline-to-csv/"
	     )
    )
  (princ)
  )

 

in order to optimize speed instead of open/activate new EXCEL after calling routine,

my suggestion : output coordinates are stored as CLIPBOARD, you just paste them into any opened EXCEL/WORD/TEXT documents etc..

 

Edited by hanhphuc
Posted

Cool, this code works with local UCS and the coordinates are referenced to new UCS, that's what I was looking for.

The reason why in this case it would be better to export to external txt file directly from the script is that the idea is to loop the procedure and carry on with consequent cross sections, one by one. Could you modify the code to export to external file? I noticed that there is a line commented, what's the reason for it?

;;;	   (startapp "notepad" fn)
Posted (edited)
1 hour ago, jackson5 said:

Cool, this code works with local UCS and the coordinates are referenced to new UCS, that's what I was looking for.

The reason why in this case it would be better to export to external txt file directly from the script is that the idea is to loop the procedure and carry on with consequent cross sections, one by one. Could you modify the code to export to external file? I noticed that there is a line commented, what's the reason for it?


;;;	   (startapp "notepad" fn)

 

Just try to uncomment & comment see..  that's the way of learning - trail & error.

That snippet exactly opens the external file with notepad app :)

 


;;snippet

    (progn (if f (close f))
       (startapp "notepad" fn)
           ;;(vl-cmdf "_.SHELL" (strcat "CLIP < " fn))
           ;;(alert "Clipboard ready, [Ctrl+V] paste into EXCEL/WORD docs etc.. ")
	   )
       
       ;;snippet...

 

Edited by hanhphuc
Grammar
Posted (edited)

Thanks for your reply, I am getting closer

 

I modified the code:

1. I added the option to pick the reference level from text string. This will be used to set local UCS (it works:)

2. I added the option to pick the cross-section chainage (text string)

3. What is missing is looping the whole operation for multiple sections and exporting the set of data to external file like below

 

sample file structure:

 

25+500 (from text string - chainage)

-5.0;212.22

-3.0;200.50

1.1;205.69

4.6;202.37

 

25+600

-2.0;213.22

-3.0;201.50

5.1;205.69

6.6;202.37

 

25+700

-4.0;202.22

-2.0;220.50

5.1;212.69

8.6;212.37

 

I put some comments in the code

Could you help with this?

 

(vl-load-com)
(defun c:ptexport (/ *error* ss fn f sep en vo pt) ; export lwpoly vertices ucs coordinates

;loop should start here

  (command "_ucs" "_w")

;(defun c:mu (/ p y ) ; move ucs
  (princ "\nCurrent UCS origin : ")
  (while (not (and (princ (getvar 'ucsorg))(setq p (getpoint "\nSpecify base point at datum level line & zero offset line:"))

  (setq
    chainage (car (entsel "\nPick the cross section chainage: "))
    chainagedata (entget chainage)
    chainagestr (cdr (assoc 1 chainagedata))
  ); setq

  (setq
    reflev (car (entsel "\nPick the reference level: "))
    reflevdata (entget reflev)
    reflevstr (cdr (assoc 1 reflevdata))
  ); setq

  (setq y (atof reflevstr)) ; convert string to real

;		   (setq y (getreal "\nEnter known reference level elevation (datum) : "))
		   (vl-cmdf "_.UCS" "MOVE" (mapcar '- p (list 0.0 y 0.0)))
		   )
	      )
    )
   (princ (strcat "\nX=0.00 Y="(rtos y 2 2) ) )
  (princ)
;  ) 

  (defun *error* (msg)
    (if	f (close f) ) ) ;minimal trap
  
  (if (and (setq ss (ssget '((0 . "POINT,LWPOLYLINE"))))
	   (setq sep (list '(sep l) '(substr (apply 'strcat (mapcar ''((x) (strcat sep (rtos x 2 3))) l)) (+ 1 (strlen sep )) ))
		 fn  (strcat (getvar 'tempprefix) "xyz.csv")
		 f   (open fn "w")
		 )
	   (repeat (setq i (sslength ss))
	     (setq en (ssname ss (setq i (1- i)))
		   vo (vlax-ename->vla-object en)
		   pt (vlax-get vo 'coordinates)
		   )
	     (if (= (length pt) 3)
	       (write-line (sep ","(trans pt 0 1)) f)
	       (while pt
		 (write-line
		   (setq str (sep "," (trans (list (car pt) (cadr pt) (vla-get-elevation vo)) en 1)))
		   f
		   )
		 (setq pt (cddr pt))
		 )
	       )
	      t
	     )
	   )

;loop should finish here

;the data from few cross sections should be exported below

    (progn (if f (close f))
 	   (startapp "notepad" fn)
        ;   (vl-cmdf "_.SHELL" (strcat "CLIP < " fn))
        ;   (alert "Clipboard ready, [Ctrl+V] paste into EXCEL/WORD docs etc.. ")
	   )
    (vl-cmdf "_.START"
	     "https://www.cadtutor.net/forum/topic/66243-export-cross-section-polyline-to-csv/"
	     )
    )
  (princ)          
  )

 

A sample cross-section:

image.thumb.png.8c460e8ba57520310c4406200477dd2b.png

 

Edited by jackson5
Posted
51 minutes ago, jackson5 said:

Thanks for your reply, I am getting closer

 

3. What is missing is looping the whole operation for multiple sections and exporting the set of data to external file like below

 

sample file structure:

 

25+500 (from text string - chainage)

-5.0;212.22

-3.0;200.50

1.1;205.69

4.6;202.37

 

25+600

-2.0;213.22

-3.0;201.50

5.1;205.69

6.6;202.37

 

 

 It's glad you are getting closer. Your achievement if you got problems sorted yourself :)

 



(open fn "a") ; a=append, w=write

[/Code]

 

My $0.02 if your cross sections are drawn where base point is 100m apart from each other (constant array as long as not overlapped), X is 0.00 then IMO it is possible to solve multiple Y values in single selection set 

Posted

You going down the path I would have gone a little help the datum point is "RL 123.5" I have something else that pulls Rl out for surface levels. I use lee-mac's Parse Numbers so it removes the RL bit.

 

Something else I use is a dcl that has the 3 values hor scale, ver scale, and decimal places preset saves a bit of time.

 


(if (not AH:getval3)(load "getvals3"))
(ah:getval3 "Enter Horizontal scale " 5 4 "100" "Enter Vertical scale" 5 4 "50" "Enter number of decimal places" 5 4 "2")
(setq horiz (atof val1))
(setq vert (atof val2))
(setq prec (atoi val3)

 

 

 

 

 

 

 

 

GETVALS3.lsp

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