Lee Mac Posted April 6, 2010 Author Posted April 6, 2010 I have updated the code in the first post to Version 2.8, in this version the user can choose to extract the block coordinates. Lee Quote
Lady Hawk Posted April 7, 2010 Posted April 7, 2010 Pulled V2.8 of this fantastic program, it works great! I would like to modify it a bit to suit my own needs but I've never really worked with VBA,. I really just need the editor (if you happen to have it as a stand alone), and I would like add in my own LISP that updates the titleblock (mainly a basic Block=Block redefine with some clean up functions) but I have no idea where to plug it in. Quote
Lee Mac Posted April 7, 2010 Author Posted April 7, 2010 Hi Lady Hawk, Firstly I'm glad you like the program I haven't used VBA in this program, but Visual LISP and ObjectDBX - the Extractor and Editor are combined in one subfunction of the program, as they share various functions, and it was easier this way. You will not be able to use your own LISP routines in this program unless they are suited for use with ObjectDBX, i.e. only using Visual LISP methods, (no command calls, not ent* methods, no access to system variables). Lee Quote
Lee Mac Posted April 10, 2010 Author Posted April 10, 2010 It should be attached in the first post - I'm not sure if there are restrictions if you have fewer than 10 posts (hopefully a Mod will correct me), but you should be able to just click on the attached file in the first post to download it. Lee Quote
Lee Mac Posted April 13, 2010 Author Posted April 13, 2010 Thank you Lee Mac for your work.:wink: You're very welcome, I'm glad it helps you out - I enjoyed coding it Quote
MotoGirl Posted April 27, 2010 Posted April 27, 2010 Hello, I'm new to this site, first off your program is awesome, very very helpful. Thank you. but i admit I am curious mainly about the subject of having any it update back to cad, or if that was just impossible. Well, as I said, the format that the extractor uses groups all the block information together for blocks with the same name, hence, when coming to read this information how would the program know which information went where... The drawing numbers for instance would be fixed. All other data in excel would link to cad through these drawing numbers. Quote
Lee Mac Posted April 27, 2010 Author Posted April 27, 2010 Hello, I'm new to this site, first off your program is awesome, very very helpful. Thank you. but i admit I am curious mainly about the subject of having any it update back to cad, or if that was just impossible. The drawing numbers for instance would be fixed. All other data in excel would link to cad through these drawing numbers. Firstly, thanks for your interest in the program - I'm glad you like it True, the drawing numbers would be fixed, but how would the program know which blocks to update... unless the handle was extracted into the Excel sheet also. Lee Quote
MotoGirl Posted April 27, 2010 Posted April 27, 2010 Firstly, thanks for your interest in the program - I'm glad you like it True, the drawing numbers would be fixed, but how would the program know which blocks to update... unless the handle was extracted into the Excel sheet also. Lee So, There could not be a direct sync from the excel file your program creates to back to the dwg sheet it came from then. Just update everything, type thing. forgive me i don't know a ton about this kinda stuff, our issue is that we have sometimes 20 layout pages with 15 att per layout, it would be way easier to edit them in excel then update cad, then going through each layout sheet. I've always pictured a window in cad that allows edits of every att on the drawing file organized by location(layout tab). but that's probably wishful thinking. lol Thanks again, your like my cad hero now lol. Quote
alanjt Posted April 27, 2010 Posted April 27, 2010 Wasn't someone working on an Excel to Titleblock attribute program? Quote
Lee Mac Posted April 27, 2010 Author Posted April 27, 2010 Thanks again, your like my cad hero now lol. Hehe thanks I can see what you are getting at, and believe me I've considered it - the only problem is that when going through the blocks in the drawing, the order that they are encountered is not consistent enough for an accurate 'sync', the way to do it would be to extract the Object handles to Excel (these don't change unless the object is deleted), then, when reading from Excel, update the objects based on the handle that is read. But, this would probably have to be coded as a separate program, a counterpart to the Extractor program, and reading the same format ( not easy when I've provided the option to write in three different formats ) Lee Quote
MotoGirl Posted April 27, 2010 Posted April 27, 2010 Hehe thanks I can see what you are getting at, and believe me I've considered it - the only problem is that when going through the blocks in the drawing, the order that they are encountered is not consistent enough for an accurate 'sync', the way to do it would be to extract the Object handles to Excel (these don't change unless the object is deleted), then, when reading from Excel, update the objects based on the handle that is read. But, this would probably have to be coded as a separate program, a counterpart to the Extractor program, and reading the same format ( not easy when I've provided the option to write in three different formats ) Lee Okay, it just clicked what you meant. damn. i figured you were right, i just wanted to understand. Thanks! Quote
MotoGirl Posted April 27, 2010 Posted April 27, 2010 Wasn't someone working on an Excel to Titleblock attribute program? oh i wish, the time it would save us!!! Quote
alanjt Posted April 27, 2010 Posted April 27, 2010 oh i wish, the time it would save us!!! I saw it floating around, but don't have a clue where it is. Do a little searching. Quote
fixo Posted April 27, 2010 Posted April 27, 2010 I saw it floating around, but don't have a clue where it is. Do a little searching. Try this one don't remember how it worked ; Tested on A2005, A2008; MS Office 2003 (defun C:AXE (/) ;; local defun: ;; read Excel data (defun EXD ( / ExcelApp ExcData FilePath Sht ShtNum UsdRange Wbk) (vl-load-com) (setq FilePath (getfiled "Select Excel file to read attribute values:" (getvar "dwgprefix") "xls" 16 ) ) (setq ShtNum 1); Spreadsheet number, change to suit (setq ExcelApp (vlax-get-or-create-object "Excel.Application")) (vla-put-visible ExcelApp :vlax-true) (setq Wbk (vl-catch-all-apply 'vla-open (list (vlax-get-property ExcelApp "WorkBooks") FilePath))) (setq Sht (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property Wbk "Sheets") "Item" ShtNum))) (vlax-invoke-method Sht "Activate") (setq Sht (vlax-get-property ExcelApp "ActiveSheet")) (setq UsdRange1 (vlax-get-property Sht "Range" "A1:D1");<-- first row with headers (tags), change to suit UsdRange2 (vlax-get-property Sht "Range" "A3:D3");<-- second row with attribute values, change to suit UsdRange (vlax-invoke ExcelApp "Union" UsdRange1 UsdRange2 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil ) ) (vlax-for Row (vlax-get-property UsdRange 'Areas) (setq ExcData (cons (car (vlax-safearray->list (vlax-variant-value (vlax-get-property Row 'Value2)))) ExcData))) (setq ExcData (reverse (mapcar (function (lambda (x) (mapcar 'vlax-variant-value x))) ExcData) ) ) (vl-catch-all-apply 'vlax-invoke-method (list Wbk "Close") ) (vl-catch-all-apply 'vlax-invoke-method (list ExcelApp "Quit") ) (mapcar (function (lambda (x) (if (not (vlax-object-released-p x)) (vlax-release-object x) ) ) ) (list UsdRange1 UsdRange2 UsdRange Sht Wbk ExcelApp) ) (setq UsdRange1 nil UsdRange2 nil UsdRange nil Sht nil Wbk nil ExcelApp nil ) (gc) (gc) ; to ignore empty cells: (vl-remove-if (function(lambda(x)(member nil x))) ExcData ) ) ;======================main part=======================; (if (and (setq data (exd)) (setq data (mapcar 'cons (car data)(cadr data))) (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 2 "Title-Block")(cons 66 1)))));<-- change title block name here (progn (setq i -1) (repeat (sslength ss) (setq blkref (vlax-ename->vla-object (ssname ss (setq i (1+ i))))) (setq atts (vlax-invoke blkref "GetAttributes")) (foreach at atts (if (setq itm (assoc (vla-get-tagstring at) data)) (progn (vla-put-textstring at (cdr itm)) (vla-update at))) ) (vla-update blkref) ) ) (alert "Something wrong") ) (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acallviewports) (princ) ) (prompt "\t\t***\t\nType AXE to change attributes\t***") (princ) ~'J'~ Quote
alanjt Posted April 27, 2010 Posted April 27, 2010 There you go MotoGirl. Thanks for sharing Fixo. Try this one don't remember how it worked ; Tested on A2005, A2008; MS Office 2003 (defun C:AXE (/) ;; local defun: ;; read Excel data (defun EXD ( / ExcelApp ExcData FilePath Sht ShtNum UsdRange Wbk) (vl-load-com) (setq FilePath (getfiled "Select Excel file to read attribute values:" (getvar "dwgprefix") "xls" 16 ) ) (setq ShtNum 1); Spreadsheet number, change to suit (setq ExcelApp (vlax-get-or-create-object "Excel.Application")) (vla-put-visible ExcelApp :vlax-true) (setq Wbk (vl-catch-all-apply 'vla-open (list (vlax-get-property ExcelApp "WorkBooks") FilePath))) (setq Sht (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property Wbk "Sheets") "Item" ShtNum))) (vlax-invoke-method Sht "Activate") (setq Sht (vlax-get-property ExcelApp "ActiveSheet")) (setq UsdRange1 (vlax-get-property Sht "Range" "A1:D1");<-- first row with headers (tags), change to suit UsdRange2 (vlax-get-property Sht "Range" "A3:D3");<-- second row with attribute values, change to suit UsdRange (vlax-invoke ExcelApp "Union" UsdRange1 UsdRange2 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil ) ) (vlax-for Row (vlax-get-property UsdRange 'Areas) (setq ExcData (cons (car (vlax-safearray->list (vlax-variant-value (vlax-get-property Row 'Value2)))) ExcData))) (setq ExcData (reverse (mapcar (function (lambda (x) (mapcar 'vlax-variant-value x))) ExcData) ) ) (vl-catch-all-apply 'vlax-invoke-method (list Wbk "Close") ) (vl-catch-all-apply 'vlax-invoke-method (list ExcelApp "Quit") ) (mapcar (function (lambda (x) (if (not (vlax-object-released-p x)) (vlax-release-object x) ) ) ) (list UsdRange1 UsdRange2 UsdRange Sht Wbk ExcelApp) ) (setq UsdRange1 nil UsdRange2 nil UsdRange nil Sht nil Wbk nil ExcelApp nil ) (gc) (gc) ; to ignore empty cells: (vl-remove-if (function(lambda(x)(member nil x))) ExcData ) ) ;======================main part=======================; (if (and (setq data (exd)) (setq data (mapcar 'cons (car data)(cadr data))) (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 2 "Title-Block")(cons 66 1)))));<-- change title block name here (progn (setq i -1) (repeat (sslength ss) (setq blkref (vlax-ename->vla-object (ssname ss (setq i (1+ i))))) (setq atts (vlax-invoke blkref "GetAttributes")) (foreach at atts (if (setq itm (assoc (vla-get-tagstring at) data)) (progn (vla-put-textstring at (cdr itm)) (vla-update at))) ) (vla-update blkref) ) ) (alert "Something wrong") ) (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acallviewports) (princ) ) (prompt "\t\t***\t\nType AXE to change attributes\t***") (princ) ~'J'~ Quote
fixo Posted April 27, 2010 Posted April 27, 2010 No flowers, please, still waiting for result from MotoGirl Quote
MotoGirl Posted April 27, 2010 Posted April 27, 2010 lmao, hahah i got a messege that said.... "something wrong" lol, i'm still working on it tho, i just thought it was funny, i feel that it should say that when i get those stupid unhelpful autocad errors. lol Quote
fixo Posted April 27, 2010 Posted April 27, 2010 lmao, hahah i got a messege that said.... "something wrong" lol, i'm still working on it tho. lol Can you upload your Excel file here Probably problem is on data format I use now Excel 2007 (I will be back just tomorrow only) ~'J'~ 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.