how to overwrite excel file name in iLogic rule

how to overwrite excel file name in iLogic rule

Anonymous
Not applicable
808 Views
11 Replies
Message 1 of 12

how to overwrite excel file name in iLogic rule

Anonymous
Not applicable

Hello I need help with my iLogic rule. First of all I am not experienced with VBA.

I have rule where excel file is always attached in same folder as parametric model, but name of excelfile is variable. In picture you can see that every time when i change excelfile name I must go to iLogic and overwrite it as well. Can anybody help me make it automatically?

 

Thank you in advance

0 Likes
Accepted solutions (1)
809 Views
11 Replies
Replies (11)
Message 2 of 12

mcgyvr
Consultant
Consultant

Well.. you will need to give us a clue on how Inventor is supposed to know what excel file it needs to search for..

Is it always the same as the part number?

Example... part1.ipt would always be looking for part1.xlsx? 

 

If so you could change the rule to pick up on the part number of the file and then use that to populate the excel filename code.. 

 

Something like this..

PN = iProperties.Value("Project", "Part Number")
GoExcel.Open(PN & ".xlsx", "Sheet1")


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 12

Anonymous
Not applicable

Thank you,

well it´s not exactly true. one excell file belong to two or more ipt models.

when models have name ABCD_part1.ipt , ABCD_part2.ipt atc. and excell file is named ABCD.xlsm(same for all models)

Can I in your rule anyhow avoid the end of IPT filename?

0 Likes
Message 4 of 12

mcgyvr
Consultant
Consultant

@Anonymous wrote:

Thank you,

well it´s not exactly true. one excell file belong to two or more ipt models.

when models have name ABCD_part1.ipt , ABCD_part2.ipt atc. and excell file is named ABCD.xlsm(same for all models)

Can I in your rule anyhow avoid the end of IPT filename?


This should do it..

PN = iProperties.Value("Project", "Part Number")
Dim s() As String = PN.split("_")
GoExcel.Open(s(0) & ".xlsx", "Sheet1")


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 5 of 12

Anonymous
Not applicable

It´s better. i try to handle with it but i got error message

 

"Object reference not set to an instance of an object."

 

I little bit update code and check it with message box if the address is correct, but it gave mi the same error message.

PN = ThisDoc.FileName(True)
Dim s() As String = PN.split("_")
GoExcel.Open(s(0) & ".xlsm", "Sheet 1")
0 Likes
Message 6 of 12

mcgyvr
Consultant
Consultant

Are you trying to run that in an assembly or something?



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 7 of 12

Anonymous
Not applicable

no it´s .ipt model, but inside are more Solid Bodies. Can it affect that?

0 Likes
Message 8 of 12

mcgyvr
Consultant
Consultant

@Anonymous wrote:

no it´s .ipt model, but inside are more Solid Bodies. Can it affect that?


Please post your ipt file and the associated excel file and the ilogic code you have created..

The code I posted works just fine but its only a small piece so whatever code you have added is causing the problems..

 

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 9 of 12

Anonymous
Not applicable

Please find files in attachement.

0 Likes
Message 10 of 12

mcgyvr
Consultant
Consultant
Accepted solution
PN = ThisDoc.FileName(True)
Dim s() As String = PN.split("_")
MessageBox.Show(s(0), "Title")

Excelfile=s(0) & ".xlsx"


p1=GoExcel.CellValue(Excelfile,"Sheet1","B2")
p2=GoExcel.CellValue(Excelfile,"Sheet1","B3")
p3=GoExcel.CellValue(Excelfile,"Sheet1","B4")
p4=GoExcel.CellValue(Excelfile,"Sheet1","B5")
p5=GoExcel.CellValue(Excelfile,"Sheet1","B6")


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 11 of 12

Anonymous
Not applicable

Excellent!!!

That´s exactly what I need. Many thanks mcgyvr.

 

0 Likes
Message 12 of 12

mcgyvr
Consultant
Consultant

You can remove the "message box show line" I forgot to cut that out..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes