乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: Alex_AMF

[编程交流] 检索AutoCAD块记录

[复制链接]

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 22:52:49 | 显示全部楼层
 
http://www.cadtutor.net/forum/showthread.php?71118-ThisDrawing-Property-with-AutoCAD-2013
回复

使用道具 举报

2

主题

13

帖子

11

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 22:56:37 | 显示全部楼层
 
这不是也一样吗?
  1. Imports Autodesk.AutoCAD.Interop

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

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 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
回复

使用道具 举报

2

主题

13

帖子

11

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 23:02:50 | 显示全部楼层
Derp。谢谢你,哈哈,我会试试的。
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 23:05:40 | 显示全部楼层
 
别担心。。。。看看这个线程:VB。NET-从单机exe打开现有Dwg
 
... 比尔和我在CADTutor这里来回奔波了几周,在这一系列的小主题上,我们有很多相关的帖子,看看相关的帖子。
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 23:10:46 | 显示全部楼层
 
您好,Fixo,我现在知道您刚刚发布了一些示例代码,供OP使用(我删除了之前的帖子),但我确实想问一下ReadDwg。。。这是降级为插件,还是独立的EXE也可以使用ReadDwg?
 
另外,是否可以通过ReadDwg(即侧数据库)打印?
 
TIA
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:13:27 | 显示全部楼层
不,你们不能在side数据库中使用ReadDwdgFile,比如说,只使用API
例如,从多个文件中获取表格并写入csv
 
  1. Public Function GetDirectoryDrawings(directoryFullName As String, subDirsBrowse As Boolean) As List(Of FileInfo)
  2.            Dim dir As New DirectoryInfo(directoryFullName)
  3.            If Not dir.Exists Then
  4.                Throw New DirectoryNotFoundException()
  5.                Return Nothing
  6.            End If
  7.            Dim opt As SearchOption = SearchOption.AllDirectories
  8.            If subDirsBrowse = False Then opt = SearchOption.TopDirectoryOnly
  9.            Return dir.GetFiles("*dwg", opt).AsEnumerable().OrderBy(Function(x) x.FullName).ToList()
  10.        End Function
  11.        <CommandMethod("wtb", CommandFlags.Session)> _
  12.        Public Sub testDirFiles()
  13.            Dim folder As String = "C:\Test"
  14.            Dim csvfile As String = "C:\Test\atable.csv"
  15.            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  16.            Dim db As Database = doc.Database
  17.            Dim ed As Editor = doc.Editor
  18.            Dim fd As List(Of FileInfo) = GetDirectoryDrawings(folder, False) ''     True for processing the subdirectories
  19.            Dim collect As New StringBuilder
  20.            If fd.Count = 0 Then Return
  21.            Try
  22.                Using doclock As DocumentLock = doc.LockDocument()
  23.                    For n As Integer = 0 To fd.Count - 1
  24.                        Dim dwgname As String = fd(n).FullName
  25.                        Using newdb As Database = New Database(False, True)
  26.                            ed.WriteMessage(vbLf + dwgname + vbLf)
  27.                            Try
  28.                                newdb.ReadDwgFile(dwgname, FileOpenMode.OpenForReadAndAllShare, False, Nothing)
  29.                            Catch ex As Autodesk.AutoCAD.Runtime.Exception
  30.                                If ex.ErrorStatus = ErrorStatus.DwgNeedsRecovery Then
  31.                                    Continue For
  32.                                End If
  33.                            End Try
  34.                            Using newtr As Transaction = newdb.TransactionManager.StartTransaction
  35.                                ' Open dictionary for reading
  36.                                Dim layoutDict As DBDictionary = DirectCast(newtr.GetObject(newdb.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)
  37.                                ' Loop through dictionary entries
  38.                                For Each entry As DictionaryEntry In layoutDict
  39.                                    Dim ltr As Layout = DirectCast(newtr.GetObject(DirectCast(entry.Value, ObjectId), OpenMode.ForRead), Layout)
  40.                                    Dim btr As BlockTableRecord = DirectCast(newtr.GetObject(ltr.BlockTableRecordId, OpenMode.ForRead), BlockTableRecord)
  41.                                    For Each id As ObjectId In btr
  42.                                        Dim obj As DBObject = DirectCast(newtr.GetObject(id, OpenMode.ForRead), DBObject)
  43.                                        If TypeOf obj Is Table Then
  44.                                            Dim tbl As Table = TryCast(obj, Table)
  45.                                            If tbl IsNot Nothing Then
  46.                                                collect.AppendLine(String.Format("---------------------------------------"))
  47.                                                collect.AppendLine(String.Format("Drawing name: {0}", dwgname))
  48.                                                collect.AppendLine(String.Format("Tab: {0}", ltr.LayoutName))
  49.                                                Dim numrows As Integer = tbl.Rows.Count
  50.                                                Dim numcols As Integer = tbl.Columns.Count
  51.                                                For i As Integer = 0 To numrows - 1
  52.                                                    Dim rowline As New List(Of String)
  53.                                                    Dim line As String = String.Empty
  54.                                                    For j = 0 To numcols - 1
  55.                                                        Dim cel As Cell = tbl.Cells(i, j)
  56.                                                        rowline.Add(cel.TextString)
  57.                                                        line = line + cel.TextString + vbTab
  58.                                                    Next
  59.                                                    collect.AppendLine(line.TrimEnd(vbTab))
  60.                                                Next
  61.                                            End If
  62.                                        End If
  63.                                    Next
  64.                                Next
  65.                                newtr.Commit()
  66.                            End Using
  67.                        End Using
  68.                    Next
  69.                End Using
  70.                WriteTableToFile(csvfile, collect)
  71.            Catch ex As System.Exception
  72.                ed.WriteMessage(vbLf + ex.ToString + vbLf)
  73.            Finally
  74.                ed.WriteMessage(vbLf + vbTab + "--->   File saved as: {0}   <---" + vbLf, csvfile)
  75.            End Try
  76.        End Sub
  77.        Public Sub WriteTableToFile(fpath As String, data As StringBuilder)
  78.            'If Not (File.Exists(fpath)) Then
  79.            '    Using frs As New FileStream(fpath, FileMode.Create)
  80.            '        frs.Flush()
  81.            '    End Using
  82.            'End If
  83.            Using fs As New FileStream(fpath, FileMode.Append, FileAccess.Write)
  84.                Using sw As New StreamWriter(fs, Encoding.ASCII)
  85.                    sw.WriteLine(data.ToString)
  86.                End Using
  87.            End Using
  88.        End Sub

电子不停车收费系统
回复

使用道具 举报

2

主题

13

帖子

11

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 23:15:17 | 显示全部楼层
 
这是我最初的举动,我也认为它会奏效。奇怪的是,它仍然告诉我它是模糊的
232032wb0us6n80pk23mut.png
232033wyfarzwgfowaaatc.png
232035mk7xai0mdr948789.png
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:19:51 | 显示全部楼层
回复

使用道具 举报

2

主题

13

帖子

11

银币

初来乍到

Rank: 1

铜币
10
发表于 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
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 11:20 , Processed in 0.340158 second(s), 73 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表