PDA

View Full Version : Using lisp to Edit Attributes in a Title Block


Red Devil
2007-07-25, 09:18 PM
Hi,

Does anyone know of a lisp routine that will let me edit an Attribute in a Title block in multiple Dwgs?
For example
We use attributes for our Revision Notes.

Rev No. Rev Date Rev Description

00 08.09.2007 Permit issue (<-----Attributes)

Now I have to add, to above, a Construction issue

Rev No. Rev Date Rev Description

00 08.09.2007 Permit issue (<-----Attributes)
01 10.09.2007 Construction issue (<-----Attributes)

How can I do this with a lisp routine so that i don't have to use ddatte and enter the text manually?

I've tried writing a lisp routine (very new to lisp first attempt) but it triggers a dialogue box for the Title Block attributes and then I am stuck. I just want it to select the appropriate attribute and replace it with a set value.

I've tried the ATTDIA, FILEDIA, CMDDIA commands to suppress the dialogue box but it still keeps popping up. Not even sure that would solve my problem.

Regards

Paul

rkmcswain
2007-07-26, 02:26 AM
Let me get this straight....

You want to programatically insert a block that contains attributes and fill in those attributes with known values? (or maybe the attributes are already part of the main block and are blank now...?)

Is the block/atts inserted in the same spot in each drawing?

Do you have to do this to many drawings? If so, do you want to make this change without even opening all these drawings? Or do you just want a routine to run now and then when the time arises?

ccowgill
2007-07-26, 01:48 PM
you may have to tweak these programs but I think it gives you a huge jump start on a program of course you will probably need to reorder everything, change the attribute tag names, and possibly even modify your title block to be more compatible. there are a couple of other things that may need to be tweaked, I think that this file is designed to be run with another program that takes care of some of the variables. the sheet control is specified by the layout tab name, this may also need to be tweaked


I forgot the procedure:
With the file name Revisions.xls in the x-folder. To specify the sheets that revisions apply to, follow this format:

ALL applies to all sheets

X####-## applies to the specific sheet

-X####-## applies to all sheets, excluding the sheet entered with a minus sign.

-- in the revision# column is to be used for the As-Recorded revision note only – this triggers the use of Red Text in the revision box.

Red Devil
2007-07-26, 08:48 PM
Hi Guys,

Thanks for your replys

I have a Title Block with Attributes tied into the revision data.
I now have to go into each Dwg and add a revision number, date and description to each and every Dwg. e.g. 01 07.26.07 Construction Issue

I just need a routine for every now again.

As I said I am new to Lisp and this is my first attempt. But when I try to edit the attributes and sub in my Setq values the routine opens the dialogue box and and waits for me to scroll thru the attibutes to the revisions and then enter them manualy. Which is what I'm trying to avoid.
I realise I have a ways to go but any help along the way helps!!

Regards

Paul

rkmcswain
2007-07-26, 09:19 PM
If you just want a quick routine to use every now and then, then this should work:




(command "._attedit" "_N" "_N" "BLOCKNAME" "TAGNAME" "*" "OLD_STRING" "NEW_STRING")

ccowgill
2007-07-26, 10:38 PM
Hi Guys,

Thanks for your replys

I have a Title Block with Attributes tied into the revision data.
I now have to go into each Dwg and add a revision number, date and description to each and every Dwg. e.g. 01 07.26.07 Construction Issue

I just need a routine for every now again.

As I said I am new to Lisp and this is my first attempt. But when I try to edit the attributes and sub in my Setq values the routine opens the dialogue box and and waits for me to scroll thru the attibutes to the revisions and then enter them manualy. Which is what I'm trying to avoid.
I realise I have a ways to go but any help along the way helps!!

Regards

Paul
if you could post a copy of your title block, I might be able to modify my routine to work for what you need.

stephen.coff
2007-07-27, 07:25 PM
rkmcswain,
Am I missing something here or have things changed in the newer versions ?
I am using 2008 and when i tried your simple routine I kept getting a request to select attributes.
Below is a copy of the command line.



