此代码不再适用于AutoCAD 2019。我的目标是框架4.7。托管.NET参考指南指定函数<pre>
- Database.ReadDwgFile(string, FileShare, [MarshalAs(UnmanagedType.U1)] bool, string) Method
已过时,将在未来版本中删除。调试时,它不会遍历BlockTableRecord中的对象ID?功能是否已被替换?我正在研究图形系统的变化…但任何输入都很好…
谢谢。
- Public Shared Sub UpdateAttributesInSideDatabase(ByVal FilePath As String, blockName As String, attbName As String, attbValue As String)
- Dim doc As Document = Application.DocumentManager.MdiActiveDocument
- Dim currentDb As Database = doc.Database
- Dim ed As Editor = doc.Editor
- Using targetDb As New Database(False, True)
- Try
- targetDb.ReadDwgFile(FilePath, System.IO.FileShare.ReadWrite, True, "")
- Using tr As Transaction = targetDb.TransactionManager.StartTransaction()
- Dim layoutDict As DBDictionary = tr.GetObject(targetDb.LayoutDictionaryId, OpenMode.ForRead)
- For Each dicEnt As DBDictionaryEntry In layoutDict
- Dim lay As Layout = DirectCast(dicEnt.Value.GetObject(OpenMode.ForRead), Layout)
- ''do your stuffs in every layout
- If lay.LayoutName "Model" Then
- Dim btr As BlockTableRecord = tr.GetObject(lay.BlockTableRecordId, OpenMode.ForRead)
- For Each id As ObjectId In btr
- If id.ObjectClass.DxfName = "INSERT" Then
- Dim br As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForRead), BlockReference)
- ' ... to see whether it's a block with
- ' the name we're after
- If br.Name.ToUpper() = blockName.ToUpper() Then
- For Each arId As ObjectId In br.AttributeCollection
- Dim ar As AttributeReference = DirectCast(tr.GetObject(arId, OpenMode.ForRead), AttributeReference)
- ' ... to see whether it has
- ' the tag we're after
- If ar.Tag.ToUpper() = attbName.ToUpper() Then
- ' If so, update the value
- ' and increment the counter
- ar.UpgradeOpen()
- ar.TextString = attbValue
- 'realign attributes after editing their values
- 'ar.AdjustAlignment(targetDb)
- 'ar.DowngradeOpen()
- End If
- Next
- End If
- End If
- Next
- End If
- Next
- 'end of code from template insert
- tr.Commit()
- End Using
- targetDb.SaveAs(FilePath, DwgVersion.Current)
- Catch ex As Autodesk.AutoCAD.Runtime.Exception
- ed.WriteMessage(vbLf & "Error while running > " + ex.Message)
- End Try
- End Using
- End Sub
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |