如果未安装AutoCAD或不希望运行AutoCAD,则需要RealDWG。
要获得更好的解决方案,请查看数据库。GetHostDwgXrefGraph,从中可以获取嵌套的外部参照
这是一个简单示例的硬编码,只是为了让您开始
两个图形都在“C\Test”中
外部参照图形。dwg和XrefHost。图纸
XrefHost已将XrefDrawing xref放入并将其移动到另一个文件夹
--数据库。ReadDwgFile,用于打开未在编辑器中与之交互的图形
--迭代块表,检查块表记录。IsFromExternalReference属性
--更改路径名属性并移动文件
- <CommandMethod("ChangeXrefPath")> _
- Public Sub ChangeXrefPath()
- Using db As New Database(False, True)
- Try
- db.ReadDwgFile("C:\Test\XrefHost.dwg", FileOpenMode.OpenForReadAndWriteNoShare, True, Nothing)
- Using trx As Transaction = db.TransactionManager.StartTransaction()
- Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead)
- For Each objId As ObjectId In bt
- Dim btr As BlockTableRecord = trx.GetObject(objId, OpenMode.ForRead)
- If btr.IsFromExternalReference Then
- btr.UpgradeOpen()
- btr.PathName = "C:\Test\NewLocation\XrefDrawing.dwg"
- Exit For
- End If
- Next
- trx.Commit()
- End Using
- db.SaveAs(db.Filename, True, DwgVersion.Current, db.SecurityParameters)
- Catch
- End Try
- End Using
- System.IO.File.Move("C:\Test\XrefDrawing.dwg", "C:\Test\NewLocation\XrefDrawing.dwg")
- End Sub
- End Class
|