grazwelis Posted January 27, 2009 Posted January 27, 2009 Hello.. Could you help me? I am green i Autocad VBA. Could you help me write vba program for it. Attributes tags name = drawings filename. Is it possible? for example i have drawing and when i am opening tags name write filename: c:\autocad\Test01.Dwg Block attribute tags name NR1 = test01 c:\autocad\drawing12.Dwg Block attribute tags name NR1 = drawing12 Thanks Quote
dbroada Posted January 27, 2009 Posted January 27, 2009 its possible in VBA but it is much easier to just insert a field Quote
Lee Mac Posted January 27, 2009 Posted January 27, 2009 This could also be accomplished in LISP if that suits you also. The necessary information is stored in the following variables: (getvar "dwgname") (getvar "dwgprefix") Depending upon whether you would like the drawing name alone, or the whole filepath written, these variables can be manipulated to suit. Would you like to proceed with LISP? Quote
Lee Mac Posted January 27, 2009 Posted January 27, 2009 Haha, Dave, you must've just beaten me to the mark. Quote
dbroada Posted January 27, 2009 Posted January 27, 2009 that's 'cause my solution required less typing. Quote
grazwelis Posted January 27, 2009 Author Posted January 27, 2009 its possible in VBA but it is much easier to just insert a field Could you make an example? please Quote
Lee Mac Posted January 27, 2009 Posted January 27, 2009 I've also never used a field before - Dave could you explain further please Quote
dbroada Posted January 27, 2009 Posted January 27, 2009 when you create an attribute right click in the default value box. One of the selections is "INSERT FIELD". Select "File Name" in the left column and set your options. Press OK and Robert is your dad's brother. You can do the same if you have already created the block in the attribute editor of your choice. Quote
Lee Mac Posted January 27, 2009 Posted January 27, 2009 Sounds good, but is it only in '08? I can't seem to do it in '04. I laughed at this \/ Press OK and Robert is your dad's brother.. Quote
dbroada Posted January 27, 2009 Posted January 27, 2009 Sounds good, but is it only in '08? I can't seem to do it in '04. Ah, you may have me there. I don't remember what release they came in at, probably 2006. Sorry. Quote
Lee Mac Posted January 27, 2009 Posted January 27, 2009 Ah, you may have me there. I don't remember what release they came in at, probably 2006. Sorry. No probs Dave, but good solution for if I upgrade - sounds like an easy fix. Quote
grazwelis Posted January 28, 2009 Author Posted January 28, 2009 Ah, you may have me there. I don't remember what release they came in at, probably 2006. Sorry. No probs Dave, but good solution for if I upgrade - sounds like an easy fix. Thanks again, Field is good idea, but VBA I think is better Because we can make more flexible. For example I need like this: I have example filenames, and need decode like this Drawing13_1 (Deskription).dwg tag: Value: filename...Drawing13 Page.......1 Drawing17_2 (Description).dwg filename...Drawing17 Page.......2 Drawing01_7 (bla bla).dwg filename...Drawing01 Page.......7 So i am very green in VBA editing I have Autocad2009. Maybe somebody is wizar in VBA and could give me adwise for that Thanks, Quote
Lee Mac Posted January 28, 2009 Posted January 28, 2009 I suppose you could use vl-string-search in LISP to segregate terms... Sorry for the emphasis on LISP - but my VBA skills are non-existent... Quote
dbroada Posted January 28, 2009 Posted January 28, 2009 it is relatively trivial in VBA using Lee's original post (getvar "dwgname")(getvar "dwgprefix") you cn extract the values and then work on them in VBA. You need a bit more code to write them back to an attribute but its not too complicated. however I do have work that MUST come first so I'll leave at this point..... Quote
Lee Mac Posted January 28, 2009 Posted January 28, 2009 As Dave says, using the values as I posted, you can retrieve the filename - then either using VBA or LISP, update the attribute accordingly. Updating an attriute isn't too difficult - just substitution of various DXF codes. Just to verify - You have two attributes: Filename, and Page, and you want the attribute values of these to be the Drawing Name and page number respectively. Am I close? Quote
dbroada Posted January 28, 2009 Posted January 28, 2009 The following is a code I used to use to add the filename as a field in our drawing blank. Public Sub PopCadFile() '%<\AcVar Filename \f "%tc1%fn2">% Dim myEntity As AcadEntity Dim mySelSet As AcadSelectionSet Dim TempName As String Dim gpCode(0 To 1) As Integer Dim dataValue(0 To 1) As Variant Dim groupCode As Variant Dim dataCode As Variant Dim myAttrib As Variant Dim myCurrentAtt As Variant TempName = "%<\AcVar Filename \f " & Chr$(34) & "%tc1%fn2" & Chr$(34) & ">%" gpCode(0) = 0 'item gpCode(1) = 2 '? groupCode = gpCode dataValue(0) = "INSERT" 'item type dataValue(1) = "STL*" '? dataCode = dataValue Set mySelSet = ThisDrawing.SelectionSets.Add("Blocks") mySelSet.Select acSelectionSetAll, , , groupCode, dataCode For Each myEntity In mySelSet myAttrib = myEntity.GetAttributes For Each myCurrentAtt In myAttrib If myCurrentAtt.TagString = "CADFILE" Then myCurrentAtt.TextString = TempName If myCurrentAtt.TagString = "XXX-XXX.DWG" Then myCurrentAtt.TextString = TempName Next myCurrentAtt Next myEntity ThisDrawing.SelectionSets.Item("Blocks").Delete End Sub ALL our blanks start with STL so I search for a drawing blank. Depending on the age of the drawing the ATTRIBUTE I want is either CADFILE or XXX-XXX.DWG. TempName is the field value, insert your own values in there. Quote
grazwelis Posted January 29, 2009 Author Posted January 29, 2009 As Dave says, using the values as I posted, you can retrieve the filename - then either using VBA or LISP, update the attribute accordingly. Updating an attriute isn't too difficult - just substitution of various DXF codes. Just to verify - You have two attributes: Filename, and Page, and you want the attribute values of these to be the Drawing Name and page number respectively. Am I close? Of course you all right Quote
Lee Mac Posted January 29, 2009 Posted January 29, 2009 Ok, if you don't get on with Dave's code - let me know and I'll see if I can engineer you something to do the job 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.