eNotFromThisDocument

eNotFromThisDocument

我用下面的代码可以从dwg文件导入一个标注样式
但是换成LineType,却不能导入一个线型,出现错误“eNotFromThisDocument”
程序代码:

从外部文件导入一个文字样式
    <CommandMethod("AddDimStyleFromDWG")> _
    Public Sub AddDimStyleFromDWG()
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Dim Ex As Autodesk.AutoCAD.Runtime.Exception
        Try
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                Dim acDimStyleTbl As DimStyleTable
                Dim acDimStyleTblRecCopy As DimStyleTableRecord
                acDimStyleTbl = acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForWrite)
                If acDimStyleTbl.Has("TcDim100") = False Then '如果当前文档中还不存在该标注样式
                    Dim FileName As String = My.Application.Info.DirectoryPath & "\support\DimStyle.Dwg"
                    '创建一个新的Database,作为Database,以读入外部dwg文件中的对象
                    Dim Dwg_Db As Database = New Database(False, True)
                    Dwg_Db.ReadDwgFile(FileName, System.IO.FileShare.Read, True, "")
                    Using DWG_acTrans As Transaction = Dwg_Db.TransactionManager.StartTransaction()
                        Dim DWG_acDimStyleTbl As DimStyleTable
                        DWG_acDimStyleTbl = DWG_acTrans.GetObject(Dwg_Db.DimStyleTableId, OpenMode.ForRead)
                        acDimStyleTblRecCopy = DWG_acTrans.GetObject(DWG_acDimStyleTbl("Dim100"), OpenMode.ForRead)
                        DWG_acTrans.Dispose()
                    End Using
                    acDoc.Editor.WriteMessage(vbLf & acDimStyleTblRecCopy.Name)
                    Dim acDimStyleTblRec As DimStyleTableRecord = New DimStyleTableRecord
                    acDimStyleTblRec = acDimStyleTblRecCopy.Clone
                    acDimStyleTbl.Add(acDimStyleTblRec)
                    acTrans.AddNewlyCreatedDBObject(acDimStyleTblRec, True)
                    acDoc.Editor.WriteMessage(vbLf & "标注样式:TcDim100添加成功")
                End If
                acTrans.Commit()
            End Using
        Catch Ex
            acDoc.Editor.WriteMessage(vbLf & "标注样式加载出错: " + Ex.Message)
        End Try
    End Sub






Please follow WeChat's public account ByCAD