Update name of UCS

Update name of UCS

marius.andersen3RVB4
Enthusiast Enthusiast
216 Views
1 Reply
Message 1 of 2

Update name of UCS

marius.andersen3RVB4
Enthusiast
Enthusiast

Hi.
All my Inventor part and assembly template files is starting with a inserted UCS in 0,0,0
The name of this UCS is COG - (0 kg)
I am writing a iLogic code that (On demand) can update the position of this UCS by the iProperties.CenterOfGravity.x y and z value.

'Ok. I know there is some codes out there that does this trick, but update is the clue here.
'All other codes i have seen inserts a new workpoint..... Then all constrains to the cog object is lost.
'I need to update and Actually move the cog object.

So far so good. I am able to manipulate the prosition og the UCS and i have declared string variable for the name of the UCS. CogW. I can also handle manipulation of the string.

Now I want to update the name of this UCS object.
I need a code that can look through the file and look for a UCS object eith name starting with COG - (
Then change the name of this object to the content of string variable CogW.
As long as the code is only looking for the string COG - ( it will also work after the mass value is updated in the name.

Some Snags

mariusandersen3RVB4_0-1672353680813.png

mariusandersen3RVB4_1-1672353817230.png

 




Anyone that can help a newbie 

0 Likes
217 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

Try something like this:

Dim ucsName = "COG - ("

Dim doc As PartDocument = ThisDoc.Document
Dim def As PartComponentDefinition = doc.ComponentDefinition

Dim ucs = def.UserCoordinateSystems.
    Cast(Of UserCoordinateSystem).
    Where(Function(u) u.Name.StartsWith(ucsName)).
    FirstOrDefault()

If (ucs Is Nothing) Then
    MsgBox(String.Format("None UCS found with a name that starts with: '{0}' (Search is case sensitive!)", ucsName))
End If

ucs.XOffset.Value = def.MassProperties.CenterOfMass.X
ucs.YOffset.Value = def.MassProperties.CenterOfMass.Y
ucs.ZOffset.Value = def.MassProperties.CenterOfMass.Z

Dim mass = Math.Round(def.MassProperties.Mass, 3).ToString()

ucs.Name = String.Format("{0} ({1}Kg)", ucsName, mass)

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