Center Flat Pattern

Center Flat Pattern

Anonymous
Not applicable
391 Views
1 Reply
Message 1 of 2

Center Flat Pattern

Anonymous
Not applicable

Is there a way to center a formed view with a flat view in and Inventor drawing? I tried to center the views using iLogic, but the flat pattern is offset for some reason. Thanks

0 Likes
392 Views
1 Reply
Reply (1)
Message 2 of 2

ekinsb
Alumni
Alumni

I'm not sure what you want to center the view relative to.  The center of the sheet or something else.  Below is a simple VBA sample that demonstrates placing some view of a folded model and then places a view of the flat pattern.  It first calculates the center of the border and uses that as the position, then it calculates a point at a slight offset from the upper-left corner of the border and moves it there.  The position property of the drawing view is the center of the view so I'm also using the view width and height properties to get is positioned in the corner.

 

Public Sub AddAndPositionViews()
    Dim drawDoc As DrawingDocument
    Set drawDoc = ThisApplication.ActiveDocument
    Dim sht As Sheet
    Set sht = drawDoc.ActiveSheet
    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
    
    Dim filename As String
    filename = "C:\Temp\PunchTest.ipt"
    Dim sheetMetalDoc As PartDocument
    Set sheetMetalDoc = ThisApplication.Documents.Open(filename, False)
      
    Dim foldedFrontView As DrawingView
    Dim pstn As Point2d
    Set pstn = tg.CreatePoint2d(20, 10)
    Set foldedFrontView = sht.DrawingViews.AddBaseView(sheetMetalDoc, pstn, 1, kFrontViewOrientation, kHiddenLineDrawingViewStyle)
    
    Dim foldedRightView As DrawingView
    Set pstn = tg.CreatePoint2d(40, 10)
    Set foldedRightView = sht.DrawingViews.AddProjectedView(foldedFrontView, pstn, kHiddenLineDrawingViewStyle)
    
    Dim isoView As DrawingView
    Set pstn = tg.CreatePoint2d(40, 30)
    Set isoView = sht.DrawingViews.AddProjectedView(foldedFrontView, pstn, kHiddenLineRemovedDrawingViewStyle)
    
    Dim borderRange As Box2d
    Set borderRange = sht.Border.RangeBox
    Dim flatView As DrawingView
    Set pstn = tg.CreatePoint2d((borderRange.MinPoint.x + borderRange.MaxPoint.x) / 2, (borderRange.MinPoint.y + borderRange.MaxPoint.y) / 2)
    Dim options As NameValueMap
    Set options = ThisApplication.TransientObjects.CreateNameValueMap
    Call options.Add("SheetMetalFoldedModel", False)
    Set flatView = sht.DrawingViews.AddBaseView(sheetMetalDoc, pstn, 1, kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle, , , options)
    flatView.DisplayBendExtents = True
    
    MsgBox ("Center")
    
    Dim newPosition As Point2d
    Set newPosition = tg.CreatePoint2d(borderRange.MinPoint.x, borderRange.MaxPoint.y)
    newPosition.x = newPosition.x + flatView.Width / 2 + 1
    newPosition.y = newPosition.y - (flatView.Height / 2 + 1)
    flatView.Position = newPosition
End Sub

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes