Results 1 to 6 of 6

Thread: Another GetObject problem

  1. #1
    Member
    Join Date
    2000-12
    Posts
    8
    Login to Give a bone
    0

    Default Another GetObject problem

    I am using Windows7 Home Premium. ie 64bit.
    The following is what I believe is standard code. I have simplified it, and it has worked in the recent past. Now App returns nothing if AutoCad is loaded. And fails on GetObject with can't create ActiveX etc

    Code:
    Imports Autodesk.AutoCAD.Interop
    Public Class AcadClass
       Private App As AcadApplication
       Private AppReg As String
       Public Sub New(ByVal ver As String)      ' ver is read from Windows Registry
          If ver.StartsWith("R") Then ver = ver.Substring(1)
          AppReg = "Autocad.Application." & ver
          Try
             App = GetObject(, AppReg)
          Catch ex As Exception
             Try
                App = CreateObject(AppReg)
             Catch ex1 As Exception
                Threading.Thread.Sleep(1000)
                App = GetObject(, AppReg)
             End Try
          End Try
       End Sub
    End Class
    The second try is intended to give AutoCad a chance to load and register itself.

    It is galling because it used to work. And now I am worried that their is going to be a problem on other machines.
    Last edited by Ed Jobe; 2011-05-02 at 04:17 PM. Reason: Added code tags.

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Another GetObject problem

    You need to do the proper debugging. Step through the code and see where it is failing. What if your reg reading function fails? Then you will be passing an empty string? Then sub New() will execute GetObject(, "").
    C:> ED WORKING....


    LinkedIn

  3. #3
    Member
    Join Date
    2000-12
    Posts
    8
    Login to Give a bone
    0

    Default Re: Another GetObject problem

    It fails at every Try.
    It also fails to find Autocad if loaded.

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Another GetObject problem

    Quote Originally Posted by smn View Post
    It fails at every Try.
    It also fails to find Autocad if loaded.
    The question you should be asking is "why?". You need to examine variable states at each step to figure that out. What was the value of your variables at each point? Was ver = ""?

    A Try..Catch is like an If statement. Try to do something and If there's no error, move on. If the Try is failing, examine the exception for details as to why it failed. You can examin ex1 in the ide or simply echo its description to the user. To do that, pop a MessageBox or use acad's prompt.
    Last edited by Ed Jobe; 2011-05-03 at 03:11 PM.
    C:> ED WORKING....


    LinkedIn

  5. #5
    Member
    Join Date
    2000-12
    Posts
    8
    Login to Give a bone
    0

    Default Re: Another GetObject problem

    Sorry Ed, but I do step through the code. (using F 8 )
    ver is the correct number. I've checked this a number of times.
    I have tried using GetObject(",Autocad.application") also.

  6. #6
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Another GetObject problem

    The var status is only part of it. I also mentioned finding out what the exceptions are. Your code doesn't do anything to show what the exception is. Working this way, you are assuming that there will always only be one possible cause that creates an exception. In the case of the first Try..Catch, you are assuming that the only possible exception is that acad is not running. Therefore, you don't examine ex1 in the Catch block and just attempt to create a new instance of acad. Normally, this would probably work, but apparently you have an abnormal condition.

    "Catch ex1 as Exception" generates an Exception object, but you haven't done anything with ex1. e.g. MessageBox = ex1.Message. Also, it helps to make use of more specific Exception objects. They provide additional features and more specific information. e.g. "Catch ex1 as Autodesk.AutoCAD.Runtime.Exception". You can also break in the Catch block and use the Locals window to examine ex1.

    Without information, there's nothing you or I can use to troubleshoot.
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. Replies: 3
    Last Post: 2012-12-10, 01:51 PM
  2. API question: GetObject() to link to a running Robot instance
    By bauskas in forum Robot Structural Analysis
    Replies: 12
    Last Post: 2012-03-06, 09:39 AM
  3. getObject for NavisWorks
    By gregor.vilkner in forum VBA/COM Interop
    Replies: 0
    Last Post: 2010-05-17, 06:22 PM
  4. GetObject AutoCAD Application
    By sthedens in forum VBA/COM Interop
    Replies: 8
    Last Post: 2006-09-21, 02:52 PM
  5. GetObject
    By rad.77676 in forum VBA/COM Interop
    Replies: 24
    Last Post: 2005-01-14, 10:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •