Open Inventor Part With the help of excel vba

Open Inventor Part With the help of excel vba

Anonymous
Not applicable
7,068 Views
19 Replies
Message 1 of 20

Open Inventor Part With the help of excel vba

Anonymous
Not applicable

Hello Friends,

 

Could you please tell me, Is there any option to open inventor part by excel vba user form.

Thirty different types of door series are include in one part using multiple extrude,cut, and other features and i have drives those different series with the help of combo box from excel vb.net user form sheet also drive different parameter like Door Width, Length and Thickness by same excel. All parameters are worked and updated in inventor model. But i want, when i put all the value of parameter in excel user form and click on the DONE button then part will be open and get update as per excel parameter then after it will be closed.  

please see below excel vb.net user form for you reference.

 

 

 

Thanks

Parth Patel

0 Likes
7,069 Views
19 Replies
Replies (19)
Message 2 of 20

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

Hi,

 

You can use this code but you must add a reference in Excel vba (Tools->References)

 

Knipsel.JPG

 

Then you can use this code to open the file:

 

Sub OpenInventorDocumentFromExcel()
Dim strFile As String
strFile = "Fill In Full Filename of the document"

Dim InvApp As Inventor.Application

'If you like to create a new inventor instance
Set InvApp = CreateObject("Inventor.Application")

'if you like to use an open instance of inventor

'Set inventorApp = GetObject(, "Inventor.Application")
InvApp.Visible = True
Call InvApp.Documents.Open(strFile, False)

End Sub

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 3 of 20

Anonymous
Not applicable
Accepted solution
0 Likes
Message 4 of 20

Anonymous
Not applicable
Accepted solution

Hi, 

 

I need another help.

when i update my excel user form parameter and click on the button then part is open but it is not updated as per my excel user from parameters and selection.

 

It is update when i was close my excel sheet and run i-logic rules manually from i-logic rule tab which is in my model.

 

Thanks

Parth

 

0 Likes
Message 5 of 20

frederic.vandenplas
Collaborator
Collaborator

Hi,

 

If you do the steps manually (as i allways do before programming i write down all the steps i need to program.) you wille see

that you need to save the excel file, before or after opening the document. And to be sure doc.rebuild or doc.rebuild2

If your excel is not saved, inventor will look at the value when the document was last saved.

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 6 of 20

Anonymous
Not applicable

Hi,

 

Thank you very much

 

Its worked very well.

 

 

0 Likes
Message 7 of 20

Anonymous
Not applicable

HI,

 

When i have change the parameters of model from excel user form and click user from button then my model have open and update as per my excel user from parameters.but after when i have change model parameters from excel user form it's not update in my model.

 

Is there any option to live update inventor model by clicking excel user form button when model and excel both are open?

 

 

 

 

 

0 Likes
Message 8 of 20

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

Hi,

 

If you call this sub in every sub/function you have in excel then your model will update.

You could also raise an excel event on changing cells

 

Sub Button1_Click() 'this is a button in excel or form in vba

ActiveWorkbook.Save 'Don't forget to save
LiveUpdate

End Sub

 

Sub LiveUpdate()

Dim InvApp As Inventor.Application

Set InvApp = GetObject(, "Inventor.Application")
Dim oDoc As PartDocument

Set oDoc = InvApp.ActiveDocument

oDoc.Rebuild

End Sub

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 9 of 20

Anonymous
Not applicable

Hi Frederic,

 

When i have upload the Live Update vba code and click on the button then below error occur.

it's stop at oDoc.Rebuild.

 

 

 

Capture.JPG

 

 

0 Likes
Message 10 of 20

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

Hi,

 

The error occuring is most likely because your document is not open, my snippet is perfectly working here.

 

You have to make sure that you first open the document you need to update

Set oDoc = Invapp.document.open("fullfilename",True)

 

What i don't know from your explanation is if you want to open a part/assembly/drawing.

 

So if you declare oDoc, you need to modify this:

 

Dim oDoc as PartDocument (or AssemblyDocument or DrawingDocument )

 

