Change parameters in a different part from the iLogic code.

Change parameters in a different part from the iLogic code.

Jam_Jumpin
Advocate Advocate
1,237 Views
8 Replies
Message 1 of 9

Change parameters in a different part from the iLogic code.

Jam_Jumpin
Advocate
Advocate

Here's what I am trying to do. 

 

I will open the part and run a rule

Save a copy of the part to a temp location

Alter some parameters on this part

Save it to it's final location

Close the temporary part window. 

 

I can do all these things, but the issue is that I do not know how to change the parameter in the temp part, it is changing the parameters in the part that the rule is running in. 

 

w is the parameter I am trying to change. 

 

TempFile="C:\Users\***\Target\temp_part.ipt"
TargetFile="C:\Users\***\Target\New file.ipt"

ThisDoc.Document.SaveAs(TempFile , True)
Temp2=ThisApplication.Documents.Open(TempFile)

w = InputBox("Width", "Size", "10")
InventorVb.DocumentUpdate()

Temp2.SaveAs(TargetFile, True)

Temp2.Close

 

 

All the forum posts I could find related to the part being in an assembly which is not how I am doing this.  

0 Likes
Accepted solutions (1)
1,238 Views
8 Replies
Replies (8)
Message 2 of 9

JamieVJohnson2
Collaborator
Collaborator

parameters and properties allow you to specify the file as well as the parameter/property name in an overloaded option.  This means you can force the active (or choice) file into the parameter call instead of the 'current' file.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@Jam_Jumpin,

 

Hoping that below iLogic code may helpful.

 

TempFile="C:\Users\***\Target\temp_part.ipt"
TargetFile="C:\Users\***\Target\New file.ipt"

ThisDoc.Document.SaveAs(TempFile, True)

Dim Temp2 As PartDocument 
Temp2 = ThisApplication.Documents.Open(TempFile)

Dim oDef As PartComponentDefinition
oDef = Temp2.ComponentDefinition 

oDef.Parameters.Item("w") = InputBox("Width", "Size", "10")

InventorVb.DocumentUpdate()

Temp2.SaveAs(TargetFile, True)

Temp2.Close

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 9

Jam_Jumpin
Advocate
Advocate

Error on Line 12 : Property 'Item' is 'ReadOnly'.

 

Line 12 is

oDef.Parameters.Item("w") = InputBox("Width", "Size", "10")

 

0 Likes
Message 5 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@Jam_Jumpin,

 

Can you please provide non confidential sample part to test? please mention the Inventor version as well.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 9

Jam_Jumpin
Advocate
Advocate

Simply using a square block to test. Attached. 

 

Inventor 2018

0 Likes
Message 7 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Jam_Jumpin ,

 

Try below iLogic code.

 

TempFile="C:\Users\***\Target\temp_part.ipt"
TargetFile="C:\Users\***\Target\New file.ipt"

ThisDoc.Document.SaveAs(TempFile, True)

Dim Temp2 As PartDocument 
Temp2 = ThisApplication.Documents.Open(TempFile, True)

Dim oDef As PartComponentDefinition
oDef = Temp2.ComponentDefinition 

oDef.Parameters.Item("w").Expression = InputBox("Width", "Size", "10") 
 
Call Temp2.Update 

Temp2.SaveAs(TargetFile, True)

Temp2.Close

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 9

Jam_Jumpin
Advocate
Advocate

Thanks, that works now but I don't understand why it works. Please can you have a look? I have commented out what I think is happening in each stage.

 

I also don't really understand what the command DIM does. 

 

It's great getting help on the internet but if I don't understand it I will never learn to do it myself. 

 

Thank you!

 

'location of temporary folder
TempFile="***\temp_part.ipt"
'Location of target folder
TargetFile="***\New file.ipt"

'Save a temporary file
ThisDoc.Document.SaveAs(TempFile, True)

'Declares Temp2 as a PartDocument variable?
Dim Temp2 As PartDocument 
'Switches ilogic focus to the open temp file?
Temp2 = ThisApplication.Documents.Open(TempFile, True)

'Definies the temp part's parameters as a variable?
Dim oDef As PartComponentDefinition
'Switches iLogic focus to the temp parameters instead of where rule is running?
oDef = Temp2.ComponentDefinition 
'Sets the temp part parameter from input box
oDef.Parameters.Item("w").Expression = InputBox("Width", "Size", "10") 
 
'forces a rebuild?
Call Temp2.Update 
'Saves temp file as new file in target location
Temp2.SaveAs(TargetFile, True)
'Close Temp file
Temp2.Close
0 Likes
Message 9 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@Jam_Jumpin ,

 

ThisDoc means always focus would be in a document where iLogic rule is running. To shift the focus to current document, Temp2 variable is defined. After that, parameters are accessed from componentdefinition.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes