metaldan 发表于 2022-7-6 22:37:36

vb。属性的net列表

嗨,我开始学vb了。net for autocad。我必须全部打开。DWG文件,并列出所有块名称和以“bom”作为名称的块的块属性。
 
 
当我尝试获取块引用时,代码停止。
 
我的sub是从表单按钮调用的
 
有人能帮我吗。
 
 



PrivateSub traitement2(ByVal CIBLE AsString)

Dim fichiersTrouv = Directory.GetFiles(T_CIBLE.Text, "*.dwg", SearchOption.AllDirectories)
ForEach ligneF In fichiersTrouv
Debug.Print(ligneF)
Dim myDB AsNew Database(False, True)
myDB.ReadDwgFile(ligneF, IO.FileShare.ReadWrite, True, "")
Using myTrans As Transaction = myDB.TransactionManager.StartTransaction
Dim MYBT As BlockTable = myDB.BlockTableId.GetObject(OpenMode.ForRead)
ForEach mybtrid As ObjectId In MYBT
Dim MYBTR As BlockTableRecord = mybtrid.GetObject(OpenMode.ForRead)
Debug.WriteLine(MYBTR.Name)
If MYBTR.Name = "bom"Then
Using MYTRANS2 As Transaction = mybtrid.Database.TransactionManager.StartTransaction
' program stop on next line autocad fatal error : Unhandled e0434f4dh exception at 7c812afdh
Dim MYBREF As BlockReference = mybtrid.GetObject(OpenMode.ForRead)
Dim MYATTCOLLECTION As AttributeCollection = MYBREF.AttributeCollection
ForEach MYATTREFID AsObjectIn MYATTCOLLECTION
Dim myAttRef As AttributeReference = MYATTREFID.GetObject(OpenMode.ForWrite)
Debug.WriteLine(MYBTR.Name & " - " & myAttRef.Tag & " - " & myAttRef.TextString)
Next
EndUsing
EndIf
Next
EndUsing
myDB.Dispose()
Next
EndSub


BlackBox 发表于 2022-7-6 22:59:15

首先。。。
 
CIBLE=/=T\u CIBLE
 
我也会使用
 
If MYBTR.Name.ToLower = "bom" Then
 
:眨眼:

metaldan 发表于 2022-7-6 23:24:52

谢谢你的帮助,但这不是我想要的解决方案吗
 
我找到了解决问题的方法
 
这是我的工作代码
 

Dim myDWG As Document = Application.DocumentManager.MdiActiveDocument
Dim myDB As New Database(False, True)
myDB = myDWG.Database
Using mytrans As Transaction = myDB.TransactionManager.StartTransaction
For Each myBlockName As String In GetTopLevelBlocks(myDB)
For Each BRefID As ObjectId In GetBRefIDs(myDB, myBlockName)
If myBlockName = "DANCART" Then
Dim MYATTVALS As New Dictionary(Of String, String)
MYATTVALS.Add("PROJET", "A")
MYATTVALS.Add("CLIENT1", "B")
MYATTVALS.Add("CLIENT2", "C")
MYATTVALS.Add("DESSINATEUR", "D")
MYATTVALS.Add("DATE", "E")
MYATTVALS.Add("DESSIN", "F")
Using myTrans2 As Transaction = BRefID.Database.TransactionManager.StartTransaction
Dim myBRef As BlockReference = BRefID.GetObject(OpenMode.ForRead)
Dim myAttCollection As AttributeCollection = myBRef.AttributeCollection
For Each myAttRefID As ObjectId In myAttCollection
Dim myAttRef As AttributeReference = myAttRefID.GetObject(OpenMode.ForWrite)
If MYATTVALS.ContainsKey(myAttRef.Tag) Then
myAttRef.TextString = MYATTVALS(myAttRef.Tag)
End If
Next
myTrans2.Commit()
End Using

End If
Next
Next
mytrans.Commit()
End Using
[/尺寸]

shirazbj 发表于 2022-7-6 23:48:07

为什么我在说“GetTopLevelBlocks未定义”时出错。
页: [1]
查看完整版本: vb。属性的net列表