Jump to content

Recommended Posts

Posted

Hey all, this is my first post so I'm sorry if I violate any of the forum rules. I appreciate the help!

 

I'm trying to write a script to get the latest revision number from our drawings, then save that info into a text or CSV file. Each drawing has a revision block like the image tagged below. How would I do that in LISP?

 

Thanks!

 

Screen Shot 2016-05-26 at 12.52.27 PM.jpg

Posted

Welcome to the forum my friend. Thank GOD that we have people like Lee Mac in the community. You do not need to re-invent the wheel because Lee has already done a neat job with this sort of task. Use Global Attribute Extractor & Editor lisp from Lee Mac (with this lisp you can ask to extract certain attribute from bunch of drawings - not necessarily all tags) and it will show the final results in CSV file afterwards.

 

Kudo to Lee Mac

Posted

This is an example of something similar shows how to change a ttribute value based on tag name but you can use GET rather than PUT and write out the value to a csv

 

; changes to issued for construction
: thanks to lee mac for original code
(vl-load-com)
; 1.  Get current date in mm/dd/yy format.
(defun ddmmyy (/ x today)
    (setvar "cmdecho" 0)
    (setq x (getvar "CDATE"))                 ; get current date
    (setq today ( rtos x 2 4))                    ; convert to a string
    (setq date (strcat (substr today 7 2) "."    (substr today 5 2) "." (substr today 3 2) ))
)

(setq oldtag1 "DRAWING_STATUS") ;attribute tag name
(setq newstr1 "ISSUED FOR CONSTRUCTION")
(setq oldtag2 "REV_NO")  ;attribute tag name
(setq newstr2 "0")
(setq ss1 (ssget "x"  '((0 . "INSERT") (2 . "DA1DRTXT"))))
(setq inc (sslength ss1))
(repeat inc      
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq inc (1- inc)) )) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr1) 
) ; end if
(if (= oldtag2 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr2) 
) ; end if
) ; end for
) ;end repeat
(setq oldtag1 "REV-NO")
(setq newstr1 "0")
(ddmmyy)
(setq oldtag2 "DATE")
(setq newstr2 date)
(setq oldtag3 "AMENDMENT")
(setq newstr3 "ISSUED FOR CONSTRUCTION")
(setq ss2 (ssget "x"  '((0 . "INSERT") (2 . "REVTABLE"))))
(setq inc (sslength ss2))
(repeat inc
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname ss2 (setq inc (1- inc)))) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr1) 
)
(if (= oldtag2 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr2) 
)
(if (= oldtag3 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr3) 
)
)
)
(setq ss1 nil)
; (setq ss2 nil)
(princ)

Posted

Thanks bababarghi! I've downloaded and run the script. I can use the editor fine, but the extractor gives me an error when I use it on the block in my original screenshot named revision_text:

 

bad argument type: VLA-OBJECT nil

 

I noticed if I make up a random block name I don't get the error, it just returns nothing. Could something be amiss in that block?

Posted
Thanks bababarghi! I've downloaded and run the script. I can use the editor fine, but the extractor gives me an error when I use it on the block in my original screenshot named revision_text:

 

bad argument type: VLA-OBJECT nil

 

I noticed if I make up a random block name I don't get the error, it just returns nothing. Could something be amiss in that block?

 

Can you perhaps share your block with us?

Posted

Actually, I'm very close to what I need with the DATAEXTRACTION command. It outputs the contents of my revision_text block to a spreadsheet. I just need to add a filename or something so I can correlate each row to it's drawing file. Any idea how to do that?

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