Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

LISP or Pogram to Push Civil 3D Points to excel and back to civil 3D

timothy.mckinney
Participant

LISP or Pogram to Push Civil 3D Points to excel and back to civil 3D

timothy.mckinney
Participant
Participant

Has anyone come across a program or LISP that can take currently selected civil 3D points and copy the point, northing, easting, elevation, and description directly into an excel file (potentially a file that is currently open)? Ideally, I am also looking for the functionality to push PNEZD points from excel directly back into civil 3d.

 

The idea/work flow I have in mind is this: 1) take a selection of points from civil 3d and push into excel, 2) perform calculations on those points in excel including creating new points via calculations 3) push the new set of points back into civil 3d.

 

I am looking to perform calculations on points in excel but be able to see those points quickly in civil 3d to do quality control/see the results.

0 Likes
Reply
Accepted solutions (1)
1,039 Views
10 Replies
Replies (10)

cwr-pae
Mentor
Mentor

You can create point group of selected points, select them in any points window and copy and paste to excel. Getting them back to C3d is another matter, I think this can only be done importing points whether by a lisp or manually.

0 Likes

paul.reichert
Contributor
Contributor

Forefront Design Specialist has Survey Mapper that can automate that and the draw-up with all your layers, linetypes and blocks set up to 31 attributes.  Survey freedom! tool. https://www.forefrontdesignspecialist.com/survey-mapper.html

Or you can purchase that lisp you need.

 

0 Likes

hosneyalaa
Advisor
Advisor

try this

 

