Jump to content

insert a formula in the block attribute value via vba


Recommended Posts

Hi everybody,

 

I'm new with autocad. Actually it's my first time I need to write a VBA procedure for autocad. That's the reason why I'm posting this thread.

 

I have blocks with attribute. In one of this attribute I want to insert an expression that calculates a polyline area.

 

Doing it manually works. the expression is:

"%%).Area>%" where 2130001176 is the ObjectID of the specific poly.

 

I tried to insert the expression via vba with this code:

attArr = oBlkRef.GetAttributes

attArr(3).TextString = "%%).Area>%"

 

It doesn't work and the value (corresponding to the poly area) is not calculated. Only "####" is shown as value.

 

Any idea how to insert the expression via VBA?

Edited by aleair
error
Link to post
Share on other sites

I think you need 2 extra line

 

area ="%%).Area>%"

 

attArr(3).TextString = area

attarr(3).update

 

found this

Sub Example_Area()
   ' This example creates a polyline object and
   ' then uses the area property to find the
   ' area of that polyline.
   
   Dim plineObj As AcadLWPolyline
   Dim points(0 To 5) As Double
   Dim plineArea As Double
   ' Establish the points for the Polyline
   points(0) = 3: points(1) = 7
   points(2) = 9: points(3) = 2
   points(4) = 3: points(5) = 5
   
   ' Create the polyline in modelspace
   Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
   
   ' Close the polyline and update display of it
   plineObj.Closed = True
   plineObj.Update
   ZoomAll
   
   ' Get the area of the polyline
   plineArea = plineObj.Area
   
   MsgBox "The area of the new Polyline is: " & plineArea, vbInformation, "Area Example"
End Sub

Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...