johmmeke Posted December 1, 2010 Posted December 1, 2010 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 Quote
HRae Posted December 1, 2010 Author Posted December 1, 2010 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 Quote
HRae Posted December 1, 2010 Author Posted December 1, 2010 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 Quote
Lee Mac Posted December 1, 2010 Posted December 1, 2010 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 Quote
Lee Mac Posted December 1, 2010 Posted December 1, 2010 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 Quote
johmmeke Posted December 1, 2010 Posted December 1, 2010 Lee that is quick.... i'm give it a try i a few hours when i get home ... Thx for coding John Quote
Lee Mac Posted December 1, 2010 Posted December 1, 2010 You're welcome John, I simplified the code quite a lot using a different algorithm Quote
johmmeke Posted December 1, 2010 Posted December 1, 2010 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 Quote
Lee Mac Posted December 1, 2010 Posted December 1, 2010 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 Quote
HRae Posted December 1, 2010 Author Posted December 1, 2010 Hi Lee, Thanks for the updated lisp. 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 Quote
Lee Mac Posted December 1, 2010 Posted December 1, 2010 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... Quote
HRae Posted December 2, 2010 Author Posted December 2, 2010 Lee I didn't modify the xls file at first but then changed as per notes in lisp. Attached is the acad, xls and csv files that I'm using to test. 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. Heather 4431-31-011.zip 4431-31 DWG REGISTER.zip Quote
johmmeke Posted December 2, 2010 Posted December 2, 2010 Lee, is it possible that i don't have a acaddoc.lsp ? John Quote
Lee Mac Posted December 2, 2010 Posted December 2, 2010 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. Quote
Lee Mac Posted December 2, 2010 Posted December 2, 2010 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. Quote
johmmeke Posted December 2, 2010 Posted December 2, 2010 Lee, have found a caddoc create lisp.. you never gues where thx again John Quote
Lee Mac Posted December 2, 2010 Posted December 2, 2010 Yeah, you could use that - or, there is the tutorial I linked you to earlier :wink: Quote
johmmeke Posted December 2, 2010 Posted December 2, 2010 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. Quote
Lee Mac Posted December 2, 2010 Posted December 2, 2010 Thanks John Certainly the code is free for you to modify, but I would ask that you mark the parts you have modified Quote
CADkitt Posted December 3, 2010 Posted December 3, 2010 (edited) Cool script, I am trying to scrap like half of it 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 (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 December 3, 2010 by CADkitt Quote
Recommended Posts
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.