Jump to content

Fill CSV file with block attributes


Manuel_Kunde

Recommended Posts

Hi all, I'm looking for a lisp that will write the custom content from the block attributes of a specific block (in this case named "Test_Block") in a CSV File.

 

In the image below, you can see in red the fields that are the same every time, and in green, the variable values I want to select from the block.

Does anyone have a template or idea how this should work?

 

image.png.cd256b44d07b64361f5794402d9e05a6.png

 

image.png.4d849f6d6b1cab640bf5b2eac416fea2.png

image.png

Edited by Manuel_Kunde
Link to comment
Share on other sites

5 hours ago, Manuel_Kunde said:

Hi all, I'm looking for a lisp that will write the custom content from the block attributes of a specific block (in this case named "Test_Block") in a CSV File.

 

In the image below, you can see in red the fields that are the same every time, and in green, the variable values I want to select from the block.

Does anyone have a template or idea how this should work?

 

image.png.cd256b44d07b64361f5794402d9e05a6.png

 

image.png.4d849f6d6b1cab640bf5b2eac416fea2.png

image.png

 

Hi

Please Attached 

Drawing example

And 

Excel file 

 

  • Like 1
Link to comment
Share on other sites

23 hours ago, hosneyalaa said:

Hi

Please Attached 

Drawing example

And 

Excel file 

 

Hi, DWG test_door_block.dwg and CSV attached.

In the CSV file I have filled the cells in red, which must always be written, and in green the variable numbers, which should be selected from the block.

Do you have any idea how this could be done?


Thanks in advance.

 

image.png.97a16acda7fada8af09cce3a45497d31.png

 

image.png.d15fb39d3565e639d9ba1d56cbc17cb4.png

test_door_block.csv

Link to comment
Share on other sites

They are dynamic blocks in your sample so this matches your sample, it can be changed to work with any dynamic blocks. 

 

Try it 

 

https://www.cadtutor.net/forum/topic/73872-fill-csv-file-with-block-attributes/

;; Get Dynamic Block Property Value  -  Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)

(defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

(defun LM:getdynprops ( blk )
    (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

(defun c:exdynblk ( / ss blk x lst fo str)

(setq ss (ssget (list (cons 0 "INSERT"))))

(if (= ss nil)
(progn (alert "You have not picked blocks ")(exit))
(progn
(setq fo (open "d:\\acadtemp\\dynblks.csv" "W"))
(setq num 0)
(repeat (setq x (sslength ss))
(setq blk (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq lst (LM:getdynprops blk ))
(setq str (strcat
(rtos (setq num (1+ num)) 2 0)
","
(rtos(cdr (nth 0 lst)) 2 2)
","
(rtos (cdr (nth 2 lst)) 2 2)
","
(rtos (cdr (nth 4 lst)) 2 2)
)
)
(princ str)
(write-line str fo)
)
(close fo)
)
)
(princ)
)

(c:exdynblk)

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, BIGAL said:

They are dynamic blocks in your sample so this matches your sample, it can be changed to work with any dynamic blocks.

 

The lisp works very well!
The attributes are all written in one line. How can I tell that an attribute goes in a specific row (e.g. cell B2)?

 

Link to comment
Share on other sites

Just open the csv with Excel it will auto column, if you use the semi-colon for seperator change the "," to ";" different parts of the world use , v's ; inside Excel.

Link to comment
Share on other sites

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