乐筑天下

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

[编程交流] 替代标注文字trou

[复制链接]

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 11:57:58 | 显示全部楼层 |阅读模式
大家好,
在打开一个新的图形文件和许多不同类型的型腔图形时,我有自己的模板,我使用插入块命令插入这些图形。然后在标注这些空腔尺寸时使用“分解”命令。选定圆的直径测量随圆尺寸标注自动提供。但在那之后,我必须添加或附加一些额外的文本到特定于该空洞的维度。我不想每次都使用编辑文本命令。
所以我决定用VBA编写一个宏。我想做的是:
首先,我将选择用于标注尺寸的圆。选择后,将出现我的对话框,然后我将使用选项按钮选择型腔的类型。最后,当我单击命令按钮时,该空腔的特定文本将根据其直径自动涂改。我已经创建了对话框。
我的问题是,我熟悉VB,但我完全不懂VBA对象类型,我没有设法识别选定的圆。我试图创建一个新的AcadDimDiametric并使用AcadEntity指定选定的圆,但我不知道如何继续。
是否有任何信息资源或示例代码页可供探索?谢谢。。。
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 12:09:29 | 显示全部楼层
  1. ...............
  2. Dim oDimDia as AcadDimDiametric
  3. Dim oEnt as AcadEntity
  4. Dim oCircle as AcadCircle
  5. 'After you selected a circle try this
  6. If TypeOf oent Is AcadCircle Then
  7. Set oCircle =oEnt
  8. oDimDia.TextOveride = "Diameter=" & Cstr(oDimDia.Measurement)' <--or something you need
  9. End If

 
我无法像使用ampowerdim_dia命令那样固定尺寸的位置。在使用ampowerdim\u dia完成标注后,是否有方法以编程方式编辑标注文本?我们如何理解某些用户使用ampowerdim\u dia命令完成了操作?非常感谢,新年快乐。。。
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 12:21:51 | 显示全部楼层
 
对不起,我对ampowerdim\u dia命令一无所知
我猜这不是一个普通的Autocad命令,不是吗?
 
试试这个,但稍微编辑一下
 
  1.    Private Sub AddDimensionText()
  2.      Dim dimDiametric As AcadDimDiametric
  3.      Dim util As AcadUtility
  4.      Dim entity As AcadEntity
  5.      Dim circ As AcadCircle
  6.      Dim centerPoint As Variant
  7.      Dim pt1(0 To 2) As Double
  8.      Dim pt2(0 To 2) As Double
  9.      Dim dimLength As Double
  10.      Dim mainLength As Double
  11.      On Error Resume Next
  12.      Set util = ThisDrawing.Utility
  13.      util.GetEntity entity, centerPoint, "Select circle"
  14.      If Err.Number <> 0 Then
  15.          Err.Clear
  16.          MsgBox "Entity not selected"
  17.      Else
  18.          If TypeOf entity Is AcadCircle Then
  19.              Set circ = entity
  20.              centerPoint = circ.Center
  21.              dimLength = circ.Radius
  22.              mainLength = Math.Sqr((dimLength * dimLength) + (dimLength * dimLength))
  23.              pt1(0) = centerPoint(0) + dimLength: pt1(1) = centerPoint  (1) + dimLength: pt1(2) = 0
  24.              pt2(0) = pt1(0) + mainLength: pt2(1) = pt1(1) + mainLength: pt2(2) = 0
  25.              Set dimDiametric =   ThisDrawing.ModelSpace.AddDimDiametric(pt2, pt1, 0)
  26.              dimDiametric.Update
  27.          Else
  28.              MsgBox "Please select a circle"
  29.          End If
  30.      End If
  31. End Sub

 
新年快乐
 
~'J'~
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 12:37:27 | 显示全部楼层
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 12:48:48 | 显示全部楼层
Hello everyone ;
 
So far , I have managed to add diametric dimension and I know how to update the dimension text.But now I have point setting problems on the added dimension.Here is what I have wrote :
 
  1.    Private Sub AddDimensionText()     Dim dimDiametric As AcadDimDiametric     Dim util As AcadUtility     Dim entity As AcadEntity     Dim circ As AcadCircle     Dim centerPoint As Variant     Dim pt1(0 To 2) As Double     Dim pt2(0 To 2) As Double     Dim dimLength As Double     Dim mainLength As Double     On Error Resume Next     Set util = ThisDrawing.Utility     util.GetEntity entity, centerPoint, "Select circle"     If Err.Number  0 Then         Err.Clear         MsgBox "Entity not selected"     Else         If TypeOf entity Is AcadCircle Then             Set circ = entity             centerPoint = circ.Center              dimLength = circ.Radius              mainLength = Math.Sqr((dimLength * dimLength) + (dimLength * dimLength))              pt1(0) = centerPoint(0) + dimLength: pt1(1) = centerPoint  (1) + dimLength: pt1(2) = 0              pt2(0) = pt1(0) + mainLength: pt2(1) = pt1(1) + mainLength: pt2(2) = 0             Set dimDiametric =   ThisDrawing.ModelSpace.AddDimDiametric(pt2, pt1, 0)             dimDiametric.Update         Else             MsgBox "Please select a circle"         End If     End If End Sub
 
I could not fix the position of the dimension as we can do with ampowerdim_dia command.Is there a way to edit programmatically the dimension text after finishing the dimensioning using ampowerdim_dia ? How can we understand that some user is finished using ampowerdim_dia command ? Thanks a lot , happy new year...
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 12:58:11 | 显示全部楼层
 
Sorry I know nothing about ampowerdim_dia command
Guess it's not a plain Autocad command, isn't it?
 
Try this but slightly edited
 
  1. Option Explicit   Private Sub AddDimensionText()     Dim dimDiametric As AcadDimDiametric     Dim util As AcadUtility     Dim entity As AcadEntity     Dim circ As AcadCircle     Dim centerPoint As Variant     Dim pt1(0 To 2) As Double     Dim pt2(0 To 2) As Double     Dim pi As Double     pi = 3.14159265358979     Dim dimLength As Double     Dim mainLength As Double     On Error Resume Next     Set util = ThisDrawing.Utility     util.GetEntity entity, centerPoint, "Select circle"     If Err.Number  0 Then         Err.Clear         MsgBox "Entity not selected"     Else         If TypeOf entity Is AcadCircle Then             Set circ = entity             centerPoint = circ.Center             dimLength = circ.Radius             mainLength = dimLength * Sin(pi / 4)              pt1(0) = centerPoint(0) - mainLength: pt1(1) = centerPoint(1) - mainLength: pt1(2) = 0              pt2(0) = centerPoint(0) + mainLength: pt2(1) = centerPoint(1) + mainLength: pt2(2) = 0             Set dimDiametric = ThisDrawing.ModelSpace.AddDimDiametric(pt2, pt1, dimLength)             dimDiametric.LeaderLength = dimLength             dimDiametric.Update         Else             MsgBox "Please select a circle"         End If     End If End Sub
 
Happy New Year
 
~'J'~
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 10:22 , Processed in 0.777778 second(s), 64 queries .

© 2020-2025 乐筑天下

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