Jump to content

Lisp routine use csv to update title block attributes - on ctab


HRae

Recommended Posts

Heather, another question about your XLS file, i just have to make the colum header match my att-tag are read the program it in other way?

 

 

Greetz John

Link to comment
Share on other sites

  • Replies 116
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    31

  • HRae

    26

  • SteveK

    17

  • johmmeke

    15

Top Posters In This Topic

Posted Images

Lee

 

The thing about the simplicity of the system is that you can add any block attributed text to the spreadsheet and have it updated.

 

I resently had to get a complete set of drawings issued for Work as Executed, this required a block to be inserted to each drawing and filled out. I have since added this to the title block on a layer, have the information updated in the xls spreadsheet and hey presto all the WAE information is added. The only down side is I now need to find a script to turn on a particualar layer without having to open each drawing (any links to existing scripts that do this?)

 

Heather

Link to comment
Share on other sites

John - yes if you see in the xls file the column headers look like DWG_TITLE1 and R1 etc the R series is all the different revision numbers. oops I posted the title block but forgot the attached that is the text block.

 

BGP_A1A.dwg

 

Heather

Link to comment
Share on other sites

The only down side is I now need to find a script to turn on a particualar layer without having to open each drawing (any links to existing scripts that do this?)

 

Firstly, this will help :)

 

Then, either this will help write the Script, or you could use ScriptPro or similar.

 

I would recommend just using the Script to open/save/close the drawings, and call a LISP from the script to turn the layer on.

 

This LISP will turn a layer on:

 

(defun LayerOn ( layer )

 (if (setq layer
       (LM:Itemp
         (vla-get-Layers
           (vla-get-ActiveDocument
             (vlax-get-acad-object)
           )
         )
         layer
       )
     )
   (vla-put-layeron layer :vlax-true)
 )
 (princ)
)

;;-----------------------=={ Itemp }==------------------------;;
;;                                                            ;;
;;  Retrieves the item with index 'item' if present in the    ;;
;;  specified collection, else nil                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  coll - the VLA Collection Object                          ;;
;;  item - the index of the item to be retrieved              ;;
;;------------------------------------------------------------;;
;;  Returns:  the VLA Object at the specified index, else nil ;;
;;------------------------------------------------------------;;

(defun LM:Itemp ( coll item )
 ;; © Lee Mac 2010
 (if
   (not
     (vl-catch-all-error-p
       (setq item
         (vl-catch-all-apply
           (function vla-item) (list coll item)
         )
       )
     )
   )
   item
 )
)

Call like this:

 

(LayerOn "YourLayerHere")

You could also use ObjectDBX using this program, coupled with this function:

 

(defun LayerOn ( doc )

 (setq layer "YourLayerHere")

 (if (setq layer (LM:Itemp (vla-get-Layers doc) layer))
   (vla-put-layeron layer :vlax-true)
 )
 (princ)
)

;;-----------------------=={ Itemp }==------------------------;;
;;                                                            ;;
;;  Retrieves the item with index 'item' if present in the    ;;
;;  specified collection, else nil                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  coll - the VLA Collection Object                          ;;
;;  item - the index of the item to be retrieved              ;;
;;------------------------------------------------------------;;
;;  Returns:  the VLA Object at the specified index, else nil ;;
;;------------------------------------------------------------;;

(defun LM:Itemp ( coll item )
 ;; © Lee Mac 2010
 (if
   (not
     (vl-catch-all-error-p
       (setq item
         (vl-catch-all-apply
           (function vla-item) (list coll item)
         )
       )
     )
   )
   item
 )
)

i.e.

 

(LM:ODBX 'LayerOn nil t)

Lee

Link to comment
Share on other sites

Hi Guys,

 

Had a quick look at the code today, please try the attached.

 

The code is fully described in the header, including the expected format of the DWG Register CSV file. The Text file containing the location of the DWG Register is expected to be found in the same directory as the working drawing.

 

Please let me know how you get on,

 

Lee

update.lsp

Link to comment
Share on other sites

Lee, have done soms quick test (i just whas to exiting not to)

works great for my need ;)

 

do a better testing when i got home, also have to find out just how to ad it to acaddoc.lsp

 

this is a real helper for me

 

thx Lee for just another great Lisp

Link to comment
Share on other sites

Lee, have done soms quick test (i just whas to exiting not to)

works great for my need ;)

 

Excellent to hear John, I'm really glad it works for you :)

 

...also have to find out just how to ad it to acaddoc.lsp

 

With regards to adding it to the ACADDOC.lsp, as it stands you could either add a load call to the ACADDOC.lsp, something like:

 

(load "update.lsp" "Update.lsp Failed to Load")