Or alternatively you could do this (less advised)

 

Dim oDoc as Document

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 11 of 20

Anonymous
Not applicable

Hi frederic,

 

As instructed by you i have follow the rule and it's worked up to excel sheet. when i have click my button then the user form parameters pass into my excel cells and it's save and also opened inventor part window is flashing  whenever i have clicking button but my part is not update as per my excel cells value.

 

Please help.

 

Thanks

Parth

 

0 Likes
Message 12 of 20

frederic.vandenplas
Collaborator
Collaborator

Hi,

 

Can you please provide a full sample of what you are trying to achieve (excel file, inventor file, code...)

 

That would be more realistic to test because your close, but something missing that i can't see or know.

 

Thanks

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 13 of 20

Anonymous
Not applicable

Hi Frederic,

 

Please find enclosed here with zip folder of my model with excel.

In folder i have placed another folder of door series images for your reference of door series types which is include in my model.

 

Parth

 

0 Likes
Message 14 of 20

Anonymous
Not applicable
Accepted solution

Hi Frederic,

 

What  about my model? is there worked?

 

Thanks

Parth

 

0 Likes
Message 15 of 20

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

Hi,

 

Sorry for my late response, busy here Smiley Tongue

 

I took a decent look at your project and here is my resolution

 

First of al, it's easier if you make a relative path for referenced documents, if you move your project then there's no need to alter the code.

 

for example:

 

'oWB = oExcel.Workbooks.Open("C:\Users\parth.vpatel\Desktop\BARN DOOR\DOOR DESIGN TOOL.xlsm")
oWB = oExcel.Workbooks.Open(ThisDoc.Path & "\DOOR DESIGN TOOL.xlsm")

But when i look deeper into your project, i would suggest to NOT use excel for this, you can make it much easier if you just use an iLogic form where you place the parameters.

 

So i've recreated the excel as an ilogic form "Door Design Tool" with the parameters included and a button to run the rule if needed.

I also supressed the rule for excel, because it's eliminated.

 

The modified project is included as an attachment, if in doubt, just ask!

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 16 of 20

Anonymous
Not applicable

Hello Frederic,

 

Sorry for late replay due to workload.

 

Yes, i understood and i will done that. But just for knowledge can you tell me, Is that possible live update inventor model with excel?

 

Thanks

Parth

0 Likes
Message 17 of 20

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

Hi,

 

I've digged a little deeper in the live update, and update, update2, rebuild, rebuild2 does NOT work persistent.

 

So i've came up with the idea to move the EndOfPart feature to the top of the browser, and place it back to the end of the browser.

That invoked an update of the model (finally)

 

Attached you can find a working example with code in excel, and also a sub that should work on your model.

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 18 of 20

Anonymous
Not applicable

Hello Frederic,

 

Sorry for late reply.

 

Thank you very much.

it's worked very well.

 

Regards

Parth

 

0 Likes
Message 19 of 20

frederic.vandenplas
Collaborator
Collaborator

Nice to hear that!

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 20 of 20

Anonymous
Not applicable
Hello Frederic,

 

Could you do me a favaour regarding below?

 

I have an assembly model in which i am create i logic rules. All rules are worked and update the model but i want to one extra thing. which  is, when i am entering the new project number from user form and click the apply button from user form then the whole assembly and its parts generate with new project number with appropriate new project folder and delete all rule from generated new assembly model.  See below what i am exactly looking,

 

My Master Model,

 

1) Master Model- 2200

    Master Model File Path:-E:\Project\2200\

 

    Master Model Assembly Parts- 2200-001

    Master Model Assembly Parts- 2200-002

    Master Model Assembly Parts- 2200-003

 

 

Generated New Model Assembly

 

 

2) New Model- 2300

    New Model File Path:-E:\Project\2300\

 

    New Model Assembly Parts- 2300-001

    New Model Assembly Parts- 2300-002

    New Model Assembly Parts- 2300-003

 

Thanks 

Parth

0 Likes