明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 438|回复: 11

怎样分解属性块

[复制链接]
发表于 2024-6-4 10:59 | 显示全部楼层 |阅读模式
怎样分解CASS高程点,此程序分解为最后一行那样 ,正常应是第一行那样。

        Dim DocLock As DocumentLock = Core.Application.DocumentManager.MdiActiveDocument.LockDocument()
        NativeMethods.SetFocus(Core.Application.DocumentManager.MdiActiveDocument.Window.Handle) 'CAD获得焦点
        Dim ed As Editor = Core.Application.DocumentManager.MdiActiveDocument.Editor '对话框
        Dim db As Database = HostApplicationServices.WorkingDatabase '数据库对象  
        Dim psr As PromptSelectionResult '请求在图形区域选择对象
        Dim SetA As SelectionSet '= Nothing
        psr = ed.GetSelection() '屏幕选取
        If psr.Status = PromptStatus.OK Then '如果提示状态OK,表示对象已选
            SetA = psr.Value
            Dim ids As ObjectId() = SetA.GetObjectIds
            For Each obj In SetA
                Using cTrans As Transaction = db.TransactionManager.StartTransaction() '开启事务处理
                    Dim entity As Entity = CType(cTrans.GetObject(obj.ObjectId, OpenMode.ForWrite, True), Entity)
                    Using dbObjCol As New DBObjectCollection
                        entity.Explode(dbObjCol)

                        For Each dbObj As DBObject In dbObjCol
                            Dim acEnt As Entity = dbObj
                            acEnt.ColorIndex = 6 '颜色索引
                            AppendEntity(acEnt)
                            ???
                            acEnt = cTrans.GetObject(dbObj.ObjectId, OpenMode.ForWrite)
                            ed.WriteMessage(vbLf & "Exploded Object: " & acEnt.GetRXClass().DxfName)
                        Next
                    End Using
                    cTrans.Commit()
                End Using
            Next
        End If

        '''https://www.cadn.net.cn/portal.php?mod=view&aid=11626'原文



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2024-6-4 18:56 | 显示全部楼层
  1. <CommandMethod("TcExplodeAtt")>
  2.     Public Sub TcExplodeAtt()
  3.         On Error Resume Next
  4.         Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  5.         Dim acCurDb As Database = acDoc.Database
  6.         Dim acEditor As Editor = acDoc.Editor
  7.         Dim acTypValAr(0) As TypedValue
  8.         acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT,ATTDEF"), 0) '过滤参照块和属性
  9.         Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
  10.         Dim acSSPrompt As PromptSelectionResult = acEditor.GetSelection(acSelFtr)
  11.         If acSSPrompt.Status <> PromptStatus.OK Then
  12.             Exit Sub
  13.         End If
  14.         Dim acSSet As SelectionSet = acSSPrompt.Value
  15.         Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
  16.             For Each OBJ As Object In acSSet
  17.                 Dim E As Entity = acTrans.GetObject(OBJ.ObjectId, OpenMode.ForWrite)
  18.                 If E.GetRXClass.DxfName = "INSERT" Then
  19.                     Dim BRef As BlockReference = CType(E, BlockReference)
  20.                     Dim AttCollection As AttributeCollection
  21.                     AttCollection = BRef.AttributeCollection
  22.                     If AttCollection.Count < 1 Then
  23.                         BRef.ExplodeToOwnerSpace()
  24.                         BRef.Erase()
  25.                     Else
  26.                         'Dim AttRef As AttributeReference
  27.                         'For I As Int16 = 0 To AttCollection.Count - 1
  28.                         '    AttRef = acTrans.GetObject(AttCollection(I), OpenMode.ForRead, False)
  29.                         '    If AttRef.IsMTextAttribute = False Then
  30.                         '        Dim DBT As DBText = New DBText()
  31.                         '        DBT.Rotation = AttRef.Rotation
  32.                         '        DBT.TextString = AttRef.TextString
  33.                         '        DBT.WidthFactor = AttRef.WidthFactor
  34.                         '        DBT.Height = AttRef.Height
  35.                         '        DBT.TextStyleId = AttRef.TextStyleId
  36.                         '        DBT.LayerId = AttRef.LayerId
  37.                         '        DBT.LinetypeId = AttRef.LinetypeId
  38.                         '        DBT.Position = AttRef.Position
  39.                         '        AddEnt(DBT)
  40.                         '    Else
  41.                         '        Dim DBT As MText = AttRef.MTextAttribute
  42.                         '        AddEnt(DBT)
  43.                         '    End If
  44.                         'Next
  45.                         '以下方法分解后AttDef可能缺失
  46.                         Dim DBC As DBObjectCollection = New DBObjectCollection
  47.                         'BRef.ExplodeToOwnerSpace()
  48.                         BRef.Explode(DBC)
  49.                         Dim N As Long = 0
  50.                         For Each dbObj As DBObject In DBC
  51.                             Dim acEnt As Entity = dbObj
  52.                             If acEnt.GetRXClass().DxfName.ToUpper = "ATTDEF" Then
  53.                                 Dim DBT As DBText = New DBText()
  54.                                 Dim AttRef As AttributeReference
  55.                                 AttRef = acTrans.GetObject(AttCollection(N), OpenMode.ForWrite, False)
  56.                                 DBT.Rotation = AttRef.Rotation
  57.                                 DBT.TextString = AttRef.TextString
  58.                                 DBT.WidthFactor = AttRef.WidthFactor
  59.                                 DBT.Height = AttRef.Height
  60.                                 DBT.TextStyleId = AttRef.TextStyleId
  61.                                 DBT.LayerId = AttRef.LayerId
  62.                                 DBT.LinetypeId = AttRef.LinetypeId
  63.                                 DBT.Position = AttRef.Position
  64.                                 AddEnt(DBT)
  65.                                 N = N + 1
  66.                             Else
  67.                                 AddEnt(acEnt)
  68.                             End If
  69.                             'MsgBox("Exploded Object: " & acEnt.GetRXClass().DxfName)
  70.                         Next
  71.                         BRef.Erase()
  72.                     End If
  73.                 Else
  74.                     Dim DBT As DBText = New DBText()
  75.                     Dim AttRef As AttributeDefinition = CType(E, AttributeDefinition)
  76.                     DBT.Rotation = AttRef.Rotation
  77.                     DBT.TextString = AttRef.TextString
  78.                     DBT.WidthFactor = AttRef.WidthFactor
  79.                     DBT.Height = AttRef.Height
  80.                     DBT.TextStyleId = AttRef.TextStyleId
  81.                     DBT.LayerId = AttRef.LayerId
  82.                     DBT.LinetypeId = AttRef.LinetypeId
  83.                     DBT.Position = AttRef.Position
  84.                     AddEnt(DBT)
  85.                     E.Erase()
  86.                 End If
  87.             Next
  88.             acTrans.Commit()
  89.         End Using
  90.         If Err.Number > 0 Then
  91.             MsgBox(Err.Description)
  92.         End If
  93.     End Sub
发表于 2024-6-6 17:50 | 显示全部楼层
tiancao100 发表于 2024-6-6 11:08
BURST 是Express Tools中的, 仍然只能分解允许分解的,创建时不允许分解的他也爆不了, 也不能分解属性

可以使用(vla-put-explodable blk -1)来使块允许分解,然后再用BURST来进行分解
发表于 2024-6-6 18:15 | 显示全部楼层
OooCcc 发表于 2024-6-6 17:50
可以使用(vla-put-explodable blk -1)来使块允许分解,然后再用BURST来进行分解

net不用,能够读取就自己创建就好了
发表于 2024-6-4 17:20 | 显示全部楼层
事务为什么套在for里面
发表于 2024-6-4 17:30 | 显示全部楼层
et好像有炸属性块
发表于 2024-6-4 18:57 | 显示全部楼层
你有种再说一遍 发表于 2024-6-4 17:20
事务为什么套在for里面

有时候也有好处,
发表于 2024-6-4 19:28 | 显示全部楼层
tiancao100 发表于 2024-6-4 18:57
有时候也有好处,

请上声明式事务
 楼主| 发表于 2024-6-4 19:37 | 显示全部楼层

谢谢大老的回复。
发表于 2024-6-6 10:06 | 显示全部楼层
CAD自带命令 BURST 试试。可以分解属性块保留属性值。
发表于 2024-6-6 11:08 | 显示全部楼层
BURST 是Express Tools中的, 仍然只能分解允许分解的,创建时不允许分解的他也爆不了, 也不能分解属性
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-18 21:53 , Processed in 0.148367 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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