PDA

View Full Version : Fields w/ VBA



zfoland20
2004-06-15, 09:56 PM
Is it possible to program your fields using VBA? Also, can you use fields w/ VBA to automatically populate an Excel Spreadsheet?

Thanks in advance,
Zach

Mike.Perry
2004-06-16, 07:40 AM
Hi Zach

Please note I've *moved* this Topic (Thread) from the ACAD 2005 Fields Forum (http://forums.augi.com/forumdisplay.php?f=53) to this one as I believe it would be better served here.

Thanks, Mike

Forum Moderator

RobertB
2004-06-22, 12:33 AM
Field expressions can be added to the TextString property. Simply use the desired field expression that the field dialog displays.

The answer to your 2nd question is "sort of". Once the field expression is added to the TextString property, it will then appear as normal text if you reexamine the property. So you can use that to populate Excel.


Sub Test()
Dim pt0(0 To 2) As Double
Dim myText As AcadMText
Set myText = ThisDrawing.ModelSpace.AddMText(pt0, 3, _
"%<\AcVar Filename \f " & Chr(34) & "%fn7" & Chr(34) & ">%")
Debug.Print myText.TextString
End Sub

thomas-p
2005-05-05, 07:17 PM
I'm trying to insert the area field of a selected object. I get your code to work using the following

%<AcObjProp Object(%<_ObjId 2126689144>%).Area>%

How can I get the 2126689144 ID number to placed from the object I pick. I replaced it with ID as follows:

Dim id As Long

id = myObject.ObjectID

Set myArea = ThisDrawing.ModelSpace.AddMText(pt0, 3, _
"%<AcObjProp Object(%<_ObjId id>%).Area>%")
Debug.Print myArea.TextString

This does not work. Is there a way to do this.


Field expressions can be added to the TextString property. Simply use the desired field expression that the field dialog displays.

The answer to your 2nd question is "sort of". Once the field expression is added to the TextString property, it will then appear as normal text if you reexamine the property. So you can use that to populate Excel.


Sub Test()
Dim pt0(0 To 2) As Double
Dim myText As AcadMText
Set myText = ThisDrawing.ModelSpace.AddMText(pt0, 3, _
"%<AcVar Filename f " & Chr(34) & "%fn7" & Chr(34) & ">%")
Debug.Print myText.TextString
End Sub

thomas-p
2005-05-05, 08:52 PM
I figured it out. For anyone that wants to know this is what I did.

I switch to text instead of Mtext also.


TextId = myObject.ObjectID
text = "%<\AcObjProp Object(" + TextId + ").Area>%"

insertionPoint(0) = 0: insertionPoint(1) = 0: insertionPoint(2) = 0
Height = 0.08

Set myArea = ThisDrawing.ModelSpace.AddText(text, insertionPoint, Height)

RobertB
2005-05-05, 10:35 PM
You should use the & operator to concatentate strings and not the + operator.

thomas-p
2005-05-09, 01:21 PM
Ok, thanks.


You should use the & operator to concatentate strings and not the + operator.