(defun c:Civiltocsv (/ pnts i obj pnt eastng northng elev player FEAT FEATUR FILE2OPEN F_OPEN LN LNP LST OLDBLIPMODE OLDLAYER OLDSNAP)
  (vl-load-com)

	(if (setq pnts (ssget '((0 . "AECC_COGO_POINT")))) ;select COGO points
	  (PROGN
	  (repeat (setq i (sslength pnts))
           (setq obj  (vlax-ename->vla-object (ssname pnts (setq i (1- i)))))

           (setq pnt (vlax-get obj 'number)
              eastng (vlax-get obj 'easting)
              northng (vlax-get obj 'northing)
              elev (vlax-get obj 'elevation)
;;;              player (vlax-get obj 'layer)
           ) ;end of setq
	
	        (setq FEAT(LIST pnt eastng northng elev))
	        (setq FEATUR(CONS FEAT FEATUR))	
		
   ) ;end of repeat
          (setq lst(apply 'append FEATUR))

      (setq file2open (vl-filename-mktemp "Civiltocsv" (getvar 'dwgprefix) ".csv"))
      (setq f_open (open file2open "w"))
	(princ "NU" f_open)
        (princ ";" f_open)
        (princ "X" f_open)
        (princ ";" f_open)
	(princ "Y" f_open)
        (princ ";" f_open)
        (princ " Z" f_open)
        (princ ";" f_open)
        (princ "\n" f_open)
	 
      (repeat (/ (length lst) 4)
        (princ (rtos (car lst) 2 3) f_open)
        (princ ";" f_open)
        (princ (rtos (cadr lst) 2 3) f_open)
        (princ ";" f_open)
	(princ (rtos (caddr lst) 2 3) f_open)
        (princ ";" f_open)
        (princ (rtos (cadddr lst) 2 3) f_open)
        (princ ";" f_open)
        (princ "\n" f_open)
	(setq lst (cddddr lst))
      )
      (close f_open)
	 (startapp "explorer" file2open);opin excel
	  
   (princ "No point selected!")
  )) ;end of if
 (princ)
)

 

 

التقاط.PNG

0 Likes

TerryDotson
Mentor
Mentor

Interesting idea that falls in line with a previous request we've had for our C3DTools.  Here is what we have planned.  The tool would have a create option that would take all CogoPoints in the drawing and write them directly out to a XLSx file, the file name being the same as the drawing name.  Then whenever you open a drawing later (or when commanded) if the spreadsheet exists it would read the external file, adjust any points that had changed, remove any that were missing and add any that were added to the spreadsheet.

 

Of course on drawing close (only if any CogoPoints were changed, removed or added) it would need to update the spreadsheet to keep them synchronized.

 

Maybe add a setting for automatic or on prompted approval for the load / change drawing.

0 Likes

hosneyalaa
Advisor
Advisor
Accepted solution
 

(defun c:csvTOCivil (/ C3D C3DDOC D DATA F FILEPATH I LN OCOGO OK POINTS)
  (vl-load-com)
  
  (if (setq FilePath (getfiled "Select TEXT file to read :"
			       (getvar "dwgprefix")
			       "csv"
			       4
		     )
      )
    (progn



      (defun getC3D	()
    (vl-load-com)
    (setq C3D (strcat "HKEY_LOCAL_MACHINE\\"
		      (if vlax-user-product-key
			(vlax-user-product-key)
			(vlax-product-key)
		      )
	      )
	  C3D (vl-registry-read C3D "Release")
	  C3D (substr
		C3D
		1
		(vl-string-search
		  "."
		  C3D
		  (+ (vl-string-search "." C3D) 1)
		)
	      )
	  C3D (vla-getinterfaceobject
		(vlax-get-acad-object)
		(strcat "AeccXUiLand.AeccApplication." C3D)
	      )
    )
    (setq C3Ddoc (vla-get-activedocument C3D))
  )

      (getC3D)
      (setq points (vlax-get C3Ddoc 'points))

      
      (if filepath
	(progn
	  (setq f (open FilePath "r"))
	  (setq ln (read-line f))
	  
	  (while (setq ln (read-line f))
	    (setq data (cons (str2list ln ";") data))
	    )
	  (close f)
	  (setq data (reverse data))
	  
	
	  (setq i -1)
	  
	  (while (< (setq i (1+ i)) (length data))
	    
	    (PROGN
	      (setq d (nth i data)
		    OK NIL)
	      (vlax-for s points
		(if (equal (vlax-get s 'number) (FIX (atof (nth 0 d))))
		  (PROGN
		    (vla-put-elevation s (atof (nth 3 d)))
		    (setq OK 1)
         	    );;   (PROGN
		  ;;   (PROGN
		  );;IF
		);;vlax-for
	      (if (/= OK 1)
		(PROGN
		    (setq oCogo(vlax-invoke points 'add (list (atof (nth 1 d)) (atof (nth 2 d)) (atof (nth 3 d)))))
		    (setq OK NIL)
         	    )
		)

	      
	      );;   (PROGN
	    );;Vwhile
	  );   (PROGN
	);;IF
      );(PROGN
    );;IF
  ); ; ;;;; defun  ;;;;  

;;;str2list by John Uhden, as posted to the adesk customization newsgroup a long time ago
(defun Str2List	(str pat / i j n lst)
  (cond
    ((/= (type str) (type pat) 'STR))
    ((= str pat) '(""))
    (T
     (setq i 0
	   n (strlen pat)
     )
     (while (setq j (vl-string-search pat str i))
       (setq lst (cons (substr str (1+ i) (- j i)) lst)
	     i	 (+ j n)
       )
     )
     (reverse (cons (substr str (1+ i)) lst))
    )
  )
)

 

012.gif

0 Likes

timothy.mckinney
Participant
Participant

@paul.reichertThank you for the recommendation, I will take a look at this.

0 Likes

timothy.mckinney
Participant
Participant

@hosneyalaaThis is great. I am working with this now and may just make a couple tweeks to get this going. Really appreciate the help.

timothy.mckinney
Participant
Participant

@TerryDotsonthis good to hear, excited to see what the final tool looks like!

0 Likes

Sea-Haven
Mentor
Mentor

Whilst reading / writing csv is one way why not just go direct, something like Getexcel.lsp has all the code required.

 

I did do recently a macro in excel that will read a csv, ok so you say so ! But it has a keyword detect so will make new sheets so you could write a csv using description wildcards  each going to a different sheet.

 

Just ask its over at Lisp section.

0 Likes

hosneyalaa
Advisor
Advisor

Hi @Sea-Haven 
Thank you for the clarification
But posting the code is simple

0 Likes