BlackBox 发表于 2022-7-6 22:52:49

 
http://www.cadtutor.net/forum/showthread.php?71118-ThisDrawing-Property-with-AutoCAD-2013

Alex_AMF 发表于 2022-7-6 22:56:37

 
这不是也一样吗?
Imports Autodesk.AutoCAD.Interop
 
我试着导入你说的内容(不过我有ObjectARX 2010…)它说名称空间不明确。可能是因为我以前已经有了那个代码?它只在我导入Autodesk时出错。AutoCAD。互操作。dll

BlackBox 发表于 2022-7-6 23:00:47

 
必须添加互操作程序集作为对解决方案的引用,只有这样,您的Imports语句(在C#中使用)才会成功。
 
 
 
您可能会发现其他有用信息:http://forums.autodesk.com/t5/NET/how-to-access-AutoCAD-2012-from-Vb-net-Standard-Exe/td-p/3363237

Alex_AMF 发表于 2022-7-6 23:02:50

Derp。谢谢你,哈哈,我会试试的。

BlackBox 发表于 2022-7-6 23:05:40

 
别担心。。。。看看这个线程:VB。NET-从单机exe打开现有Dwg
 
... 比尔和我在CADTutor这里来回奔波了几周,在这一系列的小主题上,我们有很多相关的帖子,看看相关的帖子。

BlackBox 发表于 2022-7-6 23:10:46

 
您好,Fixo,我现在知道您刚刚发布了一些示例代码,供OP使用(我删除了之前的帖子),但我确实想问一下ReadDwg。。。这是降级为插件,还是独立的EXE也可以使用ReadDwg?
 
另外,是否可以通过ReadDwg(即侧数据库)打印?
 
TIA

fixo 发表于 2022-7-6 23:13:27

不,你们不能在side数据库中使用ReadDwdgFile,比如说,只使用API
例如,从多个文件中获取表格并写入csv
 

Public Function GetDirectoryDrawings(directoryFullName As String, subDirsBrowse As Boolean) As List(Of FileInfo)
         Dim dir As New DirectoryInfo(directoryFullName)
         If Not dir.Exists Then
               Throw New DirectoryNotFoundException()
               Return Nothing
         End If
         Dim opt As SearchOption = SearchOption.AllDirectories
         If subDirsBrowse = False Then opt = SearchOption.TopDirectoryOnly
         Return dir.GetFiles("*dwg", opt).AsEnumerable().OrderBy(Function(x) x.FullName).ToList()
       End Function

       <CommandMethod("wtb", CommandFlags.Session)> _
       Public Sub testDirFiles()
         Dim folder As String = "C:\Test\"
         Dim csvfile As String = "C:\Test\atable.csv"
         Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
         Dim db As Database = doc.Database
         Dim ed As Editor = doc.Editor
         Dim fd As List(Of FileInfo) = GetDirectoryDrawings(folder, False) ''   True for processing the subdirectories
         Dim collect As New StringBuilder
         If fd.Count = 0 Then Return

         Try
               Using doclock As DocumentLock = doc.LockDocument()
                   For n As Integer = 0 To fd.Count - 1
                     Dim dwgname As String = fd(n).FullName
                     Using newdb As Database = New Database(False, True)
                           ed.WriteMessage(vbLf + dwgname + vbLf)
                           Try
                               newdb.ReadDwgFile(dwgname, FileOpenMode.OpenForReadAndAllShare, False, Nothing)
                           Catch ex As Autodesk.AutoCAD.Runtime.Exception
                               If ex.ErrorStatus = ErrorStatus.DwgNeedsRecovery Then
                                 Continue For
                               End If
                           End Try

                           Using newtr As Transaction = newdb.TransactionManager.StartTransaction
                               ' Open dictionary for reading
                               Dim layoutDict As DBDictionary = DirectCast(newtr.GetObject(newdb.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)
                               ' Loop through dictionary entries
                               For Each entry As DictionaryEntry In layoutDict
                                 Dim ltr As Layout = DirectCast(newtr.GetObject(DirectCast(entry.Value, ObjectId), OpenMode.ForRead), Layout)
                                 Dim btr As BlockTableRecord = DirectCast(newtr.GetObject(ltr.BlockTableRecordId, OpenMode.ForRead), BlockTableRecord)
                                 For Each id As ObjectId In btr
                                       Dim obj As DBObject = DirectCast(newtr.GetObject(id, OpenMode.ForRead), DBObject)
                                       If TypeOf obj Is Table Then
                                           Dim tbl As Table = TryCast(obj, Table)
                                           If tbl IsNot Nothing Then
                                             collect.AppendLine(String.Format("---------------------------------------"))
                                             collect.AppendLine(String.Format("Drawing name: {0}", dwgname))
                                             collect.AppendLine(String.Format("Tab: {0}", ltr.LayoutName))
                                             Dim numrows As Integer = tbl.Rows.Count
                                             Dim numcols As Integer = tbl.Columns.Count
                                             For i As Integer = 0 To numrows - 1
                                                   Dim rowline As New List(Of String)
                                                   Dim line As String = String.Empty
                                                   For j = 0 To numcols - 1
                                                       Dim cel As Cell = tbl.Cells(i, j)
                                                       rowline.Add(cel.TextString)
                                                       line = line + cel.TextString + vbTab
                                                   Next
                                                   collect.AppendLine(line.TrimEnd(vbTab))
                                             Next
                                           End If
                                       End If
                                 Next
                               Next
                               newtr.Commit()
                           End Using
                     End Using
                   Next
               End Using
               WriteTableToFile(csvfile, collect)
         Catch ex As System.Exception
               ed.WriteMessage(vbLf + ex.ToString + vbLf)
         Finally
               ed.WriteMessage(vbLf + vbTab + "--->   File saved as: {0}   <---" + vbLf, csvfile)
         End Try
       End Sub

       Public Sub WriteTableToFile(fpath As String, data As StringBuilder)
         'If Not (File.Exists(fpath)) Then
         '    Using frs As New FileStream(fpath, FileMode.Create)
         '      frs.Flush()
         '    End Using
         'End If
         Using fs As New FileStream(fpath, FileMode.Append, FileAccess.Write)
               Using sw As New StreamWriter(fs, Encoding.ASCII)
                   sw.WriteLine(data.ToString)
               End Using
         End Using
       End Sub

电子不停车收费系统

Alex_AMF 发表于 2022-7-6 23:15:17

 
这是我最初的举动,我也认为它会奏效。奇怪的是,它仍然告诉我它是模糊的

fixo 发表于 2022-7-6 23:19:51

Alex_AMF 发表于 2022-7-6 23:22:14

 
That was my initial move and I also thought it was going to work. Oddly enough, it still tells me it is ambiguous
页: 1 [2]
查看完整版本: 检索AutoCAD块记录