klarson85 Posted August 13, 2012 Share Posted August 13, 2012 (edited) 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 Edited August 14, 2012 by klarson85 Quote Link to comment Share on other sites More sharing options...
SLW210 Posted August 14, 2012 Share Posted August 14, 2012 I moved your thread to the Autodesk Inventor forum. Please read the CODE POSTING GUIDELINES and edit your post to include code tags. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.