Jump to content

Macro for custom property of total number of piercings in a part


Recommended Posts



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

Edited by klarson85
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...