Command: (command "._attedit" "_N" "_Y" "Sheet Details-DSA"
"WHAT_IS_THE_CURRENT_ISSUE" "*" "#" "1")
._attedit
Edit attributes one at a time? [Yes/No] <Y>: _N
Performing global editing of attribute values.
Edit only attributes visible on screen? [Yes/No] <Y>: _Y
Enter block name specification <*>: Sheet Details-DSA
Enter attribute tag specification <*>: WHAT_IS_THE_CURRENT_ISSUE
Enter attribute value specification <*>: * Select Attributes: #
*Invalid selection*
Expects a point or Window/Last/Crossing/BOX/Fence/WPolygon/CPolygon
; error: Function cancelled


If I have the command with the 2 "_N" I get another window open and the routine stops.
Even if i put it in manually I still get asked to select the attribute.


Stephen

rkmcswain
2007-07-27, 08:13 PM
This:


(command "._attedit" "_N" "_N" "Sheet Details-DSA" "WHAT_IS_THE_CURRENT_ISSUE" "*" "#" "1")


...works fine with a block I made up named "Sheet Details-DSA", that contains 1 attribute whose tag is "WHAT_IS_THE_CURRENT_ISSUE"

I also added more attributes to the same block and copied the block so that there are multiple insertions of the block.

The same code still works.

stephen.coff
2007-07-27, 08:15 PM
rkmcswain,
hmmm, is there any variables that you know of that could effect this working ?

Stephen

stephen.coff
2007-08-04, 11:01 AM
Guys,
Can anyone assist further here ?
I have played with simple code to edit an attribute and it does work (sort of) though it open the text window and needs to be closed. The second time around it doesn't work and the window still appears. Can anyone assist any further ?

Stephen

peter
2007-08-05, 04:08 PM
If you use the vl-directory-files expression to get a list of all drawings in a directory you can

