Center of Gravity as an iProperty for part in subassembly

Center of Gravity as an iProperty for part in subassembly

Anonymous
Not applicable
553 Views
0 Replies
Message 1 of 1

Center of Gravity as an iProperty for part in subassembly

Anonymous
Not applicable

Hi!

I can set the center of gravity for the top level parts and assemblies using "CoG" in the attached files. And I can change a custom variable for all parts using the script "MyNumber".

 

'CoG as a parameter for all parts.
Dim Namn As String = "CoG" 'Sätt variabel:

' Set a reference To the Assembly Component definintion.
'' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
''Iterate through all Of the occurrences
Dim oOccurrence As ComponentOccurrence

check = 0
For Each oOccurrence In oAsmCompDef.Occurrences
''check for and skip virtual components
''(in case a virtual component trips things up)
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
Part=oOccurrence.Name

Dim oString as Object

check=1
pt = iProperties.CenterOfGravity(Part) 

X=Round(pt.X, 1)
Y=Round(pt.Y, 1)
Z=Round(pt.Z, 1)
a="X="&X &"m Y=" &Y &"m Z=" &Z &"m"
iProperties.Value(Part,"Custom",Namn) = a

Else
End If
Next

InventorVb.DocumentUpdate()

If check=0
MessageBox.Show("Failed - check input","iLogic")
Else
End If
'- - - - - - - - - - - find or create custom iProperty - - - - - - - - - -
'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
Dim propertyName1 As String = "MyNumber"
'define custom property collection
oCustomPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")
Try
'look for property
oProp = oCustomPropertySet.Item(propertyName1).Delete
oProp = oCustomPropertySet.Item(propertyName1)
Catch
' Assume error means not found so create it
oCustomPropertySet.Add(15, propertyName1)
End Try
Next

 

 

I would be happy if someone could help me to put them together. See the attached file for a working example (Inventor 2014).

 

Regards

//Markus

0 Likes
554 Views
0 Replies
Replies (0)