Or

 

(load "C:\\My Folder\\update.lsp" "Update.lsp Failed to Load")

Should the LISP not reside in an AutoCAD Support Path.

 

Or you could even just copy the whole code into the ACADDOC.lsp (but this is less maintainable).

 

This and maybe this may also help.

 

Lee

Link to comment
Share on other sites

Hi Lee,

 

Thanks for the updated lisp. :D

 

I have tested the lisp on a drawing that has 5 layouts (simulating 5 seperate drawings). The routine updates all title blocks located within each of the layouts. The downside is that it updates the blocks with exactly the same information. For example from the xls file drawing 011 will have title block 'Construction Details Sheet 1 of 5'. Then the second layout (ctab) represents drawing 012 (Sheet 2 of 5). The routine then puts the same information into the title block, in essense repeating the 011 information.

 

So we have it working on the same blocks within a drawing, but it hasn't distinguished that the additional blocks on the different layouts in fact represent a different drawing and hence the next line in the xls (csv) file.

 

I'm slowly converting the 'old hands' to use one drawing file to represent one sheet. Although if we can get the routine to work with layouts then the lisp will (should) work with any type of drawing setup.....maybe! :)

 

Regards

Heather

Link to comment
Share on other sites

Hmmm...

 

In my opinion, that part of the system seems a bit flawed (ambiguous), as the drawing filenames don't correlate with the Drawing Register, and furthermore, when updating the blocks, the order of layouts/entries in the drawing register would add extra risk of error - what if the layouts are reordered? Then the drawing register needs to be reordered...

Link to comment
Share on other sites

Lee, is it possible that i don't have a acaddoc.lsp ?

 

John

 

Yes, very possible - just create one and save it in an AutoCAD Support path, AutoCAD will load the first ACADDOC.lsp it finds.

Link to comment
Share on other sites

The issue may be with the way the xls file is set up and the creation of the csv file that is causing the problem.

 

No, my code just looks for the appearance of the name of the dwg file in the CSV drawing register, then uses that row to populate the attributed blocks.

Link to comment
Share on other sites

very nice site ..

clean and usefull

 

can i take the first part of this lisp to make another lisp, that auto create dwg's with the name in the first colum starting from a dwt?

i'm just to new to this.

Link to comment
Share on other sites

Cool script, I am trying to scrap like half of it :P

Since i want to use one database file and not one per directory.

But I had the most problem till now that is DON'T ADD .DWG in the csv filenames.

Here is my modified code so it works with one CVS/txt file Removed the top description because I edited just made some modifications.

This code isn't clean but works :P


(defun c:Update2 ( / *error* _FixDir _CloseFile AS CSV CSVFILE CSVPATH DOC DWG LST NL SS TAGS )
 (vl-load-com)
(setq csv "C:\\Engineering\\Dwglistcsv.txt")
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (mapcar '_CloseFile (list csvfile csv))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _FixDir ( d )
   (if (not (eq "\\" (substr d (strlen d)))) (strcat d "\\") d)
   )

 (defun _CloseFile ( f )
   (if (and f (eq 'FILE (type f))) (close f))
   )

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
 
 
     (setq dwg (strcase (vl-filename-base (getvar 'DWGNAME))) csv (open csv "r"))
(princ dwg)
     (if
       (and (setq tags (LM:str->lst (strcase (read-line csv)) ","))
         (progn
           (while
             (and (setq nl (read-line csv))
               (not (wcmatch (strcase nl) (strcat dwg "`,*")))
             )
           )
           nl
         )
         (setq lst (mapcar 'cons tags (LM:str->lst nl ",")))
         (ssget "_X" '((0 . "INSERT") (66 . 1)))
       )
       (progn
         (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
           (foreach att (vlax-invoke obj 'GetAttributes)
             (if (setq as (assoc (strcase (vla-get-TagString att)) lst))
               (vla-put-TextString att (cdr as))
             )
           )
         )
         (vla-delete ss)
       )
     )

     (_CloseFile csv)    
   (princ)
)

;;-------------------=={ String to List }==-------------------;;
;;                                                            ;;
;;  Separates a string into a list of strings using a         ;;
;;  specified delimiter string                                ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - string to process                                   ;;
;;  del - delimiter by which to separate the string           ;;
;;------------------------------------------------------------;;
;;  Returns:  A list of strings                               ;;
;;------------------------------------------------------------;;

(defun LM:str->lst ( str del / pos )
 ;; © Lee Mac 2010
 (if (setq pos (vl-string-search del str))
   (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
   (list str)
 )
)


;; Remove this to disable program running upon loading:
;(c:update)

;; EOF

Edited by CADkitt
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...