乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 118|回复: 2

[编程交流] 在块中插入公式

[复制链接]

2

主题

3

帖子

1

银币

初来乍到

Rank: 1

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

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 23:48:19 | 显示全部楼层
我想你需要另外两条线
 
面积=“%%”)。面积>%”
 
附件(3)。TextString=面积
附件(3)。使现代化
 
找到了这个
  1. Sub Example_Area()
  2.    ' This example creates a polyline object and
  3.    ' then uses the area property to find the
  4.    ' area of that polyline.
  5.    
  6.    Dim plineObj As AcadLWPolyline
  7.    Dim points(0 To 5) As Double
  8.    Dim plineArea As Double
  9.    ' Establish the points for the Polyline
  10.    points(0) = 3: points(1) = 7
  11.    points(2) = 9: points(3) = 2
  12.    points(4) = 3: points(5) = 5
  13.    
  14.    ' Create the polyline in modelspace
  15.    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
  16.    
  17.    ' Close the polyline and update display of it
  18.    plineObj.Closed = True
  19.    plineObj.Update
  20.    ZoomAll
  21.    
  22.    ' Get the area of the polyline
  23.    plineArea = plineObj.Area
  24.    
  25.    MsgBox "The area of the new Polyline is: " & plineArea, vbInformation, "Area Example"
  26. End Sub
回复

使用道具 举报

2

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-7 00:08:04 | 显示全部楼层
找到了解决方案,谢谢。
 
属性。TextString=“%%”)。面积\f”&Chr(34)&“%lu2”&Chr(34)&“>%”
其中Cstr(id)是poly objectID
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 06:09 , Processed in 0.541500 second(s), 58 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表