Changing parameter value of a part that does not exist in an assembly

Changing parameter value of a part that does not exist in an assembly

FINET_Laurent
Advisor Advisor
701 Views
4 Replies
Message 1 of 5

Changing parameter value of a part that does not exist in an assembly

FINET_Laurent
Advisor
Advisor

Morning, 😄

 

As the title said, I was wondering if it was possible to change the value of an user parameter of a part from an assembly where this part hasn't already been placed.

The goal is to get the part with the right parameters before placing it.

I could open the part, change parameters, save it an close it but it looks heavy for what it is..

 

Thanks and have a nice day,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Accepted solutions (2)
702 Views
4 Replies
Replies (4)
Message 2 of 5

robertast
Collaborator
Collaborator

@FINET_Laurent   Hmm na uncle, you came up with a wish. Inventory requires "artificial intelligence" with neural networks to mimic your desires. 🙂
It is possible to load the part into the assembly with the iLogic command and to link the required parameters at the time of loading. But I have no idea of ​​a different algorithm 🙄

Message 3 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

@FINET_Laurent 

The part has to be opened somehow in order to change its parameter. You can however open it hidden. See example code below. Just add the path to the part you want to place, and the name of the parameter you want to change.

Dim oPartFile As String = "C:\Users\hfljf\Desktop\TEST.ipt" 'Part to place
Dim oPart As PartDocument = ThisApplication.Documents.Open(oPartFile, False)
oPart.ComponentDefinition.Parameters("TEST").Expression = 6000 'Change "TEST" to your parameter name
oPart.Update
oPart.Save
oPart.Close
Dim cmdMgr As CommandManager = ThisApplication.CommandManager
cmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPartFile)
cmdMgr.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
ThisDoc.Document.Update
Message 4 of 5

FINET_Laurent
Advisor
Advisor

@JhoelForshav  That will indeed do the trick, thank you.

 

Still have a question, what does those lines do ?

Dim cmdMgr As CommandManager = ThisApplication.CommandManager
cmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPartFile)
cmdMgr.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute

Or can you provide some documentation ?

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 5 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

@FINET_Laurent 

Through the commandmanager you can execute the same Inventor commands that you can do in the user interface. In this example we call the AssemblyPlaceComponentCmd which is the same command as the one that is run if you click the Place button in assembly environment. This command will normally open a file browser dialog for you to select the file you want to place. In order to bypass this step and just place the file we have stored in the variable oPartFile we post this filename to inventors internal clipboard using PostPrivateEvent. When a command is being executed through the CommandManager, Inventor will first check if there's any data in this internal clipboard relevant for the command, and only if there isn't it'll show the dialog for the user to give this data.

PostPrivateEvent: https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-2DFE3D10-D17C-4898-9801-1FB9A6B1CDCD

 

Here are some blogposts on the subject of running commands through the CommandManager:

 

@Anonymous 's post about running commands:

https://clintbrown.co.uk/2020/03/14/ilogic-running-commands-using-the-api/

 

My post about getting the control definition names:

https://clintbrown.co.uk/2020/10/31/get-control-definition-names-ilogic-tool/