检索AutoCAD块记录
你好我的目标是在所有AutoCAD图形上设置批打印。每张图纸将有一个类似的记录:
红色下划线的PartNo记录是递归函数将要处理的其他图形。这就是为什么我必须访问这些信息。我相信我必须访问一个名为“BLOCKNT”的对象才能这样做,但我不确定语法。
仅供参考,出于某种原因,每当我尝试使用此代码时:
ApplicationServices.Application.DocumentManager.MdiActiveDocument
我得到以下错误:
这是一个。exe应用程序,我已经阅读,我不能使用NETLOAD命令在一个。exe项目?这有意义吗?
非常感谢。
亚历克斯 现在,如果您使用的是独立的EXE,那么您应该通过COM访问AutoCAD,而不是。NET API。
http://through-the-interface.typepad.com/through_the_interface/2010/02/handling-com-calls-rejected-by-autocad-from-an-external-net-application.html
另外,很难说清楚,因为你没有发布你的呼叫代码,但似乎是你的系统。IO。FileNotFoundException是试图将MdiActiveDocument对象传递给系统的结果。IO。文件Exists()方法调用(或类似调用),此时您需要提供限定的文件路径和文件名。 我懂了。。。我认为我一直在使用的AutoCAD文档是为了。NET API。至于调用代码本身,它看起来是这样的:
Private Sub ACAD()
'The application crashes here and I receive the error posted above.
GetBlockContents()
End Sub
Private Sub GetBlockContents()
Dim test = Application.DocumentManager.MdiActiveDocument
End Sub
从这里开始:我的第一次插件培训
不管你是否擅长。NET开发,或者如果这是您第一次尝试两者兼而有之,则需要更好地理解。NET和COM API,然后您的努力就会成功。
**注意-Autodesk的。NET文档假设对有基本了解。NET开发概念。 非常感谢。我会调查的。说到这点,我相当得体。NET开发。不过,在AutoCAD概念中还是很新的。我以前做过一些SolidEdge,但现在我正在扩展。
再次感谢!
别担心;我们都从某个地方开始。。。我想你的前任。NET开发经验很快就会派上用场。您只需要熟悉API对象的属性、方法和事件。 通过这些教程,我学到了很多东西。我还查看了该网站http://through-the-interface.typepad.com/它有大量的信息。
我仍然对如何从图形中检索块记录感到困惑。我并不是在创建一个插件,它是。NET API已加载到我的项目中,即使我只能通过COM与AutoCAD通信。我不确定这些参考文献是哪一个。NET,因为我认为我只从COM选项卡中获取了它们:
AcDbMgd
AcMgd公司
AutoCAD
AXDBLib
无论如何,我会努力进一步推进我的项目。我一拿到答案就贴出来。 作为快速示例,尝试打开多个图形进行阅读,
最好看看数据库。ReadDwg方法
代码:
<CommandMethod("bah")> _
Public Shared Sub BatchStart()
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("SDI", 0)
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
' Get drawings to process
Dim dwgsForm As New Autodesk.AutoCAD.Windows.OpenFileDialog("Drawings to Process", "", "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple)
If dwgsForm.ShowDialog() <> Windows.Forms.DialogResult.OK Then
Return
End If
Dim dwgfiles As String() = dwgsForm.GetFilenames()
Using doclock As DocumentLock = doc.LockDocument()
For i As Integer = 0 To dwgfiles.GetLength(0) - 1
Dim newdoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(dwgfiles(i), False)
'your rest code to retrieve desired things from opened document here
'__________________________________________________'
ed.WriteMessage(vbLf & dwgfiles(i).ToString())
' close doc without changes
newdoc.CloseAndDiscard()
Next
End Using
End Sub
您需要为应用程序的目标处理环境添加对互操作程序集的引用。。。例如,这些互操作程序集可以分别在32位或64位的ObjectARX 2014 SDK中找到:
C:\Autodesk\ObjectARX 2014\inc-win32\Autodesk.AutoCAD.Interop.dll
C:\Autodesk\ObjectARX 2014\inc-x64\Autodesk.AutoCAD.Interop.dll
你好,菲索,
我看到你发了很多关于AutoCAD的帖子。很高兴你来帮我!非常感谢。在任何情况下,每次我似乎在文档管理器中包含“MdiActiveDocument”部分时,我的。exe程序崩溃并出现以下错误:
再次感谢
页:
[1]
2