Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Counting bends?

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
2586 Views, 10 Replies

Counting bends?

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!

10 REPLIES 10
Message 2 of 11
alewer
in reply to: Anonymous

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.

Message 3 of 11
Anonymous
in reply to: alewer

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...

Message 4 of 11
Anonymous
in reply to: Anonymous

There is one problem, if cut or hole cuts the bend line itll count it twice.

 

Message 5 of 11
alewer
in reply to: Anonymous


@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...

Message 6 of 11
Anonymous
in reply to: alewer

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.

Message 7 of 11
alewer
in reply to: Anonymous

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.

Message 8 of 11
Anonymous
in reply to: alewer

I see what you mean...

 

we dont have a lot these "problem" parts so its not a big issue...

Message 9 of 11
k14348
in reply to: alewer

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? 

Message 10 of 11
Anonymous
in reply to: k14348

Would anyone like to update this for 2014?

Message 11 of 11
kulolofur
in reply to: Anonymous

Can anyone please update the code, cause its not working.

Thank you

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report