有关加载Autocad的更多信息 [英] More on loading Autocad

查看:131
本文介绍了有关加载Autocad的更多信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从程序中加载AutoCad.代码是:

I am trying to load AutoCad from my programe. The code is:

Private Sub LoadAcad(ByVal fn As String)
      Dim acadApp As AcadApplication
      Dim acadDoc As AcadDocument
      Dim ProgId As String = "AutoCAD.Application"
      Try
         acadApp = GetObject(, ProgId)
         With acadApp
            .Visible = True
            acadDoc = .Documents.Open(fn, False)
          End With


我收到未加载AutoCad的错误,因此我将其加载


I catch the error that AutoCad is not loaded so I load it

Catch ex1 As Exception
   Try
      acadApp = CreateObject(ProgId)
      With acadApp
         .Visible = True
         acadDoc = .Documents.Open(fn, False)
      End With


此时已加载AutoCad,因为在它消失之前我已经看到了一点,并且它在Windows任务管理器中已存在,但是我不知道是否已加载图形"fn".然后,它引发异常无法创建ActiveX组件."
这就是为什么我捕获了第二个错误.


At this point AutoCad is loaded because I see a bit of it before it disappears, and it is there in the Windows Task Manager, but I don''t know whether drawing "fn" was loaded. It then raises the exception "Cannot create ActiveX component."
Which is why I have captured the second error.

      Catch ex2 As Exception
         MsgBox(ex2.Message & vbCrLf & "Try Again")
      End Try
   End Try
End Sub



现在,如果我再次执行此代码(从表单的按钮),则它可以工作.除"fn"外,它始终是只读加载的.我刚刚检查了它的属性,并且报告它是正常的.



Now if I then execute this code again (from the form''s button) it works. Except "fn" is always loaded read-only. I have checked it''s attribues just before and it reports that it is Normal.

Any ideas?

推荐答案

在我看来,第一次尝试会锁定文件,因此第二次尝试无法正常打开它(因此默认为只读模式).您在这里做错了.您是否在这里浏览了他们的文档:

http://docs.autodesk.com/ACD/2011/ESP/filesMDG/WS1a9193826455f5ff2566ffd511ff6f8f 43ef.htm [ ^ ]
It seems to me that the first attempt locks the file, so the 2nd attempt cannot open it normally (and thus defaults to readonly mode). You are doing something wrong here. Have you gone through their documentation here:

http://docs.autodesk.com/ACD/2011/ESP/filesMDG/WS1a9193826455f5ff2566ffd511ff6f8c7ca-43ef.htm[^]


您可以尝试使用 GetRunningObjectTable [ ^ ]以获得 IRunningObjectTable [ IRunningObjectTable [
You may try using GetRunningObjectTable[^] to get IRunningObjectTable[^] and see if you are able to get access to the running instance of AutoCad.

.Net version of IRunningObjectTable[^]

It might be worth a try :)

Regards
Espen Harlinn


我认为答案是,在CreateObject语句之后制作对象需要花费一些时间.
因此,我创建了一个计时器,并在此语句后立即启动它.

在计时器事件中,我使用GetObject返回Autocad对象,它似乎可以正常工作.

但是无论我做什么,图形始终以只读方式打开.
I think the answer is that it takes a little time for the object to be made after the CreateObject statement.
So I created a timer and started it immediately after this statement.

In the timer event I use GetObject to return the Autocad object and it seems to work.

But whatever I do, the drawing is always opened as read-only.


这篇关于有关加载Autocad的更多信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