PDA

View Full Version : VBA with Fields



sdp777
02-13-2007, 06:43 PM
I am trying to produce a simple vba routine to get a pline, and provide the area via a field code. I have yet to find anything that explains field codes for vba. Are they exposed?

geekgirlau
02-13-2007, 07:38 PM
Hi sdp777,

We're going to need a bit more information here - as a general rule, more information is better than less.

What application? Version? Can you post a small, sanitised sample of what you're trying to achieve?

sdp777
02-13-2007, 07:49 PM
Valid points...I get onto to people who do that to me.

Autocad and VBA.
I was able to find out some information as to how to do via a friend, prolly one of the sharpest code guys still on the free market, relative to CAD, programming languages. For all.


Sub CreateField()
Dim vPt As Variant, vObj As Object, vObjPt As Variant

ThisDrawing.Utility.GetEntity vObj, vObjPt, vbLf + "Select polyline: "
vPt = ThisDrawing.Utility.GetPoint(, vbLf + "Pick point for mtext: ")

Dim strfield As String
strfield = "%<\AcObjProp Object(%<\_ObjId " + CStr(vObj.ObjectID) + ">%).Area>%"

Dim acMtext As AcadMText
ThisDrawing.ModelSpace.AddMText vPt, 2, strfield
End Sub


Sincerely,
Steven D. Papke
President and Owner
Visit the vizdepot!

Tommy
02-14-2007, 12:07 PM
ThisDrawing.ModelSpace.AddMText vPt, 2, strfield

This isn't going to work. The 2 needs to be calculated. It is supposed to be the width of the "box" surrounding the mtext entity. I use Len(string) * textheight * widthfacteroftextstyle. It is not completly correct but it is close enough for what I am doing (I use a lot of big fonts).

strfield looks like a call to lsp from vba(I hope) is it?

sdp777
02-14-2007, 12:25 PM
It works because MTEXT ignores the width value if the field is one word. In this case, its a field code for a number. You idea tho definitely has a value though. strfield, I believe is vlisp.

Tommy
02-14-2007, 05:31 PM
There is a file called Vlax.cls that makes the communication with lisp easier, I haven't used it.

What are you calling a field code? I am not familiar with that. dcl, lsp, vba, scr

I have Acad 2000i.