aleair 发表于 2022-7-6 22:51:46

在块中插入公式

大家好,
 
我是autocad新手。实际上,这是我第一次需要为autocad编写VBA程序。这就是我发布这个帖子的原因。
 
我有属性块。在其中一个属性中,我想插入一个计算多段线面积的表达式。
 
手动操作有效。表达式为:
“%%”)。面积>%”,其中213001176是特定多边形的ObjectID。
 
我试图用以下代码通过vba插入表达式:
attArr=oBlkRef。获取属性
附件(3)。TextString=“%%”)。面积>%”
 
它不起作用,并且不会计算值(对应于多边形区域)。只有“#####”显示为值。
 
知道如何通过VBA插入表达式吗?

BIGAL 发表于 2022-7-6 23:48:19

我想你需要另外两条线
 
面积=“%%”)。面积>%”
 
附件(3)。TextString=面积
附件(3)。使现代化
 
找到了这个
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

aleair 发表于 2022-7-7 00:08:04

找到了解决方案,谢谢。
 
属性。TextString=“%%”)。面积\f”&Chr(34)&“%lu2”&Chr(34)&“>%”
其中Cstr(id)是poly objectID
页: [1]
查看完整版本: 在块中插入公式