Search the Community
Showing results for tags 'punches'.
-
Macro for custom property of total number of piercings in a part
klarson85 posted a topic in Autodesk Inventor
Hello, I have been trying to create a macro that would add a custom property to my sheet metal parts that would tell me the total number of piercings in the part (holes and punches). So far I have the punches to count correctly but I am having issues with the holes, as I am getting an error. Any ideas? Sub Piercings() 'Get the part doc and sheet metal component defn. No error handling: Dim oPartDocument As Inventor.PartDocument Set oPartDocument = ThisApplication.ActiveDocument Dim oSheetMetalComp As Inventor.SheetMetalComponentDefinition Set oSheetMetalComp = oPartDocument.ComponentDefinition 'Dim oHoles As Inventor.HoleTables 'Set oHoles = oPartDocument.ComponentDefinition 'Get the pierce count Dim iHoleCount As Integer 'iHoleCount = oHoles.Count Dim iPunchCount As Integer iPunchCount = oSheetMetalComp.FlatPattern.FlatPunchResults.Count Dim iPierceCount As Integer iPierceCount = iHoleCount + iPunchCount 'Get the custom property set Dim oCustomProps As Inventor.PropertySet Set oCustomProps = oPartDocument.PropertySets.Item("Inventor User Defined Properties") 'Define the name of the PIERCING count iproperty name: Dim sPiercePropName As String sPiercePropName = "PIERCINGS" 'See if we already have an iproperty for the PIERCING count Dim oPierceProp As Inventor.Property Dim oProp As Inventor.Property For Each oProp In oCustomProps If oProp.Name = sPiercePropName Then 'We already have an iproperty, we just need to write the new value Set oPierceProp = oProp oPierceProp.Value = iPierceCount Exit Sub End If Next oProp 'We don't have an iproperty, so we create it and set its value If oPierceProp Is Nothing Then Set oPierceProp = oCustomProps.Add(iPierceCount, sPiercePropName) End Sub