Inventor Customization

Inventor Customization

Reply
Valued Contributor
smccoywm
Posts: 51
Registered: ‎09-29-2008
Message 1 of 8 (610 Views)
Accepted Solution

Display Bend Direction in Model Flat pattern

610 Views, 7 Replies
12-07-2011 01:25 PM

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

Solution.jpg

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

Valued Contributor
smccoywm
Posts: 51
Registered: ‎09-29-2008
Message 2 of 8 (597 Views)

Re: Display Bend Direction in Model Flat pattern

12-09-2011 01:58 PM in reply to: smccoywm

Solution.jpg

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

Mentor
alewer
Posts: 189
Registered: ‎08-15-2006
Message 3 of 8 (591 Views)

Re: Display Bend Direction in Model Flat pattern

12-09-2011 03:07 PM 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.

Valued Mentor
MegaJerk
Posts: 281
Registered: ‎01-26-2011
Message 4 of 8 (575 Views)

Re: Display Bend Direction in Model Flat pattern

12-11-2011 09:01 PM in reply to: alewer

I too would enjoy knowing the answer!

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Valued Contributor
smccoywm
Posts: 51
Registered: ‎09-29-2008
Message 5 of 8 (572 Views)

Re: Display Bend Direction in Model Flat pattern

12-12-2011 07:01 AM 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. :smileyhappy:

 

        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

 

Mentor
alewer
Posts: 189
Registered: ‎08-15-2006
Message 6 of 8 (565 Views)

Re: Display Bend Direction in Model Flat pattern

12-12-2011 08:26 AM in reply to: smccoywm

Thanks!

*Expert Elite*
brendan.henderson
Posts: 337
Registered: ‎07-22-2009
Message 7 of 8 (529 Views)

Re: Display Bend Direction in Model Flat pattern

01-10-2012 07:02 PM in reply to: smccoywm

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 2014 PDS Premium SP2 Update 2, Vault Professional 2014 Subs Release 1 & Update 1


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

Valued Contributor
smccoywm
Posts: 51
Registered: ‎09-29-2008
Message 8 of 8 (520 Views)

Re: Display Bend Direction in Model Flat pattern

01-11-2012 07:09 AM in reply to: brendan.henderson

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.