Is there any VBA code that can count the number of bends used in a sheet metal part?
I would like to make a custom property of this, so it can be exported to Excel for input in our ERP system
Thanks!
Solved! Go to Solution.
Solved by alewer. Go to Solution.
Try this:
Public Sub BendCountToIprop() '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 'Get the bend count Dim iBendCount As Integer iBendCount = oSheetMetalComp.Bends.Count 'Get the custom property set Dim oCustomProps As Inventor.PropertySet Set oCustomProps = oPartDocument.PropertySets.Item("Inventor User Defined Properties") 'Define the name of the bend count iproperty name: Dim sBendPropName As String sBendPropName = "Bend Count" 'See if we already have an iproperty for the bend count Dim oBendProp As Inventor.Property Dim oProp As Inventor.Property 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 = iBendCount Exit Sub 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(iBendCount, sBendPropName) End Sub
Let me know if it works.
Public Sub BendCountToIprop() 'Get the part doc and sheet metal component defn. No error handling: Dim oApp As Inventor.Application Dim oDoc As Inventor.Document Set oApp = GetObject(, "Inventor.Application") If oApp.ActiveDocumentType = kDrawingDocumentObject Then Set oDoc = oApp.ActiveDocument Else: If TypeOf oApp.ActiveEditObject Is Sketch Then Exit Sub Set oDoc = oApp.ActiveEditObject End If Dim oSheetMetalComp As Inventor.SheetMetalComponentDefinition Set oSheetMetalComp = oDoc.ComponentDefinition 'Get the bend count Dim iBendCount As Integer iBendCount = oSheetMetalComp.Bends.Count 'Get the custom property set Dim oCustomProps As Inventor.PropertySet Set oCustomProps = oDoc.PropertySets.Item("Inventor User Defined Properties") 'Define the name of the bend count iproperty name: Dim sBendPropName As String sBendPropName = "Bend Count" 'See if we already have an iproperty for the bend count Dim oBendProp As Inventor.Property Dim oProp As Inventor.Property 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 = iBendCount Exit Sub 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(iBendCount, sBendPropName) End Sub
Works great! Thanks a lot!
I changed it a little, so i dont need to open each part as i usually do this from an assembly...
@Anonymous wrote:There is one problem, if cut or hole cuts the bend line itll count it twice.
I can't get this behavior. With the attached part (SixBends.ipt / Inventor 2010) try to get the bend count two ways: as is, with end of part above Extrusion1 and Hole1, then with the end of part rolled all the way down. For both cases, I get six bends.
If you can upload a simple example file that shows this behavior I'd be curious, but unfortunately I'm still only on 2010...
This only happens when the face is not connected after the bend, hard to explain...
Heres pic of what i mean, this part counts 7 bends.
I see the issue: on a long enough press brake, this would be formed with two bending operations. But Inventor is counting a bend for each of the flange operations in the model. You could incorporate some logic to remove from the count any colinear bends, but that will cause errors. Open the attached file and walk with me...
To illustrate, let's look at three cases:
1-Real life bend count--how it is made in the shop
2-My code above (all Inventor bends)
3-Code that deducts colinear bend lines from Inventor's bend count
Look at the attached part. For the three cases:
1-Three bends
2-Four bends
3-Two bends. Two "real life" bending operations are required to accomplish what I created with Face4, but the bends are colinear!
I am sure it is possible to come up with some more elaborate code to better calculate the number of bends, but you're probably looking at a lot more code, and I doubt you will ever be able to program something that's right every time.
I required the same type of macros for an assembly(If i run the Macros in an assembly i have to get the BendCount for all the parts). Is it possible?
Can't find what you're looking for? Ask the community or share your knowledge.