Importing survey data via csv to write multi attribute blocks into the correct layer for the rest of my LISPS to call on

Importing survey data via csv to write multi attribute blocks into the correct layer for the rest of my LISPS to call on

orourkestuart
Contributor Contributor
5,671 Views
33 Replies
Message 1 of 34

Importing survey data via csv to write multi attribute blocks into the correct layer for the rest of my LISPS to call on

orourkestuart
Contributor
Contributor

Hi all, quick recap of where I'm at:

I've got a full suite of LISP routines for several different automated annotation and calculation tools which worked beautifully until I moved employer. Previously I have been dealing with Trimble survey data exchanged as dxf's and the data in that format gave me "DIAG_CROSS" blocks with the point attributes written into the block. Having moved companies I now find myself dealing with Leica and LisCAD and the only reliable way I have of extracting point data with an extensive attribute from the survey kit set is via csv.

What I need is a LISP to read in a csv and create a "DIAG_CROSS" block at each of the coordinates and generate 8 block attributes that match the points attribute tables, the last column in the csv contains the target layer designation for the block.

Attached are a sample dxf in the format I used to deal with, and a csv (saved as a txt since I can't attach a csv) of invented points in the format I'll be using, the headers in the csv are what I need the block attributes to be called in the block, which I can then call on with the rest of my LISP suite. Across the whole set of survey points the number of attributes will always be the same and be called the same.

The format of the csv is:

 

PtNo.,x,y,z,CODE,DEPTH,SIZE,MATERIAL,COMMONNOTES,END,NUMBEROF,METHOD,NOTES,LAYER,

 

and the attributes I need to be named and attached to the blocks are:

 

PtNo.,CODE,DEPTH,SIZE,MATERIAL,COMMONNOTES,END,NUMBEROF,METHOD,NOTES. I don't need the elevation as displayed in the dwg.

 

I've set the last value as a fixed value in the survey controller for each code, so the LISP can call on it to set the layer for the block insertion.

Thanks in advance

0 Likes
Accepted solutions (1)
5,672 Views
33 Replies
Replies (33)
Message 21 of 34

Anonymous
Not applicable

Thanks for this great lisp! It works for me perfectly, but I would also like the elevations (Z value) to be displayed in a block. Please can you adjust the lisp ?! Thanks in advance!

0 Likes
Message 22 of 34

hak_vz
Advisor
Advisor

@Anonymous 

To retain Z replace this line in @pbejse 's code

 

(setq itm (cons (Car itm) (cddddr itm)))

 

with

 

(setq itm (cons (Car itm) (cdddr itm)))

 

 

If you want x y z in your block  then just put a comment sign ; in front that line

 

;(setq itm (cons (Car itm) (cddddr itm)))

 

I think it should work

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 23 of 34

pbejse
Mentor
Mentor

@hak_vz wrote:

@Anonymous 

To retain Z replace this line in @pbejse 's code

 


Do not forget the listOfTags, it should match the data rows

(setq listOfTags (mapcar 'strcase (cons (Car NameAndTag) (cddddr NameAndTag))))
(setq itm (cons (Car itm) (cddddr itm)))

To

(cdddr NameAndTag)
(cdddr itm)

Of course you need a tag name for the Z column on your block to match.

 

HTH

0 Likes
Message 24 of 34

Anonymous
Not applicable

It works perfectly,
Thanks a lot!

0 Likes
Message 25 of 34

hak_vz
Advisor
Advisor

@pbejse 

 Here I created two functions that would add or remove attributes from already existing block.

(defun removeBlockAttributes (blockname)
(setq acad (vlax-get-acad-object) doc (vla-get-activedocument acad))
 (cond
	((tblsearch "BLOCK" blockname)
		(setq blk (vla-item (vla-get-blocks doc) blockname))
		(vlax-for item blk
			(if (= (vlax-get item 'ObjectName) "AcDbAttributeDefinition")(vla-delete item))
		)
	)
	(T (princ (strcat "\nBlock with name " blockname " don't exist in this drawing >")))
 )
(princ)
)



(defun addBlockAttributes (blockname  attlist)
(setq acad (vlax-get-acad-object) doc (vla-get-activedocument acad))
(setvar 'attdia 0)
 (cond
	((tblsearch "BLOCK" blockname)
		(setq blk (vla-item (vla-get-blocks doc) blockname))
			(vlax-for att attlist
				(vla-addattribute
				   blk
				   (getvar 'textsize)
				   acattributemodelockposition
				   acAttributeModeInvisible
				   att
				   (vlax-3D-point 0 0)
				   att
				   " "
			   )
			)	
	)
	(T (princ (strcat "\nBlock with name " blockname " don't exist in this drawing >")))
 )
 (setvar 'attdia 1)
(princ)
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 26 of 34

pbejse
Mentor
Mentor

@hak_vz wrote:

@pbejse 

 Here I created two functions that would add or remove attributes from already existing block.

(defun removeBlockAttributes (blockname)...
(princ)
)
(defun addBlockAttributes (blockname  attlist)...
(princ)
)

 

There you go, thats a start, 

Question: It appears that you are assigning attributes to a block definition  and not to individual block reference correct?  So how does it work with assigning different tags based on a given data from CSV? 

 

Curious about this bit here:

(blockname  attlist)...
..  (vlax-for att attlist ... 

What type of collection is attlist ?

 

 

0 Likes
Message 27 of 34

hak_vz
Advisor
Advisor

@pbejse  attlist is defined as '(("A". 1)("B". 2)("C". 3)("D". 4))  or simply '(("A")("B")("C")("D")) 

 

I have created functions with temporary DCL dialog that collects all blocks inside drawing (omits xrefs and layouts). User can wipe out all attributes from existing blocks and assign new one at the moments he imports new data (from first line in CSV).

Didn't have time to finish it, but will post it through the weekend.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 28 of 34

orourkestuart
Contributor
Contributor

Hey guys the LISP works excellently, however.....Randomly the csv that's sent out of the controller uses Pt instead of PT, so when I run the DIAGCROSS command I get an automation key error, changing the text in the first column to PT resolves the issue, but that's going to be painful 2k jobs down the line, I'm not even sure why it would be a problem tbh, I wasn't aware LISP recognised UC/LC unless it was concatenating.

0 Likes
Message 29 of 34

hak_vz
Advisor
Advisor

@orourkestuart

Lisp code that is checked as a solution (#14) would have to deal with this problem correctly. Changes are marked in blue.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 30 of 34

pbejse
Mentor
Mentor

@orourkestuart wrote:

....Randomly the csv that's sent out of the controller uses Pt instead of PT.. 

I'm not even sure why it would be a problem tbh..

...


 

Depends on what code are you referring to @orourkestuart. as @hak_vz  already stated.

Same here, IF  you are using the code at post # 14, then Pt and PT does not matter at all.

 

 

0 Likes
Message 31 of 34

orourkestuart
Contributor
Contributor

some random zeitgeist.....I'm not sure what the deal is with "CSV"   "DOS CSV" etc etc in excel. I ended up having similar issues with some of my other LISPS and as long as I save as a "DOS CSV" in excel it goes away, it's something to do with how 'line return' is written in the different formats.

 

Thanks heaps anyway 🙂

0 Likes
Message 32 of 34

pbejse
Mentor
Mentor

@orourkestuart wrote:

I save as a "DOS CSV" in excel it goes away, 


Good for you, glad you found the ghost. 🙂

 

Is it having issues when you save as CSV (Comma delimited) (*.csv) ? I personally never used "DOS CSV". Dont worry about it now,  just curious is all.

 

 

 

0 Likes
Message 33 of 34

orourkestuart
Contributor
Contributor

in excel - "CSV UTF8"  and "CSV" options from the 'save as type' list both give me an upside down question mark and a " at the front of the command entry, which obviously throws a spanner in the works when your LISP running command line entries. The command line gave me an error that contained the random symbols followed by the co-ordinates for insertion, so I knew the LISP was running but sticking the random symbols in front, which I eventually deduced was because the csv format was introducing a non-recognised form of line return at the end of the header line. So all I have to do is open the .csv that's exported from the controller and save it as "CSV (MS DOS)". I've encountered similar problems with 12d in the past.

0 Likes
Message 34 of 34

pbejse
Mentor
Mentor

@orourkestuart wrote:

in excel - "CSV UTF8"  and "CSV" options from the 'save as type' list both give me an upside down question mark and a " at the front of the command entry, 


 

Interesting, would like to see one though, one can always deal with stuff like that with proper coding.

Not that important now, you obviously found a good workaround that works for you.

 

 

0 Likes