Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm looking to take this excellent code supplied by Curtis W. and have it auto-populate my FX parameters at part level.
Currently, I have to drop a part or parts into an assembly to have this run properly, which works great, but I'm looking to eliminate that assembly requirement for individual parts.
While I can sometimes tweak a routine successfully, I'm not good enough at ilogic coding to understand how to do this. Suggestions welcome...
Sub Main Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences 'step into sub with the target occurrence being the the top level assembly Call TraverseAssembly(oOccs) End Sub Sub TraverseAssembly(oOccs As ComponentOccurrences) Dim oOcc As ComponentOccurrence For Each oOcc In oOccs If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then 'step back into this sub with the target occurrence being the subassembly Call TraverseAssembly(oOcc.SubOccurrences) Else 'parts Dim partDoc As PartDocument = oOcc.Definition.Document If Not partDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For' Check if sheet metal part 'step into sub routine Call FlatExtents(partDoc) End If Next End Sub Sub FlatExtents(partDoc As PartDocument) Dim oCompDef As SheetMetalComponentDefinition = partDoc.ComponentDefinition If oCompDef.HasFlatPattern = False Then oCompDef.Unfold oCompDef.FlatPattern.ExitEdit End If oA = oCompDef.FlatPattern.Length oB = oCompDef.FlatPattern.Width oFlat_Length = Max(oA, oB) oFlat_Wdith = Min(oA, oB) ' Get the parameters of the component definition Dim params As Parameters = oCompDef.Parameters ' Check if parameters "LENGTH" and "WIDTH" exist, update or add them Try params.UserParameters.Item("LENGTH").Value = oFlat_Length Catch params.UserParameters.AddByValue("LENGTH", oFlat_Length, "in") End Try Try params.UserParameters.Item("WIDTH").Value = oFlat_Wdith Catch params.UserParameters.AddByValue("WIDTH", oFlat_Wdith, "in") End Try ' Set parameters to be exposed as properties params.Item("LENGTH").ExposedAsProperty = True params.Item("LENGTH").CustomPropertyFormat.Units = UnitsTypeEnum.kInchLengthUnits params.Item("LENGTH").CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision params.Item("LENGTH").CustomPropertyFormat.ShowUnitsString = False params.Item("WIDTH").ExposedAsProperty = True params.Item("WIDTH").CustomPropertyFormat.Units = UnitsTypeEnum.kInchLengthUnits params.Item("WIDTH").CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision params.Item("WIDTH").CustomPropertyFormat.ShowUnitsString = False params.Item("Thickness").ExposedAsProperty = True params.Item("Thickness").CustomPropertyFormat.Units = UnitsTypeEnum.kInchLengthUnits params.Item("Thickness").CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision params.Item("Thickness").CustomPropertyFormat.ShowUnitsString = False iProperties.Value(partDoc.DisplayName, "Custom", "LENGTH") = "=<Sheet Metal Length>" iProperties.Value(partDoc.DisplayName, "Custom", "WIDTH") = "=<Sheet Metal Width>" End Sub
Solved! Go to Solution.