Author Topic: Where am I going wrong - Fields to areas (polylines).  (Read 3896 times)

0 Members and 1 Guest are viewing this topic.

Matersammichman

  • Guest
Where am I going wrong - Fields to areas (polylines).
« on: November 02, 2007, 08:09:57 AM »
I am trying to write a vba routine that will allow me to apply Fields to areas (polylines). I've tried numerous methods, but keep getting ####. I'm trying not to use regions and boundaries. Where am I going wrong?
2007 CAD

Code: [Select]
Private Sub CommandButton5_Click()
    Me.hide
Dim Mytext As AcadText
Dim entarea As Double
Dim textObj As AcadEntity
Dim text As String
Dim fieldcode As String
Dim insertionPoint(0 To 2) As Double
Dim height As Double
Dim NewArea As Double
Dim OBJID As Variant
Dim objEnt As AcadEntity
Dim varPick As Variant
Dim TXTID2 As AcadText
Dim entObjectID As Long
Dim sysVarName As Variant
Dim VARDATA As Variant
Dim returnpnt As Variant
sysVarName = "dimscale"
VARDATA = ThisDrawing.GetVariable(sysVarName)
    Dim plineObj As AcadLWPolyline
    Dim plineArea As Double

ThisDrawing.Utility.GetEntity objEnt, varPick, vbCr & "Select object for Area: "
entObjectID = objEnt.ObjectID
Set plineObj = objEnt
MsgBox "The ObjectID of this object is " & entObjectID, vbInformation, "ObjectID Example"
plineArea = (plineObj.Area \ 144)
MsgBox "The area is: " & plineArea, vbInformation, "Area Example"
returnpnt = ThisDrawing.Utility.GetPoint(, "Select Block Insertion Point: ")
height = Val(VARDATA * 0.09375) 'fixED to 3/32
'%<\AcObjProp Object(%<\_ObjId 1916720304>%).Area>%
text = "%<\AcObjProp plineArea(%<\_entojectid>%).Area>%"
'text = "%<\AcObjProp plineArea \f>%"
MsgBox "The Square Footage for the selected entity equals: " & fieldcode, vbInformation, "FieldCode Example"
Set textObj = ThisDrawing.ModelSpace.AddText(text, returnpnt, height) 'must use fieldcode
text = textObj.fieldcode
End Sub


edit jonesy... thread title changed/added code pane
« Last Edit: November 02, 2007, 09:55:09 AM by jonesy »

Guest

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #1 on: November 02, 2007, 10:08:48 AM »
Try editing the text, then select the EDIT FIELD.   When I do it, it says *Unknown*.  So the code for the field is wrong somewhere.

Matersammichman

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #2 on: November 02, 2007, 12:28:48 PM »
Thanks. I'd already tried that too.

Fatty

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #3 on: November 02, 2007, 02:54:45 PM »
Try AddMText instead

~'J'~

Guest

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #4 on: November 02, 2007, 03:46:59 PM »
Try AddMText instead

~'J'~

Why would it make a difference if he used MText instead of Text?

LE

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #5 on: November 02, 2007, 04:21:54 PM »
the problem or error is in this line:

Quote
text = "%<\AcObjProp plineArea(%<\_entojectid>%).Area>%"

i don't do vb/a but try to change the field code to something:

Quote
text = "%<\AcObjProp Object(%<\_ObjId 2130318016>%).Area>%"

as you have in some place on your code un comment...

LE

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #6 on: November 02, 2007, 04:43:16 PM »
or try/test with this:

Quote
text = "%<\AcObjProp Object(%<\_ObjId " + Str$(entObjectID) + ">%).Area>%"


that will add the field value....

Matersammichman

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #7 on: November 02, 2007, 04:55:36 PM »
...still won't work.

LE

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #8 on: November 02, 2007, 04:58:10 PM »
...still won't work.

Strange... here is the code I tested... (I just did minor changes to your original code)

Code: [Select]
Public Sub AddAreaField()
Dim Mytext As AcadText
Dim entarea As Double
Dim textObj As AcadEntity
Dim text As String
Dim fieldcode As String
Dim insertionPoint(0 To 2) As Double
Dim height As Double
Dim NewArea As Double
Dim OBJID As Variant
Dim objEnt As AcadEntity
Dim varPick As Variant
Dim TXTID2 As AcadText
Dim entObjectID As Long
Dim sysVarName As Variant
Dim VARDATA As Variant
Dim returnpnt As Variant
sysVarName = "dimscale"
VARDATA = ThisDrawing.GetVariable(sysVarName)
    Dim plineObj As AcadLWPolyline
    Dim plineArea As Double

ThisDrawing.Utility.GetEntity objEnt, varPick, vbCr & "Select object for Area: "
entObjectID = objEnt.ObjectID
Set plineObj = objEnt
MsgBox "The ObjectID of this object is " & entObjectID, vbInformation, "ObjectID Example"
plineArea = (plineObj.Area \ 144)
MsgBox "The area is: " & plineArea, vbInformation, "Area Example"
returnpnt = ThisDrawing.Utility.GetPoint(, "Select Block Insertion Point: ")
height = Val(VARDATA * 0.09375) 'fixED to 3/32

text = "%<\AcObjProp Object(%<\_ObjId " + Str$(entObjectID) + ">%).Area>%"

'text = "%<\AcObjProp plineArea \f>%"
MsgBox "The Square Footage for the selected entity equals: " & fieldcode, vbInformation, "FieldCode Example"

Set textObj = ThisDrawing.ModelSpace.AddText(text, returnpnt, height) 'must use fieldcode
'Set textObj = ThisDrawing.ModelSpace.AddMText(returnpnt, height, text) 'must use fieldcode
text = textObj.fieldcode
End Sub

Matersammichman

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #9 on: November 02, 2007, 05:05:48 PM »
It chokes at-
Str$

What's causing that?

LE

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #10 on: November 02, 2007, 05:09:12 PM »
It chokes at-
Str$

What's causing that?

I ran the macro/function inside of AutoCAD 2007 - and it is working

as I said, I am not a VB/A programmer

Fatty

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #11 on: November 03, 2007, 09:50:37 AM »
Hi
This worked for me too in A2007eng

Code: [Select]
Private Sub CommandButton5_Click()
Me.hide


Dim Mytext As AcadMText
Dim entarea As Double
Dim textObj As AcadEntity
Dim text As String
Dim fieldcode As String
Dim insertionPoint(0 To 2) As Double
Dim height As Double
Dim NewArea As Double
Dim OBJID As Variant
Dim objEnt As AcadEntity
Dim varPick As Variant
Dim TXTID2 As AcadText
Dim entObjectID As Long
Dim sysVarName As Variant
Dim VARDATA As Variant
Dim returnpnt As Variant
sysVarName = "dimscale"
VARDATA = ThisDrawing.GetVariable(sysVarName)
Dim plineObj As AcadLWPolyline
Dim plineArea As Double

ThisDrawing.Utility.GetEntity objEnt, varPick, vbCr & "Select object for Area: "
entObjectID = objEnt.ObjectID
Set plineObj = objEnt
'//MsgBox "The ObjectID of this object is " & entObjectID, vbInformation, "ObjectID Example"
plineArea = plineObj.Area / 144
MsgBox "The area is: " & Format(CStr(plineArea), "0.00000"), vbInformation, "Area Example"
returnpnt = ThisDrawing.Utility.GetPoint(, "Select Block Insertion Point: ")

height = CDbl(VARDATA * 0.09375) 'fixED to 3/32

text = " %<\AcObjProp Object(%<\_ObjId " & CStr(entObjectID) & ">%).Area \f " & Chr(34) & "%lu2%ct4%qf1 SQ. FT." & Chr(34) & ">%"

'//MsgBox "The Square Footage for the selected entity equals: " & fieldcode, vbInformation, "FieldCode Example"
Set Mytext = ThisDrawing.ModelSpace.AddMText(returnpnt, 0#, text)   'must use fieldcode
Mytext.height = height
ThisDrawing.Regen acActiveViewport
text = Mytext.fieldcode
MsgBox text
Me.Show
End Sub

~'J'~

Guest

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #12 on: November 05, 2007, 08:28:22 AM »
Worked for me in MEP 2008.

One thing I did notice was that if your current dimstyle was set as ANNOTATIVE it wouldn't work because the dimscale for an annotative dimension style is 0.


Matersammichman

  • Guest
Re: Where am I going wrong - Fields to areas (polylines).
« Reply #13 on: November 05, 2007, 12:35:31 PM »
Got it, thanks.
The problem was missing refernces.