Jump to content

Recommended Posts

Posted

So I have a VBA sub that assigns a variable to a drawing directly by its name. Trying to do the same thing in VB.NET however, it goes to an error like "Conversion from string to type Integer is not valid". Here is the code in vb.net, I have a opened autocad file named "Drawing3.dwg") and the error comes up in the last row.

 

        Dim acad As AcadApplication

        Dim drwg As AcadDocument

        acad = GetObject(, "AutoCAD.Application")
        drwg = acad.Documents("Drawing3.dwg")

 

If I use this instead, it goes trough with no issues:

 

        drwg = acad.Documents(0)

 

Now, in VBA you could either put an integer or a string with the name of the drawing in the parenthesis and it would work, in VB.NET only works with integer it looks like. I was wondering if there is another way around it without having to loop through all opened drawings and have it check the names.

 

Thanks a lot!

 

 

  • 3 weeks later...
Posted

See this post on the Autodesk .NET forums. If I'm reading it correctly, in .NET you can use COM, which uses either early binding or late binding. I guess you've inadvertently used early binding.

 

Here's another article that uses API instead of COM. You may want to go that route if you haven't gotten locked into COM.

 

If none of that helps, give us more information about your issue.

 

Welcome to the forum!

  • Like 1
  • 1 month later...
Posted

Hey CyberAngel, thanks for the response, im sorry to get back to it only now. I was able to solve this issue with late binding, like the following code:

 

        Dim acad As Object

        Dim drwg As AcadDocument

        acad = GetObject(, "AutoCAD.Application")
        drwg = acad.Documents("Drawing3.dwg")

 

I am using COM references (assemblies), this stand alone app does AutoCAD, Excel and Word stuff all in the same code.

 

I read that early binding is better for runtime performance in general, so im only using late binding for declaration of 'acad' and not for the rest of the variables. Should I use it in all of the variables or only the ones that give me this exception? Im guessing that this issue is related to AutoCAD only, since Excel and Word did not give me any trouble.

 

 

Thanks a lot.

 

 

 

 

 

 

 

 

 

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...