GoG coordinates to parameters

GoG coordinates to parameters

Cris-Ideas
Advisor Advisor
359 Views
3 Replies
Message 1 of 4

GoG coordinates to parameters

Cris-Ideas
Advisor
Advisor

Hi,

I am doing a boarding task right now assigning CoG coordinates to assembly parameter for many parts.

 

Perhaps someone could help me by providing simple function to do just that?

 

In assembly I have a parameters CoG_X, CoG_Y, CoG_Z.

I need to assign values to those based on X,Y,Z of current assembly's CoG position. This needs to be done by invoking command, not automatically (preferably from RMB context menu, but this may be to much to ask, so anything will do) 

 

Can you help?

 

Cris.

Cris,
https://simply.engineering
0 Likes
360 Views
3 Replies
Replies (3)
Message 2 of 4

dalton98
Collaborator
Collaborator

Try This:

Dim oAss As AssemblyDocument
oAss = ThisApplication.ActiveDocument

Dim oUserParams As UserParameters
oUserParams = oAss.ComponentDefinition.Parameters.UserParameters

Try
oUserParams.Item("CoG_X").Value = oAss.ComponentDefinition.MassProperties.CenterOfMass.X
Catch
oUserParams.AddByValue("CoG_X", oAss.ComponentDefinition.MassProperties.CenterOfMass.X, UnitsTypeEnum.kInchLengthUnits)
End Try

Try
oUserParams.Item("CoG_Y").Value = oAss.ComponentDefinition.MassProperties.CenterOfMass.Y
Catch
oUserParams.AddByValue("CoG_Y", oAss.ComponentDefinition.MassProperties.CenterOfMass.Y, UnitsTypeEnum.kInchLengthUnits)
End Try

Try
oUserParams.Item("CoG_Z").Value = oAss.ComponentDefinition.MassProperties.CenterOfMass.Z
Catch
oUserParams.AddByValue("CoG_Z", oAss.ComponentDefinition.MassProperties.CenterOfMass.Z, UnitsTypeEnum.kInchLengthUnits)
End Try
Message 3 of 4

JelteDeJong
Mentor
Mentor

probably this post has allyou need.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/center-of-gravity-coordinates-of-all...

 

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 4

Cris-Ideas
Advisor
Advisor

Hi Guys,

Thank you for support.

I have seen the mentioned post before, and the code above of course.

 

I did however go with something different, that I was able to understand (as I did not know where to place code you propose). I have basic coding experience in VB.net but I am totally unfamiliar with Inventor API, so I have no idea where to click, and how to trigger methods, and where to place them in the first place.

 

I have however been able to create a simple rule in iLogic editor (or however it is called), using your guidance on how to find required properites.

 

It does not work 100% as I expected, as I am having some issues with assembly update (that's why I have this "update" methods invoked).

 

Could you please give me some basic explanation/advice on how to make the rule:

1) update mass props before assigning coordinates of CoG to parameters, so they are up to date with current state of the assembly,

2) update/rebuild assembly so my work point is where it suppose to be.

 

At first attempts I had to run the rule twice or update the assembly manually every time. Now it kind of works but I am not entirely sure if it is by accident or if it is actually ding what I expect it to do.

 

InventorVb.DocumentUpdate()
CoG_X = iProperties.CenterOfGravity.X
CoG_Y= iProperties.CenterOfGravity.Y
CoG_Z = iProperties.CenterOfGravity.Z
InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True

 

All comments welcome.

 

Cris.

Cris,
https://simply.engineering
0 Likes