GetObject Function Fails

GetObject Function Fails

3DAli
Collaborator Collaborator
937 Views
14 Replies
Message 1 of 15

GetObject Function Fails

3DAli
Collaborator
Collaborator

Hi, 

 

I am trying to run the following code using Visual Studio 19, and Inventor pro 2022, Windows 10 and it wont run. I am new to VB but I have lots of experience with VBA. I have followed the instruction line by  line form this link https://www.autodesk.com/autodesk-university/class/Creating-Add-Ins-Inventor-2018#video

and I can't get it to work, I also tried the method below and still same error

 

System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

 

can someone help please?

 

Regards

Ali

 

3DAli_0-1636755285320.png

 

 

 

0 Likes
Accepted solutions (1)
938 Views
14 Replies
Replies (14)
Message 2 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

Why are you posting the exact same question with two user accounts at the same time?

 

What are you trying to do? Is this an Addin dll created with the Inventor .Net Addin template or a standalone exe?


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 15

3DAli
Collaborator
Collaborator

Thanks for your response , 

I notice that I had accidentally posted this using my work account, and I rather to keep it separate , thats why I posted it again using my personal account and then I couldn't figure out how to delete the first one, so I guess its not possible to remove a post.

I am trying to learn how to use VB to convert my VBA macros into Add ins and I use the training in the link to follow the step by step guideline, so this particular one is standalone EXE, and my settings is nothing different than what is shown in the training course. The code is correct, however windows fails to call the Inventor Application object and I did some research and I cant seem to find how to fix it. Any ideas would be greatly appreciated.

 

Best,

Ali

0 Likes
Message 4 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

Thanks for your explanation.

I can't watch the video cause of limitations of my current internet access. The handout describes the creation of an Addin dll.

Anyway, GetObject normally get's a running instance of Inventor. If it is not guaranteed that Inventor is running, then you should try to create one using this:

Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOk.Click
        Dim invApp As Inventor.Application = Nothing

        Try
            Try
                invApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
            Catch ex As Exception
            End Try

            If invApp Is Nothing Then
                Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
                invApp = System.Activator.CreateInstance(inventorAppType)
            End If

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show("There was a problem starting Inventor.", "Error", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)

        End Try
    End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 5 of 15

3DAli
Collaborator
Collaborator

Thank you, I will test it out and let you know for sure 

0 Likes
Message 6 of 15

3DAli
Collaborator
Collaborator

I tried the code you suggested and it gave the error message as you set , so obviously there is an issue with getting Inventor application 

0 Likes
Message 7 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

First of all, Inventor is installed on the Computer you try to run your program?

Can you try to start Inventor manually As Administrator and check if that helps?

Is it possible to zip the whole project folder of your application and post it?

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 8 of 15

3DAli
Collaborator
Collaborator

Hi

 

Yes, inventor is installed and as per instruction in the training , its open with a new part. I tried running it as an administrator and still no luck.  I have attached the project here. Also, I tried to change this from Any CPU to X64 as per the instructor advice and still no luck.

 

3DAli_0-1637008979654.png

 

 

0 Likes
Message 9 of 15

3DAli
Collaborator
Collaborator

I just tried this code with Inventor 2020 and it works fine! so the problem is IV2022 , any idea why it doesn't work with the 2022 version?

0 Likes
Message 10 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

Thanks for sharing your project. Unfortunately I can't reproduce your error. Your App starts and run as expected. I think there's maybe something wrong with the registration of Inventor in your Windows registry. You can try to create a new user profile to test if the CurrentUser part of registry is corrupted or make a clean uninsall and reinstall Inventor.

Right now read your last post. Happy to hear that it works in 2020. Which ServicePack is installed on 2022? If not installed, install 2022.2 and try again.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 11 of 15

3DAli
Collaborator
Collaborator

I'm installing 2022.2 update and let you know how it goes, at least we know that the problem is not with the code 

I appreciate your support 

Cheers

0 Likes
Message 12 of 15

3DAli
Collaborator
Collaborator

now this is very interesting, here is what I found , I uninstalled and did a registry clean up , did a fresh new install of Inventor 2022 with latest updates. then I installed the developer tools under SDK folder and even those sample standalone apps can not detect that inventor is running. it only happens on 2022, it works perfectly fine on 2020.

 

C:\Users\Public\Documents\Autodesk\Inventor 2022\SDK\DeveloperTools\Samples\VB.NET\Standalone Applications\Inventor\Attributes\bin

 

3DAli_1-1637026942761.png

 

non of those samples work, they all say Inventor must be running ad that means Windows can't detect inventor is actually running!

 

any suggestion?

 

Regards

Ali

  

0 Likes
Message 13 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

Sorry, can't tell you why this happens. I can suggest some ideas to try, but would be better to contact support for this.

Be careful not to destroy your installation.

1. First ttry to create a new user account to test if the problem persist.

2. Click Windows start button and type in "dcomcnfg". Check under component services, "DCOM configuration" the "Inventor Application Object". The local path should always target the last started Inventor version.

3. In the DCOM object properties is also the ProgID. You can search this ID in registry and check if these entrys look ok.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 14 of 15

3DAli
Collaborator
Collaborator

Hi

 

Tried them all, nothing seems to be out of order, I checked them , even a new user profile did not fix this !

 

I am out of luck till I get a hold of support , I hope they see this post 🙂 and comment

 

Thank you anyways

0 Likes
Message 15 of 15

3DAli
Collaborator
Collaborator
Accepted solution

problem solved! all you need to do is to run Visual Basic as an administrator , then everything works well regardless of which inventor version you are using. even sample EXE works well when you open them as an administrator.

 

hope this helps if someone out there is facing the same issue

 

Cheers

0 Likes