Community
Civil 3D Forum
Welcome to Autodesk’s Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export sample line/profile surface coordinates to csv

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
NV96
1937 Views, 7 Replies

Export sample line/profile surface coordinates to csv

Hello,

 

I have a model with multiple surfaces underneath it. I'm looking for a way to export the surface name, X, Y, Z every x meter along a polyline or sample line from all the surfaces into a CSV file.

 

Someone has any idea how to do this?

7 REPLIES 7
Message 2 of 8
tcorey
in reply to: NV96

AutoLISP!

 

Tell me more about this polyline. Is it an LW Polyline? Would you prefer to use a polyline or a sample line? Are these two-point objects?



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 3 of 8
tcorey
in reply to: NV96

This code will do what you ask, using a sample line. This is rough code, no error checking, like for when a point on the sample line is outside the surface being checked. Either be sure the points on the sample line are inside all surfaces.

 

The routine creates a new file name in the drawing folder, using the drawing name plus REPORT.TXT. For example, if your drawing is called Design03, the report file will be Design03REPORT.TXT.

 

Thanks to @JeffM for the code that captures the aeccappno from the registry. 

 

;this routine asks for a Sample Line. Captures surface name and xyz every n units and writes the data to a text file
;does this for every surface in the drawing.

(defun c:go ( / flnam fl incr plobj vtxs p1 p2 p1xy p2xy myangle maxdist surfcoll surfctr ctr surf surfname
	     p3 p3x p3y ptz infoline c3dproduct c3drelease c3dnumber appno acadapp c3dapp c3ddoc)

 ;create file
  (setq	flnam (strcat (getvar "dwgprefix")
		      (substr (getvar "DWGNAME")
			      1
			      (- (strlen (getvar "DWGNAME")) 4)
		      )
		      "REPORT.TXT"
	      )
  )
  (setq fl (open flnam "w"))  ;open file for write

  
  (setq incr (getreal "\nEnter distance between points: "))

  (vl-load-com)
  (getdoc)
  (setq plobj (vlax-ename->vla-object (car (entsel "\nSample Line: "))))
  (while (not (= (vlax-get-property plobj 'ObjectName) "AeccDbSampleLine"))
    (prompt "\nYou must select a Sample Line Object...")
    (setq plobj (vlax-ename->vla-object (car (entsel "\nTry again...select Sample Line: "))))
    );end while
  (setq vtxs (vlax-get plobj 'Vertices))
  (setq p1 (vlax-invoke vtxs 'Item 0)
	p2 (vlax-invoke vtxs 'Item 1)
	p1xy (list (car (vlax-get p1 'Location)) (cadr (vlax-get p1 'Location)))
	p2xy (list (car (vlax-get p2 'Location)) (cadr (vlax-get p2 'Location)))
	)
  (setq myangle (angle p1xy p2xy))
  (setq maxdist (distance p1xy p2xy))
  
    
  (setq surfcoll (vlax-get c3ddoc 'Surfaces)
	surfctr (vlax-get surfcoll 'Count)
	ctr 0)

  (while (< ctr surfctr)
    (setq surf (vlax-get-property surfcoll 'Item ctr)
	  surfname (vlax-get surf 'Name))
    (setq p3 p1xy)
    (while (<= (distance p1xy p3) (distance p1xy p2xy))
      (setq p3x (car p3)
	    p3y (cadr p3)
	    ptz (vlax-invoke-method surf 'FindElevationAtXY p3x p3y)
	    )
(setq
  infoline (strcat surfname
		   ","
		   (rtos (car p3) 2 3)
		   ","
		   (rtos (cadr p3) 2 3)
		   ","
		   (rtos ptz 2 3)
		   
	   )

)
      (write-line infoline fl)
      (setq p3 (polar p1xy myangle (+ (distance p1xy p3) incr)))
      );end while
    (setq ctr (1+ ctr))
  );end while
(close fl)
  (princ)

  );end defun

(defun getAecAppNumber (/ );c3dnumber c3dproduct c3drelease)
  (setq	C3Dproduct (strcat "HKEY_LOCAL_MACHINE\\"
			   (if vlax-user-product-key
			     (vlax-user-product-key)
			     (vlax-product-key)
			   )
		   )
	C3Drelease (vl-registry-read C3Dproduct "Release")
	C3Dnumber  (substr
		     C3Drelease
		     1
		     (vl-string-search
		       "."
		       C3Drelease
		       (+ (vl-string-search "." C3Drelease) 1)
		     )
		   )
  )
)

(defun getdoc ( / )
(setq appno (getaecappnumber))
(setq	acadapp	(vlax-get-acad-object)
	c3dapp	(vla-getinterfaceobject acadapp (strcat "AeccXUiLand.AeccApplication." appno))
	C3Ddoc	(vla-get-activedocument C3Dapp)
  )

)					;end function


Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 4 of 8
NV96
in reply to: tcorey

Thanks this code was what I needed. Thank you!

Message 5 of 8
Hammer.john.j
in reply to: tcorey

would be even more useful, if there was something that takes the station, offset, and elevation from a cross section label and exports out to a pnezd file such that the exported point takes the smart data from the graph to correlate cross section background info to import as cogo points in plan view.

 

i.e. cross section sta/offset/elev output to pnezd csv comma format to import as cogo points in plan view.

John Hammer, LA/CADD Manager
Message 6 of 8
rahmanpriadi
in reply to: tcorey

How to make this Autolisp?

help me please


@tcorey wrote:

This code will do what you ask, using a sample line. This is rough code, no error checking, like for when a point on the sample line is outside the surface being checked. Either be sure the points on the sample line are inside all surfaces.

 

The routine creates a new file name in the drawing folder, using the drawing name plus REPORT.TXT. For example, if your drawing is called Design03, the report file will be Design03REPORT.TXT.

 

Thanks to @JeffM for the code that captures the aeccappno from the registry. 

 

;this routine asks for a Sample Line. Captures surface name and xyz every n units and writes the data to a text file
;does this for every surface in the drawing.

(defun c:go ( / flnam fl incr plobj vtxs p1 p2 p1xy p2xy myangle maxdist surfcoll surfctr ctr surf surfname
	     p3 p3x p3y ptz infoline c3dproduct c3drelease c3dnumber appno acadapp c3dapp c3ddoc)

 ;create file
  (setq	flnam (strcat (getvar "dwgprefix")
		      (substr (getvar "DWGNAME")
			      1
			      (- (strlen (getvar "DWGNAME")) 4)
		      )
		      "REPORT.TXT"
	      )
  )
  (setq fl (open flnam "w"))  ;open file for write

  
  (setq incr (getreal "\nEnter distance between points: "))

  (vl-load-com)
  (getdoc)
  (setq plobj (vlax-ename->vla-object (car (entsel "\nSample Line: "))))
  (while (not (= (vlax-get-property plobj 'ObjectName) "AeccDbSampleLine"))
    (prompt "\nYou must select a Sample Line Object...")
    (setq plobj (vlax-ename->vla-object (car (entsel "\nTry again...select Sample Line: "))))
    );end while
  (setq vtxs (vlax-get plobj 'Vertices))
  (setq p1 (vlax-invoke vtxs 'Item 0)
	p2 (vlax-invoke vtxs 'Item 1)
	p1xy (list (car (vlax-get p1 'Location)) (cadr (vlax-get p1 'Location)))
	p2xy (list (car (vlax-get p2 'Location)) (cadr (vlax-get p2 'Location)))
	)
  (setq myangle (angle p1xy p2xy))
  (setq maxdist (distance p1xy p2xy))
  
    
  (setq surfcoll (vlax-get c3ddoc 'Surfaces)
	surfctr (vlax-get surfcoll 'Count)
	ctr 0)

  (while (< ctr surfctr)
    (setq surf (vlax-get-property surfcoll 'Item ctr)
	  surfname (vlax-get surf 'Name))
    (setq p3 p1xy)
    (while (<= (distance p1xy p3) (distance p1xy p2xy))
      (setq p3x (car p3)
	    p3y (cadr p3)
	    ptz (vlax-invoke-method surf 'FindElevationAtXY p3x p3y)
	    )
(setq
  infoline (strcat surfname
		   ","
		   (rtos (car p3) 2 3)
		   ","
		   (rtos (cadr p3) 2 3)
		   ","
		   (rtos ptz 2 3)
		   
	   )

)
      (write-line infoline fl)
      (setq p3 (polar p1xy myangle (+ (distance p1xy p3) incr)))
      );end while
    (setq ctr (1+ ctr))
  );end while
(close fl)
  (princ)

  );end defun

(defun getAecAppNumber (/ );c3dnumber c3dproduct c3drelease)
  (setq	C3Dproduct (strcat "HKEY_LOCAL_MACHINE\\"
			   (if vlax-user-product-key
			     (vlax-user-product-key)
			     (vlax-product-key)
			   )
		   )
	C3Drelease (vl-registry-read C3Dproduct "Release")
	C3Dnumber  (substr
		     C3Drelease
		     1
		     (vl-string-search
		       "."
		       C3Drelease
		       (+ (vl-string-search "." C3Drelease) 1)
		     )
		   )
  )
)

(defun getdoc ( / )
(setq appno (getaecappnumber))
(setq	acadapp	(vlax-get-acad-object)
	c3dapp	(vla-getinterfaceobject acadapp (strcat "AeccXUiLand.AeccApplication." appno))
	C3Ddoc	(vla-get-activedocument C3Dapp)
  )

)					;end function

 

Message 7 of 8
tcorey
in reply to: rahmanpriadi

Copy the text from the code I posted, paste to a Notepad file, Saveas anything.lsp.

 

Inside AutoCAD, use APPLOAD command to load the LISP file. After loading, at the command prompt, type GO to run the program.



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 8 of 8
fikatlove
in reply to: tcorey

Can u help me,how can i use this to export civil 3d 2018 sample line xyz?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report