(setq lstFiles (mapcar '(lambda (X)(strcat "c:/acadwin/" X))(vl-directory-files "c:/acadwin" "*.dwg")))

will give you a list of drawings

Then you can use the following function to change the attribute values in the title blocks

(mapcar '(lambda (X)(dbxatts X "mytitleblockname" "myattributetagstring" "the new attribute value") lstFiles)

Change to be your titleblockname and your attributetagstring.

I kinda threw this together for you but fundamentally it works.

You can modify it to do more like find the first blank revision attribute and add the value to that one....

Peter

(defun DBXATTS (strDWGname strBlockName strTagString strNewString /
objDBX DBXFILE strDWGName objLayout objSelection)
(setq objDBX (vla-GetInterfaceObject
(vlax-get-acad-object)
"ObjectDBX.AxDbDocument.17"; The .17 is for 2006
)
)
(vla-open objDBX (setq strDWGName (findfile strDWGName)))
(vlax-for objLayout (vla-get-layouts objDBX)
(vlax-for objSelection (vla-get-block objLayout)
(if (wcmatch (vla-get-objectname objSelection)
"AcDbBlockReference,AcDbMInsertBlock"
)
(if (wcmatch (strcase (vla-get-name objSelection))
(strcase strBlockName)
)
(foreach objAttribute (getAttributes objSelection)
(if (wcmatch (strcase (vla-get-tagstring objAttribute))
(strcase strTagString)
)
(progn
(vla-put-textstring objAttribute strNewString)
(vla-update objAttribute)
)
)
)
)
)
)
)
(vla-saveas objDBX strDWGName)
(vlax-release-object objDBX)
)


(defun StringSubst (strNewString strPattern strString)
(if (not (vl-string-search strPattern strNewString))
(while (vl-string-search strPattern strString 0)
(setq strString (vl-string-subst strNewString strPattern strString))
)
(princ "\nError: Old String is in the New String: ")
)
strString
)


(defun GetAttributes (objSelection /)
(if (= (type objSelection) 'ename)
(setq objSelection (vlax-ename->vla-object objSelection))
)
(if (= (vla-get-hasattributes objSelection) :vlax-true)
(vlax-safearray->list
(variant-value
(vla-getattributes objSelection)
)
)
)
)

stephen.coff
2007-08-07, 12:03 PM
Peter,
Sorry I have taken so long to get back. Thank you for the reply and the code. I am trying to write a routine that probably sounds pretty and simple and most likely is though seems a bit of a task for myself. I was trying to make use ofsome code from a routine Fixo had assisted me with recently. being dumb and dumber all rolled into one I struggle some what and expect what i have so far is totally screwed up.
My boss uses a revision line that is an attribute. So i figured I would just make 10copies of the attributed block with the same tags and just add a number on the end ranging 1 - 10.
That all i would do is table search the drawing for the blocks using the while function and the last number found would stop the search, add one and that was the block number to be inserted. The reason behind this was that all the blocks land on the correct line if inserted at 0,0,0. I could then just prompt for an issue and the date automatically be inserted. The revision for me is a little tricky.
My office starts with rev "A" then "B", "C", "D", "E" etc When the drawing goes for Tender the rev goes to nothing (blank) and the issue column then row i then set to "1". The following issue will then say issue "1" rev "A", "1B", "1C", "1D" , "1E" etc. When it goes to Construction the issue goes to "2" and the rev back to nothing. Then starts all over again "2A", "2B", "2C", "2D", "2E" etc.

I really have little idea of what I am looking at with your code and struggle at the best of times to get my head around lisp.
I have had an attept at this and it doesn't work as yet and needs more time though maybe this will help you understand where I am at and what I am trying to do ?
Attached is the code so far and a title block showing the ammendment line. If you type bedit you will see an example of the attributed block I aim to use with a 2 on the end of it.

Stephen

ccowgill
2007-08-07, 03:03 PM
Peter,
Sorry I have taken so long to get back. Thank you for the reply and the code. I am trying to write a routine that probably sounds pretty and simple and most likely is though seems a bit of a task for myself. I was trying to make use ofsome code from a routine Fixo had assisted me with recently. being dumb and dumber all rolled into one I struggle some what and expect what i have so far is totally screwed up.
My boss uses a revision line that is an attribute. So i figured I would just make 10copies of the attributed block with the same tags and just add a number on the end ranging 1 - 10.
That all i would do is table search the drawing for the blocks using the while function and the last number found would stop the search, add one and that was the block number to be inserted. The reason behind this was that all the blocks land on the correct line if inserted at 0,0,0. I could then just prompt for an issue and the date automatically be inserted. The revision for me is a little tricky.
My office starts with rev "A" then "B", "C", "D", "E" etc When the drawing goes for Tender the rev goes to nothing (blank) and the issue column then row i then set to "1". The following issue will then say issue "1" rev "A", "1B", "1C", "1D" , "1E" etc. When it goes to Construction the issue goes to "2" and the rev back to nothing. Then starts all over again "2A", "2B", "2C", "2D", "2E" etc.

I really have little idea of what I am looking at with your code and struggle at the best of times to get my head around lisp.
I have had an attept at this and it doesn't work as yet and needs more time though maybe this will help you understand where I am at and what I am trying to do ?
Attached is the code so far and a title block showing the ammendment line. If you type bedit you will see an example of the attributed block I aim to use with a 2 on the end of it.

Stephen
Thanks for posting an example of what you are looking for, I will try to have something maybe tomorrow, that will work off of excel. Is your titleblock xreffed and that is why the code is separate? I would recommend creating a single block that is inserted at 0,0 and contains all attributes in their proper locations, they will start of blank, but as the excel file is filed, the revisions will fill up.

ccowgill
2007-08-09, 02:47 PM
I do not know how to filter blocks that are dynamic, the whole random naming of the block for visibility states screws up the program. other than that, I got it to work on the default version of the block, except I couldnt get the first checked by field to fill in. I suppose if you created a separate block for the attributes, you would be fine, and wouldn't need the name of the main title block to run it.
anyway, here is the code that I have as of right now, maybe someone else can modify it further to better fit your needs

stephen.coff
2007-08-10, 08:42 AM
ccowgil,
Thank you for the reply and effort made. I will have a look at the routine and spreddsheet later tonight or tomorrow and get back to you.

Thanks again

Stephen