Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Import Pt X Y Z Code Desc

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
3638 Views, 9 Replies

Import Pt X Y Z Code Desc

Hey guys, I was wondering if there was a way (lsp/dcl) to import a csv which contains the following columns:

PtID X Y Z Code

or 

PtID X Y Z Code Des

 

9 REPLIES 9
Message 2 of 10
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hey guys, I was wondering if there was a way (lsp/dcl) to import a csv which contains the following columns:

PtID X Y Z Code

or 

PtID X Y Z Code Des

 


Import into what? a block with attribute? or a TEXT/MTEXT entity?

Message 3 of 10
Anonymous
in reply to: pbejse

Is it possible to import the csv into autocad as nodes? I would like the data from the csv PtID and code retained within the node.

Message 4 of 10
pbejse
in reply to: Anonymous


@Anonymous wrote:

Is it possible to import the csv into autocad as nodes? I would like the data from the csv PtID and code retained within the node.


Nodes as in POINT entitiy? So basically a BLOCK with a POINT entity and Attributes [invisible or otherwise] for the data [PtID and code] correct? 

Show us a sample of the CSV data. and also how it will look like in cad

 

 

Message 5 of 10
Anonymous
in reply to: pbejse

Yes a point entity. I could live if the last column (Description) wasnt included. I just need to be able to import surveyed points from a csv file and retain the point ID and code in order to make snense of the data.  I need to be able to inquire the points and see the point number and code when i use the ID command. Please see atached image for reference to the csv format.

Message 6 of 10
pbejse
in reply to: Anonymous


@Anonymous wrote:

Yes a point entity. I could live if the last column (Description) wasnt included. I just need to be able to import surveyed points from a csv file and retain the point ID and code in order to make snense of the data.  I need to be able to inquire the points and see the point number and code when i use the ID command. Please see atached image for reference to the csv format.


Ok. now to "retain" the point ID you need a placeholder for that data correct? do you prefer attributes or plain text? But like i said. post a sample drawing of the desired result [Drawing file please and NOT PNG]

 

 

Message 7 of 10
Anonymous
in reply to: pbejse

Is it possible to retain the Pt Id and code? I have imported a csv into a third party cad program and then exported top dxf. The attached .dwg is the result. 

Message 8 of 10
pbejse
in reply to: Anonymous


@Anonymous wrote:

Is it possible to retain the Pt Id and code? I have imported a csv into a third party cad program and then exported top dxf. The attached .dwg is the result. 


Why of course, theres a couple of ways to do that. invisible attributes or XDATA, for now we will stick with invisible attributes.. hang on i will write a quick one for you. [one with just placing the points and no ID ]....

 

EDIT: I'm not sure if the CAD software you are using can recognize attributes. Can you verify this? 

 

This one use point entity [no attributes]

 

(defun c:rcsv (/ _delFinder ss e a data b attrvalues)
;;;	pBe 21July2014	;;; 
  (defun _delFinder (str md / d l str)
    (while (setq d (vl-string-position md str nil T))
      (setq l	(cons (substr str (+ 2 d)) l)
	    str	(substr str 1 d)
      )
    )
    (cons str l)
  )
(if (setq data nil
	  file (getfiled "Select CSV file" (getvar 'dwgprefix) "CSV" 16))
  	(progn
		(setq of (open file "r"))
		(while (setq a (read-line of))
		  (setq data (cons (_delFinder a 44) data))
		)
		(close of)
	  	
		(foreach itm (cdr (reverse data))
		  (entmakex
		    (list
		      (cons 0 "POINT")
		      (cons 10
			    (mapcar 'distof (list (cadr itm) (caddr itm) (cadddr itm)))
		      )
		  (cons 8 (nth 4 itm))
		    )
		)
		  )
	  )
  )
  (princ)
  )

 

 

Message 9 of 10
pbejse
in reply to: pbejse

And this using a block with attributes [invisible attributes]

 

(defun c:rcsv (/ _delFinder ss file of a data atblk)
;;;	pBe 21July2014	;;; 
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))  
  (defun _delFinder (str md / d l str)
    (while (setq d (vl-string-position md str nil T))
      (setq l	(cons (substr str (+ 2 d)) l)
	    str	(substr str 1 d)
      )
    )
    (cons str l)
  )
(if (and
      (or (tblsearch "block" (setq bn "CCAD_POINT"))
	  (setq bn (findfile "CCAD_POINT.dwg"))
      )
      (setq data nil
	    file (getfiled "Select CSV file" (getvar 'dwgprefix) "CSV" 16)
      )
    )
  	(progn
		(setq of (open file "r"))
		(while (setq a (read-line of))
		  (setq data (cons (_delFinder a 44) data))
		)
		(close of)
	  	
		(foreach itm (cdr (reverse data))
		  	(setq atblk (vlax-invoke  (vlax-get
                            (vla-get-ActiveLayout adoc)
                                              'Block)
                                        'InsertBlock
                                        (mapcar 'distof (list (cadr itm) (caddr itm) (cadddr itm)))
                                        bn 
                                        1 1 1 0)
			      )
		  	(mapcar '(lambda (av va)
				   (vla-put-textstring  va av))
					(list (car itm) (nth 4 itm)) (vlax-invoke atblk 'Getattributes))
		)
	  )
  (princ
    (cond ((null bn) "\n<<Block \"CCAD_POINT\" Not Found>>")
	  ((null file) "\n<<Point file Not Found>>")
	  ))
  )

  
  (princ)
  )(vl-load-com)

 HTH

 

 

Message 10 of 10
Anonymous
in reply to: pbejse

An old post but a relevant one for me, I have run the script with blocks however no block have been inserted that I can see.  Any suggestions ?

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

Post to forums  

Autodesk Design & Make Report

”Boost