I have a code below,
however the ending iProperties need to be set to precision 0, and no units, leading or trailing zeros, however I believe I may need to interject a custom parameters first, and let the iProp equal these.
Let
Run code to get L W T
L= Custom Para L
W= Custom Para W
T= Custom Para T
Set Precision on Custom Para L W T
Custom iProp Length = Custom Para L
Custom iProp Width = Custom Para W
Custom iProp Thickness = Custom Para T
Imports system.Collections Public Sub Main() ' Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Get the assembly component definition. Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition ' Get all of the leaf occurrences of the assembly. Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences ' Iterate through all part occurrences in assembly. Dim oOcc As ComponentOccurrence For Each oOcc In oLeafOccs L = Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10 W = Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10 H = Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10 Dim oList As New ArrayList oList.Add(L) oList.Add(W) oList.Add(H) Call oList.Sort() iProperties.Value(oOcc.Name,"Custom", "Length") = oList.Item(2)& " mm" iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)& " mm" iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0) & " mm" Next End Sub
Solved! Go to Solution.
Solved by Sergio.D.Suárez. Go to Solution.
I have found the code that code be used, but have no ideas how to implement
DimoPartDocAsPartDocument oPartDoc=ThisApplication.ActiveDocument DimoParameterAsParameter DimoFormatAsCustomPropertyFormat ForEachoParameterInoPartDoc.ComponentDefinition.Parameters.UserParameters oFormat=oParameter.CustomPropertyFormat oParameter.ExposedAsProperty=True oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacesPrecision oFormat.Units="mm" oFormat.ShowUnitsString= False oFormat.ShowLeadingZeros= False oFormat.ShowTrailingZeros=False NextoParameter
iProperties.Value(oOcc.Name,"Custom", "Length") = Round(oList.Item(2),0)& " mm" iProperties.Value(oOcc.Name,"Custom", "Width") = Round(oList.Item(1),0)& " mm" iProperties.Value(oOcc.Name, "Custom", "Thickness") = Round(oList.Item(0),1) & " mm"
Hi, try changing the last lines.
I hope this helps. regards
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Any body wants a cutting list that you can run from a component file created from a multi body part, code below! You can also create a cutting list from it too!
Imports system.Collections Public Sub Main() ' Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Get the assembly component definition. Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition ' Get all of the leaf occurrences of the assembly. Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences ' Iterate through all part occurrences in assembly. Dim oOcc As ComponentOccurrence For Each oOcc In oLeafOccs L = Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10 W = Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10 H = Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10 Dim oList As New ArrayList oList.Add(L) oList.Add(W) oList.Add(H) Call oList.Sort() iProperties.Value(oOcc.Name,"Custom", "Length") = Round(oList.Item(2),0)& " mm" iProperties.Value(oOcc.Name,"Custom", "Width") = Round(oList.Item(1),0)& " mm" iProperties.Value(oOcc.Name, "Custom", "Thickness") = Round(oList.Item(0),1) & " mm" Next End Sub
Can't find what you're looking for? Ask the community or share your knowledge.