明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 765|回复: 0

删除文字和标注和创建面域并移动

[复制链接]
发表于 2020-1-3 21:15:24 | 显示全部楼层 |阅读模式
本帖最后由 dogingate 于 2020-1-3 21:18 编辑

CAD的VBA正在学习中,写了几个小插件
1、AddMenu增加菜单
2、deleteTextAndDimension删除选中的文字和标注
3、readSectionProperties
创建面域并将面域的形心移动到整体坐标系0点

具体代码如下:

Sub AddMenu()
' On Error Resume Next
' ¶¨òåμ±Ç°2Ëμ¥×éμıäá¿
Dim oMenus As AcadPopupMenus
Dim oMyMenu As AcadPopupMenu
Dim strMenuName As String
Dim oMyMenuItem As AcadPopupMenuItem

Set oMenus = ThisDrawing.Application.MenuGroups.Item(0).Menus

On Error Resume Next
Set oMyMenu = oMenus.Item("Wolf")
If oMyMenu Is Nothing Then
    Set oMyMenu = oMenus.Add("Wolf")
End If

If Not oMyMenu.OnMenuBar Then
    oMyMenu.InsertInMenuBar ThisDrawing.Application.MenuBar.count
End If

Set oMyMenuItem = oMyMenu.AddMenuItem(0, "é¾3yÎÄ×Öoí±ê×¢", "-vbarun deleteTextAndDimension ")
Set oMyMenuItem = oMyMenu.AddMenuItem(0, "¸Öêø¶áè¡", "-vbarun deleteTextAndDimension ")
Set oMyMenuItem = oMyMenu.AddMenuItem(0, "½ØÃæìØDÔ", "-vbarun readSectionProperties ")
End Sub


Sub deleteTextAndDimension()
Dim oDrawing As Object: Set oDrawing = ThisDrawing
Dim oUtil As Object: Set oUtil = oDrawing.Utility
Dim oSset As Object

If oDrawing.SelectionSets.count <> 0 Then
    For i = oDrawing.SelectionSets.count - 1 To 0 Step -1
        oDrawing.SelectionSets(i).Delete
    Next i
End If
    Set oSset = ThisDrawing.SelectionSets.Add("TEST_SSET") '&#212;&#246;&#188;ó&#209;&#161;&#212;&#241;&#188;ˉ

Dim FilterType(3) As Integer
Dim FilterData(3) As Variant
FilterType(0) = -4
FilterType(1) = 0
FilterType(2) = 0
FilterType(3) = -4
FilterData(0) = "<OR"
FilterData(1) = "TEXT"
FilterData(2) = "DIMENSION"
FilterData(3) = "OR>"

oSset.SelectOnScreen FilterType, FilterData '''&#212;ú&#198;á&#196;&#187;é&#207;&#189;&#248;DD&#209;&#161;&#212;&#241;
oSset.Highlight ture
oSset.Erase


End Sub

Sub readSectionProperties()
Dim oDraw As ThisDrawing
Dim oSset As AcadSelectionSet
Dim bool As Boolean: bool = False
For Each oSset In ThisDrawing.SelectionSets
    If oSset.Name = "wolf" Then
        bool = True
    End If
Next
If bool Then
    Set oSset = ThisDrawing.SelectionSets.Item("wolf")
    oSset.Delete
End If
Set oSset = ThisDrawing.SelectionSets.Add("wolf")

oSset.SelectOnScreen

Dim ents() As AcadEntity: ReDim ents(oSset.count - 1)
For i = 0 To oSset.count - 1
    Set ents(i) = oSset(i)
Next i

'oSset.Delete

Dim varRegions As Variant

varRegions = ThisDrawing.ModelSpace.AddRegion(ents)

temp = 0
k = 0
For i = LBound(varRegions) To UBound(varRegions)
    If varRegions(i).Area > temp Then
        k = i
        temp = varRegions(i).Area
    End If
Next i

Dim oReg As Object
For i = LBound(varRegions) To UBound(varRegions)
    If i <> k Then
        varRegions(k).Boolean acSubtraction, varRegions(i)
    End If
Next i

Dim varCentroid As Variant
varCentroid = varRegions(k).Centroid

Set oReg = varRegions(k)
Dim pt1(0 To 2) As Double
Dim pt2(0 To 2) As Double
pt1(0) = varCentroid(0): pt1(1) = varCentroid(1): pt1(2) = 0
pt2(0) = 0: pt2(1) = 0: pt2(2) = 0


'Dim varPt1 As Variant
'Dim varPt2 As Variant
'
'varPt1 = ThisDrawing.Utility.GetPoint(, vbCrLf & "Base point: ")
'varPt2 = ThisDrawing.Utility.GetPoint(varPt1, vbCrLf & "Second point: ")
'oReg.Move varPt1, varPt2

oReg.Move pt1, pt2
oReg.Update

End Sub







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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 23:40 , Processed in 0.161688 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表