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: 

Display Bend Direction in Model Flat pattern

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
smccoywm
1296 Views, 7 Replies

Display Bend Direction in Model Flat pattern

I am trying to create a command to display the bend information in the model Flat pattern. We do not always create a Idw for parts that we have special dies to form. This creates a problem though if the flat pattern bends are the wrong direction because then it is lasered with the bad side of the material to the outside of the part. The only way to know the bend direction is to create a view on an idw just to check this.

 

I want to open the flat pattern in the ipt and invoke a command to display the bend information on the screen. Has anyone done this or at least point me in the direction of getting a collection of the bend lines in the flat pattern?

 

Scott A. McCoy

West-Mark Tank

7 REPLIES 7
Message 2 of 8
smccoywm
in reply to: smccoywm

Solution.jpg

Nevermind I found the answer I was looking for and developed a solution.

Message 3 of 8
alewer
in reply to: smccoywm

Care to share your solution? I was hoping that somebody would come up with the answer, as it would help me too.

Message 4 of 8
MegaJerk
in reply to: alewer

I too would enjoy knowing the answer!



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 5 of 8
smccoywm
in reply to: smccoywm

 Here is my solution. I added it to my Inventor Add-In creating a button in the Flat Pattern Ribbon. It's probably not the cleanest approach but it works well. Smiley Happy

 

        Private Sub oButton_Bends_OnExecute(ByVal Context As Inventor.NameValueMap) Handles oButton_Bens.OnExecute
            oInteractionEvents = Inv.CommandManager.CreateInteractionEvents
            oInteractionEvents.StatusBarText = "Press Esc to Cancel command."
            oInteractionEvents.Start()

            Dim i As Integer = 1
            ' Set a reference to the active document.
            Dim oPartDoc As PartDocument
            oPartDoc = Inv.ActiveDocument

            ' Set a reference to the active flat pattern.
            Dim oFlatPattern As FlatPattern
            oFlatPattern = Inv.ActiveEditObject

            Dim oAllBendEdges As EdgeCollection
            oAllBendEdges = Inv.TransientObjects.CreateEdgeCollection

            Dim oTempEdge As Edge

            ' Highlight tangent edges in blue.
            Dim oTangentHS As HighlightSet
            oTangentHS = Inv.ActiveDocument.CreateHighlightSet
            oTangentHS.Color = Inv.TransientObjects.CreateColor(255, 0, 0)

            On Error Resume Next
            Call FlatPatternInformation()
            If Err.Number Then Err.Clear()

            ' Get all Bend UP edges on top face
            Dim oTopFaceBendUpEdges As Edges
            oTopFaceBendUpEdges = oFlatPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True)
            For Each oTempEdge In oTopFaceBendUpEdges
                Call AddText(i, "UP", (oTempEdge.StartVertex.Point.X + oTempEdge.StopVertex.Point.X) / 2, (oTempEdge.StartVertex.Point.Y + oTempEdge.StopVertex.Point.Y) / 2)
                i += 1
            Next

            ' Highlight tangent edges in blue.
            Dim oTangentHS2 As HighlightSet
            oTangentHS2 = Inv.ActiveDocument.CreateHighlightSet
            oTangentHS2.Color = Inv.TransientObjects.CreateColor(0, 0, 255)

            ' Get all Bend DOWN edges on top face
            Dim oTopFaceBendDownEdges As Edges
            oTopFaceBendDownEdges = oFlatPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True)
            For Each oTempEdge In oTopFaceBendDownEdges
                Call AddText(i, "DN", (oTempEdge.StartVertex.Point.X + oTempEdge.StopVertex.Point.X) / 2, (oTempEdge.StartVertex.Point.Y + oTempEdge.StopVertex.Point.Y) / 2)
                i += 1
            Next

            ' Get all Bend UP edges on top face
            oTopFaceBendUpEdges = oFlatPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True)
            For Each oTempEdge In oTopFaceBendUpEdges
                oAllBendEdges.Add(oTempEdge)
                oTangentHS.AddItem(oTempEdge)
            Next

            ' Get all Bend DOWN edges on top face
            oTopFaceBendDownEdges = oFlatPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True)
            For Each oTempEdge In oTopFaceBendDownEdges
                oAllBendEdges.Add(oTempEdge)
                oTangentHS2.AddItem(oTempEdge)
            Next
            Inv.ActiveView.Update()

        End Sub
        Private Sub AddText(ByRef Instance As Integer, ByRef Direction As String, ByRef x As Integer, ByRef y As Integer, Optional ByVal LJustify As Boolean = False)
            Dim oClientGraphics As ClientGraphics
            oClientGraphics = Inv.ActiveEditObject.ClientGraphicsCollection.Add("Bend" & Instance)
            ' Create a graphics node.
            Dim oNode As GraphicsNode
            oNode = oClientGraphics.AddNode(1)
            ' Create text graphics.
            Dim oTextGraphics As TextGraphics
            oTextGraphics = oNode.AddTextGraphics

            ' Set the properties of the text.
            oTextGraphics.Text = Direction
            oTextGraphics.Bold = False
            oTextGraphics.Font = "Arial"
            oTextGraphics.FontSize = 18
            oTextGraphics.Italic = False
            Call oTextGraphics.PutTextColor(255, 255, 0)
            oTextGraphics.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextLower

            If LJustify = True Then
                ' Set the properties of the text.
                oTextGraphics.Anchor = Inv.TransientGeometry.CreatePoint(x, y, 0)
                oTextGraphics.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft
            Else
                ' Set the properties of the text.
                oTextGraphics.Anchor = Inv.TransientGeometry.CreatePoint(x, y, 0)
                oTextGraphics.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextCenter
            End If

        End Sub
        Public Sub FlatPatternInformation()
            Dim oDoc As PartDocument
            oDoc = Inv.ActiveDocument

            Dim SpaceX As Integer = 200
            Dim SpaceY As Integer = 10
            Dim Interiorprofiles As String
            Dim Perimeter As String
            Dim strThickness As String
            Dim strMaterial As String
            Dim oExtent As Inventor.Box
            Dim dLength As Double
            Dim dWidth As Double
            Dim sLength As String
            Dim sWidth As String
            Dim oFlatPattern As Inventor.FlatPattern
            oFlatPattern = oDoc.ComponentDefinition.FlatPattern
            Perimeter = FlatPatternGetTotalLength(oDoc)
            Interiorprofiles = FlatPatternGetInteriorLoopCount(oDoc)
            strMaterial = oDoc.ComponentDefinition.Material.Name
            ' Get a reference to the parameter controlling the thickness.
            Dim oThicknessParam As Inventor.Parameter
            oThicknessParam = oDoc.ComponentDefinition.Thickness
            strThickness = oThicknessParam.Expression
            oExtent = oFlatPattern.Body.RangeBox

            ' Extract the width and length from the range.
            dLength = System.Math.Round(oExtent.MaxPoint.X, 2) - System.Math.Round(oExtent.MinPoint.X, 2)
            dWidth = System.Math.Round(oExtent.MaxPoint.Y, 2) - System.Math.Round(oExtent.MinPoint.Y, 2)

            Dim oUom As Inventor.UnitsOfMeasure
            oUom = oDoc.UnitsOfMeasure

            sWidth = oUom.GetStringFromValue(dWidth, Inventor.UnitsTypeEnum.kDefaultDisplayLengthUnits)
            sLength = oUom.GetStringFromValue(dLength, Inventor.UnitsTypeEnum.kDefaultDisplayLengthUnits)

            ' Set a reference to the component definition.
            Dim oCompDef As ComponentDefinition
            oCompDef = oDoc.ComponentDefinition

            ' Attempt to get the existing client graphics object.  If it exists
            ' delete it so the rest of the code can continue as if it never existed.
            Dim oClientGraphics As ClientGraphics

            ' Create a new ClientGraphics object.
            oClientGraphics = Inv.ActiveEditObject.ClientGraphicsCollection.Add("Flat Information")

            ' Create a graphics node.
            Dim oNode As GraphicsNode
            oNode = oClientGraphics.AddNode(1)

            Dim oTG As TransientGeometry
            oTG = Inv.TransientGeometry

            Dim oModelAnchorPoint As Inventor.Point
            If dLength > dWidth * 2 Then
                oModelAnchorPoint = oTG.CreatePoint(oExtent.MinPoint.X, oExtent.MinPoint.Y - 6, 0)
            Else
                oModelAnchorPoint = oTG.CreatePoint(oExtent.MaxPoint.X + 6, oExtent.MaxPoint.Y, 0)
            End If

            ' Create several text graphics objects, one for each font change.  The anchor of the
            ' TextGraphics object defines the position of each text element relative to each other.
            ' Because they're all drawn with pixel scaling behavior these coordinates are in
            ' pixel SpaceX.  They all use the same point as input for the SetTransformBehavior call.
            ' This point is in model SpaceX and defines their anchor within the model.

            ' Draw the first character which is the diameter symbol.
            Dim oTextGraphics(0 To 12) As TextGraphics
            oTextGraphics(1) = oNode.AddTextGraphics
            oTextGraphics(1).Text = "Thickness: "
            oTextGraphics(1).Anchor = oTG.CreatePoint(oModelAnchorPoint.X, oModelAnchorPoint.Y, 0)
            oTextGraphics(1).Font = "ARIAL"
            oTextGraphics(1).FontSize = 18
            oTextGraphics(1).Bold = True
            oTextGraphics(1).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft
            Call oTextGraphics(1).PutTextColor(255, 255, 0)
            oTextGraphics(1).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(1).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            oTextGraphics(2) = oNode.AddTextGraphics
            oTextGraphics(2).Text = strThickness
            oTextGraphics(2).Anchor = oTG.CreatePoint(oModelAnchorPoint.X + SpaceX, oModelAnchorPoint.Y, 0)
            oTextGraphics(2).Font = "ARIAL"
            oTextGraphics(2).FontSize = 18
            oTextGraphics(2).Bold = True
            oTextGraphics(2).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextRight
            Call oTextGraphics(2).PutTextColor(255, 255, 0)
            oTextGraphics(2).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(2).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            ' Draw the next section of the string relative to the first section.
            oTextGraphics(3) = oNode.AddTextGraphics
            oTextGraphics(3).Text = "Material: "
            oTextGraphics(3).Anchor = oTG.CreatePoint(oModelAnchorPoint.X, oModelAnchorPoint.Y - SpaceY * 2, 0)
            oTextGraphics(3).Font = "Arial"
            oTextGraphics(3).FontSize = 18
            oTextGraphics(3).Bold = True
            oTextGraphics(3).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft
            Call oTextGraphics(3).PutTextColor(255, 255, 0)
            oTextGraphics(3).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(3).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            oTextGraphics(4) = oNode.AddTextGraphics
            oTextGraphics(4).Text = strMaterial
            oTextGraphics(4).Anchor = oTG.CreatePoint(oModelAnchorPoint.X + SpaceX, oModelAnchorPoint.Y - SpaceY * 2, 0)
            oTextGraphics(4).Font = "ARIAL"
            oTextGraphics(4).FontSize = 18
            oTextGraphics(4).Bold = True
            oTextGraphics(4).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextRight
            Call oTextGraphics(4).PutTextColor(255, 255, 0)
            oTextGraphics(4).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(4).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            ' Draw a depth symbol on the next line.
            oTextGraphics(5) = oNode.AddTextGraphics
            oTextGraphics(5).Text = "Perimeter: "
            oTextGraphics(5).Anchor = oTG.CreatePoint(oModelAnchorPoint.X, oModelAnchorPoint.Y - SpaceY * 4, 0)
            oTextGraphics(5).Font = "Arial"
            oTextGraphics(5).FontSize = 18
            oTextGraphics(5).Bold = True
            oTextGraphics(5).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft
            Call oTextGraphics(5).PutTextColor(255, 255, 0)
            oTextGraphics(5).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(5).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            oTextGraphics(6) = oNode.AddTextGraphics
            oTextGraphics(6).Text = Perimeter
            oTextGraphics(6).Anchor = oTG.CreatePoint(oModelAnchorPoint.X + SpaceX, oModelAnchorPoint.Y - SpaceY * 4, 0)
            oTextGraphics(6).Font = "ARIAL"
            oTextGraphics(6).FontSize = 18
            oTextGraphics(6).Bold = True
            oTextGraphics(6).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextRight
            Call oTextGraphics(6).PutTextColor(255, 255, 0)
            oTextGraphics(6).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(6).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            ' Draw the last set of text.s
            oTextGraphics(7) = oNode.AddTextGraphics
            oTextGraphics(7).Text = "Interior Profiles: "
            oTextGraphics(7).Anchor = oTG.CreatePoint(oModelAnchorPoint.X, oModelAnchorPoint.Y - SpaceY * 6, 0)
            oTextGraphics(7).Font = "Arial"
            oTextGraphics(7).FontSize = 18
            oTextGraphics(7).Bold = True
            oTextGraphics(7).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft
            Call oTextGraphics(7).PutTextColor(255, 255, 0)
            oTextGraphics(7).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(7).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            oTextGraphics(8) = oNode.AddTextGraphics
            oTextGraphics(8).Text = Interiorprofiles
            oTextGraphics(8).Anchor = oTG.CreatePoint(oModelAnchorPoint.X + SpaceX, oModelAnchorPoint.Y - SpaceY * 6, 0)
            oTextGraphics(8).Font = "ARIAL"
            oTextGraphics(8).FontSize = 18
            oTextGraphics(8).Bold = True
            oTextGraphics(8).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextRight
            Call oTextGraphics(8).PutTextColor(255, 255, 0)
            oTextGraphics(8).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(8).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            ' Draw the last set of text.s
            oTextGraphics(9) = oNode.AddTextGraphics
            oTextGraphics(9).Text = "Max X Dim: "
            oTextGraphics(9).Anchor = oTG.CreatePoint(oModelAnchorPoint.X, oModelAnchorPoint.Y - SpaceY * 8, 0)
            oTextGraphics(9).Font = "Arial"
            oTextGraphics(9).FontSize = 18
            oTextGraphics(9).Bold = True
            oTextGraphics(9).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft
            Call oTextGraphics(9).PutTextColor(255, 255, 0)
            oTextGraphics(9).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(9).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            oTextGraphics(10) = oNode.AddTextGraphics
            oTextGraphics(10).Text = sLength
            oTextGraphics(10).Anchor = oTG.CreatePoint(oModelAnchorPoint.X + SpaceX, oModelAnchorPoint.Y - SpaceY * 8, 0)
            oTextGraphics(10).Font = "ARIAL"
            oTextGraphics(10).FontSize = 18
            oTextGraphics(10).Bold = True
            oTextGraphics(10).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextRight
            Call oTextGraphics(10).PutTextColor(255, 255, 0)
            oTextGraphics(10).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(10).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            ' Draw the last set of text.s
            oTextGraphics(11) = oNode.AddTextGraphics
            oTextGraphics(11).Text = "Max Y Dim: "
            oTextGraphics(11).Anchor = oTG.CreatePoint(oModelAnchorPoint.X, oModelAnchorPoint.Y - SpaceY * 10, 0)
            oTextGraphics(11).Font = "Arial"
            oTextGraphics(11).FontSize = 18
            oTextGraphics(11).Bold = True
            oTextGraphics(11).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft
            Call oTextGraphics(11).PutTextColor(255, 255, 0)
            oTextGraphics(11).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(11).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            oTextGraphics(12) = oNode.AddTextGraphics
            oTextGraphics(12).Text = sWidth
            oTextGraphics(12).Anchor = oTG.CreatePoint(oModelAnchorPoint.X + SpaceX, oModelAnchorPoint.Y - SpaceY * 10, 0)
            oTextGraphics(12).Font = "ARIAL"
            oTextGraphics(12).FontSize = 18
            oTextGraphics(12).Bold = True
            oTextGraphics(12).HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextRight
            Call oTextGraphics(12).PutTextColor(255, 255, 0)
            oTextGraphics(12).VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextUpper
            Call oTextGraphics(12).SetTransformBehavior(oModelAnchorPoint, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)

            ' Update the view to see the text.
            Inv.ActiveView.Update()
            'Inv.ActiveView.Fit(True)
        End Sub

        Private Sub oInteractionEvents_OnTerminate() Handles oInteractionEvents.OnTerminate
            Dim oClientGraphics As ClientGraphics
            For Each oClientGraphics In Inv.ActiveEditObject.ClientGraphicsCollection
                oClientGraphics.Delete()
            Next
            Inv.ActiveView.Update()
        End Sub

 

Message 6 of 8
alewer
in reply to: smccoywm

Thanks!

Message 7 of 8

Sounds like I could use this. BUt I'm confused. Is this a VBA macro (I copied/pasted but can't get it to load) or am I missing something?

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 8 of 8

This is VB.net. I wrote it to be added to a VB.net add-in.

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

Post to forums  

Autodesk Design & Make Report