iLogic View Chopper

I was looking through the Inventor API samples and I came across some code for applying “Break Views” in the Inventor drawing environment. The API sample works quite well, so I thought I would adapt it to work with iLogic and add some additional functionality to make it more useful. My code adds in view selection and options for Horizontal/Vertical breaks, with size options, as well as some error trapping.

Below is an animation of my iLogic code in action, at the bottom of this post, there is a simpler version of the code too.

Click me for high res version

Here is the iLogic Code:

'This iLogic code by @ClintBrown3D, originally posted at https://clintbrown.co.uk/ilogic-view-chopper
On Error GoTo ClintsErrorTrapper :

Dim ChopType As New ArrayList : ChopType.Add("Horizontal (||)") : ChopType.Add("Vertical (=)")
ChopSelect = InputListBox("Pick a Type", ChopType, ChopSelect, Title := "@ClintBrown3D", ListName := "Break Types")

Dim SizeOfChop As New ArrayList : SizeOfChop.Add("Small") : SizeOfChop.Add("Medium") : SizeOfChop.Add("Large")
ChopSize = InputListBox("Pick a Size", SizeOfChop, d0, Title := "@ClintBrown3D", ListName := "Sizes")
If ChopSize = "Small" Then : ZZZ = 1 : End If : If ChopSize = "Medium" Then : ZZZ = 3 : End If : If ChopSize = "Large" Then : ZZZ = 8 : End If
If ChopSelect = "Horizontal (||)" Then : GoTo oHorizontal : End If : If ChopSelect = "Vertical (=)" Then : GoTo oVertical : End If

'-------------------------------------------------------------------------------------------------------------------
Dim oDrawDoc As DrawingDocument ' Set a reference to the drawing document. This assumes a drawing document is active.
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet 'Set a reference to the active sheet.
Dim oDrawingView As DrawingView ' Set a reference to the selected drawing. This assumes that the selected view is not a draft view.
Dim oCenter As Point2d ' Set a reference to the center of the base view.
Dim oStartPoint As Point2d' Define the start point of the break
Dim oEndPoint As Point2d' Define the end point of the break
Dim oBreakOperation As BreakOperation ' Define the end point of the break

'---------------------------------------------------------------------------------------------
oHorizontal :
oViewSelect = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view to chop  : @ClintBrown3D")
oDrawDoc = ThisApplication.ActiveDocument
oSheet = oDrawDoc.ActiveSheet
oDrawingView = oViewSelect
oCenter = oDrawingView.Center

' Define the start point of the break
oStartPoint = ThisApplication.TransientGeometry.CreatePoint2d(oCenter.X - ZZZ, oCenter.Y)

'Dim oEndPoint As Point2d
oEndPoint = ThisApplication.TransientGeometry.CreatePoint2d(oCenter.X + ZZZ, oCenter.Y)

'Dim oBreakOperation As BreakOperation
oBreakOperation = oDrawingView.BreakOperations.Add(kHorizontalBreakOrientation, oStartPoint, oEndPoint, kStructuralBreakStyle, 5) 'kRectangularBreakStyle
Return
'---------------------------------------------------------------------------------------------
oVertical :
oViewSelect = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view to chop  : @ClintBrown3D")
oDrawDoc = ThisApplication.ActiveDocument
oSheet = oDrawDoc.ActiveSheet
oDrawingView = oViewSelect
oCenter = oDrawingView.Center
oStartPoint = ThisApplication.TransientGeometry.CreatePoint2d(oCenter.X, oCenter.Y - ZZZ)
oEndPoint = ThisApplication.TransientGeometry.CreatePoint2d(oCenter.X, oCenter.Y + ZZZ)
oBreakOperation = oDrawingView.BreakOperations.Add(kVerticalBreakOrientation, oStartPoint, oEndPoint, kStructuralBreakStyle, 5) 'kRectangularBreakStyle
Return
'---------------------------------------------------------------------------------------------
ClintsErrorTrapper :
MessageBox.Show("Oops - Something went wrong!" & vbNewLine & vbNewLine & "Make sure you are in a drawing" & vbNewLine & "You cannot use the same chop type twice", "@UNOFFICIAL INVENTOR")

The first version of the code that I wrote was very simple, it used the API sample for a horizontal break, but I topped and tailed it with an input selection and some error trapping.

Below is a basic version of the code:

'This iLogic code by @ClintBrown3D, originally posted at https://clintbrown.co.uk/ilogic-view-chopper
'-------------------------------------------------------------------------------------------------------------------
Dim oViewSelect As DrawingView
oViewSelect = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view to chop  : @ClintBrown3D")

On Error GoTo ClintsErrorTrapper:
'-------------------------------------------------------------------------------------------------------------------
' Set a reference to the drawing document. This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
'Set a reference to the active sheet.
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

' Set a reference to the selected drawing. This assumes that the selected view is not a draft view.
Dim oDrawingView As DrawingView

oDrawingView = oViewSelect

' Set a reference to the center of the base view.
Dim oCenter As Point2d
oCenter = oDrawingView.Center

' Define the start point of the break
Dim oStartPoint As Point2d
oStartPoint = ThisApplication.TransientGeometry.CreatePoint2d(oCenter.X - 1, oCenter.Y)

' Define the end point of the break
Dim oEndPoint As Point2d
oEndPoint = ThisApplication.TransientGeometry.CreatePoint2d(oCenter.X + 1, oCenter.Y)

Dim oBreakOperation As BreakOperation
'oBreakOperation = oDrawingView.BreakOperations.Add(kHorizontalBreakOrientation, oStartPoint, oEndPoint, kRectangularBreakStyle, 5)
oBreakOperation = oDrawingView.BreakOperations.Add(kHorizontalBreakOrientation, oStartPoint, oEndPoint, kStructuralBreakStyle, 5)

Return
ClintsErrorTrapper :
MessageBox.Show("Oops - Something went wrong!" & vbNewLine & vbNewLine & "Make sure you are in a drawing" & vbNewLine & "You cannot use the same chop type twice", "@UNOFFICIAL INVENTOR")

Notes:

This version of the code was tested with Inventor 2021. Please note that I cannot offer any additional support, this blog post is offered as-is, and is aimed at the more advanced user.

As always, please test all iLogic code extensively on non-production files. Do not use any code in a production environment until you have thoroughly tested it and have verified that it works as expected. Always back up any data before running any experimental code.