
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Public Sub BendingTime() 'set a constant to identify sheet metal parts Const CLSID_InventorSheetMetalPart_RegGUID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Dim m_inventorapplication As Inventor.Application Set m_inventorapplication = GetObject(, "Inventor.Application") 'check that this is running on an assembly document If (m_inventorapplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject) Then 'get the active assembly Dim asmDoc As AssemblyDocument Set asmDoc = ThisApplication.ActiveDocument Call TraverseAssembly(asmDoc.ComponentDefinition.Occurrences) End If msgbox ("this runs on assembly documents only") End Sub Private Sub TraverseAssembly(Occurrances As ComponentOccurrences) Dim Occ As ComponentOccurrence Dim oSheetMetalComp As Inventor.SheetMetalComponentDefinition Dim iBendCount As Integer Dim oCustomProps As Inventor.PropertySet Dim sBendPropName As String sBendPropName = "Bend Time" Dim oBendProp As Inventor.Property Dim oProp As Inventor.Property For Each Occ In Occurrances 'If Occ.SubType = CLSID_InventorSheetMetalPart_RegGUID Then Set oSheetMetalComp = Occ.ComponentDefinition iBendTime = oSheetMetalComp.Bends.Count * 0.00556 Set oCustomProps = Occ.PropertySets.Item("Inventor User Defined Properties") For Each oProp In oCustomProps If oProp.Name = sBendPropName Then 'We already have an iproperty, we just need to write the new value Set oBendProp = oProp oBendProp.Value = iBendTime End If Next oProp 'We don't have an iproperty, so we create it and set its value If oBendProp Is Nothing Then Set oBendProp = oCustomProps.Add(iBendTime, sBendPropName) If Occ.Definition.DocumentType = kAssemblyDocumentObject Then Call TraverseAssembly(Occ.SubOccurrences) End If 'Else 'MsgBox ("not a sheetmetal doc.") Next
End Sub
I have searched quite a lot for people to just write my code for me without any result - actually surprising. I even set up some stuff on fiverr! No luck!
...so here is my cleaned up version where I combined a few snippets to try to add bend times to an assembly of parts, and to all subsequent subassemblies.
It won't detect if each part is sheetmetal - needs an if statement so it skips over standard parts without just erroring, silently.
I may be declaring things outside of the loop when I need to declare them inside the loop - but that doesn't make sense to me.
Currently hangs up at the red line, object doesn't support this property. But it should! Unless I need to declare the Occ as something else first. I'm running this on an assembly comprised only of sheetmetal parts, so shouldn't be because it's a standard part it's finding.
Thanks in advance for any tips, and have a happy holidays!
James
Solved! Go to Solution.