Musashi84 Posted February 12 Posted February 12 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! Quote
CyberAngel Posted February 28 Posted February 28 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! 1 Quote
Musashi84 Posted April 5 Author Posted April 5 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. Quote
Danielm103 Posted April 5 Posted April 5 (edited) I don’t see in the API where Documents takes an int argument Possibly Documents. Item(index) https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-2C8C8291-16C9-4A9F-8399-58D5DE4B9589 Edited April 5 by Danielm103 Quote
Recommended Posts
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.