Set Section view orientation in iLogic

Set Section view orientation in iLogic

Kai_S_SR
Participant Participant
139 Views
2 Replies
Message 1 of 3

Set Section view orientation in iLogic

Kai_S_SR
Participant
Participant

Hi,

I have an issue with the automatic creation of sections in a drawing.
The script I created will create a section when I click on the main view and draws it at a defined position on the sheet. The next section will then be placed a few centimeters away.

This works as intended, but after a few sections the orientation of the sections will suddely switch (from left to right for example).
As shown in this picture. Section C should also show to the left.

Screenshot 2026-09-21 123657.png

How can I set up the section creation, so that they always view to the left side of the sheet.

Here my code:

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oDDoc As DrawingDocument = TryCast(oInvApp.ActiveDocument, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then
		MessageBox.Show("Rule named '" & iLogicVb.RuleName & "' did not run because no Drawing obtained!", _
		"No Active Drawing", MessageBoxButtons.OK, MessageBoxIcon.Stop)
		'Logger.Debug("Rule named '" & iLogicVb.RuleName & "' did not run because no Drawing obtained!")
		Return
	End If
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oDViews As Inventor.DrawingViews = oSheet.DrawingViews
	
	For Each oView As DrawingView In oSheet.DrawingViews
		If oView.ViewType = DrawingViewTypeEnum.kSectionDrawingViewType Then
			Try : oView.Delete : Catch : End Try
		End If
	Next
	
	For Each oView As DrawingView In oSheet.DrawingViews
		For Each oSketchold As DrawingSketch In oView.Sketches
			Try : oView.Sketches.Item(oSketchold.Name).Delete : Catch : End Try
		Next
	Next
	
	Dim oFrontView As DrawingView = oSheet.DrawingViews.Item(1) 
	Dim oModelDocBase As Inventor.Document = oFrontView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oXYPlaneBase As Inventor.WorkPlane = oModelDocBase.ComponentDefinition.WorkPlanes.Item(3)
	oFrontView.SetVisibility(oXYPlaneBase, True)

	Dim i As Integer
	Dim m As Integer
	Dim n As Integer
	Dim x As Integer
	
	m = 7 'Y coordinate on sheet for section placement
	n = 5
	x = 1
		
	For i = 1 To 6
		'prompt the user to 'Pick' the 'Parent View'
		Dim oParentView As Inventor.DrawingView = oInvApp.CommandManager.Pick( _
		SelectionFilterEnum.kDrawingViewFilter, "Pick Parent Drawing View")
		'if nothing was selected, then exit this rule
		If oParentView Is Nothing Then Return
		
		'here we are creating an 'instance' of the custom Class
		'and supplying a reference to the currently running Inventor.Application object
		Dim oMouseClick As New MouseClickCls(oInvApp)
		'here we are calling its Public Function to run
		'it will pause this rule, allow manual click, capture it, and return it, and unpause this rule
		Dim oP3D As Inventor.Point = oMouseClick.GetMouseClickModelPoint()
		
		'it returns a 3D point in model space, so convert it to a 2D point by eliminating the Z coordinate
		Dim oP2D As Inventor.Point2d = oInvApp.TransientGeometry.CreatePoint2d(oP3D.X, oP3D.Y)

		Dim oCent As Point2d
		
		Dim oDist As Point2d
		oDist = ThisApplication.TransientGeometry.CreatePoint2d(oP2D.X - oParentView.Center.X, oP2D.Y - oParentView.Center.Y )

		
		Dim oSketch As Inventor.DrawingSketch
		Dim oDC As Inventor.DrawingCurve
		
		oSketch = oParentView.Sketches.Add
		
		oSketch.Edit
			Dim oTG As TransientGeometry
			oTG = ThisApplication.TransientGeometry
			
			Dim oConv As Double = 1 / oParentView.Scale
			Dim oCenter As Double = oParentView.Center.Y
			Dim oHeight As Double = oParentView.Height / 1
			
			Dim oX As Double = oDist.X * oConv
			Dim oY1 As Double =  oHeight * oConv - 20
			Dim oY2 As Double =  - oHeight * oConv + 20
			
			Dim oPointA As Point2d
			oPointA = ThisApplication.TransientGeometry.CreatePoint2d(oX, oY1)
			
			Dim oPointB As Point2d
			oPointB = ThisApplication.TransientGeometry.CreatePoint2d(oX, oY2)
			
			Dim oLine As SketchLine
			
			oLine = oSketch.SketchLines.AddByTwoPoints(oPointA, oPointB)
		
		oSketch.ExitEdit
		
		Dim DPPV As Double = (m) 
		Dim DPPH As Double = (n)

		Dim oDPP As Point2d 
	        oDPP = ThisApplication.TransientGeometry.CreatePoint2d(DPPH, DPPV) 
		Dim oLPP = ThisApplication.TransientGeometry.CreatePoint2d(DPPH, 12.5) 'Height of Lable for section
		
		Dim oScale = 1 / 30
		
		Dim SectionView As Inventor.SectionDrawingView
		SectionView = oSheet.DrawingViews.AddSectionView(oParentView, oSketch, oDPP, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, oScale, , SectionViewName, , False, 50)
		SectionView.Aligned = False 
		SectionView.Center = oDPP 
		SectionView.Label.ConstrainToBorder = False
		SectionView.ReverseDirection
		
		Dim oModelDoc As Inventor.Document = SectionView.ReferencedDocumentDescriptor.ReferencedDocument
		Dim oXYPlane As Inventor.WorkPlane = oModelDoc.ComponentDefinition.WorkPlanes.Item(3)
		SectionView.SetVisibility(oXYPlane, True)
		
		Dim SheetY As Double = 6.0 'height of ground plane of section from bottom of sheet
		
		Dim Y1 As Double = SectionView.ModelToSheetSpace(oXYPlane.Plane.RootPoint).Y
		SectionView.Position = ThisApplication.TransientGeometry.CreatePoint2d(SectionView.Position.X, SectionView.Position.Y + (SheetY - Y1))
		SectionView.Label.Position = oLPP
		SectionView.Name = num2Letter(x)
		
		n = n + 5
		x = x + 1
	Next	
	m = m - 5
	n = 5
	Exit Sub
End Sub



0 Likes
Accepted solutions (1)
140 Views
2 Replies
Replies (2)
Message 2 of 3

Ivan_Sinicyn
Collaborator
Collaborator
Accepted solution

Hi,

Why the direction flips

`AddSectionView` has no direction argument. Inventor derives the view direction from the `Position` point you pass it — specifically from which side of the section line that point falls on, exactly like the interactive command does when you drag the preview across the line. The arrows always point away from where the view is placed: a view dropped to the left of the section line looks right, and vice versa.

The switch is sharp, right at the line. I measured it on Inventor 2026 with the section line at sheet X = 42.0 cm:

| Section line (sheet) | Position passed in | Resulting direction |
| 42.0 | 41.9 | looks right |
| 42.0 | 42.1 | looks left |

Two things that do not matter, in case you suspected them: the direction of the sketch line itself (top→bottom vs bottom→top gives identical results), and the drafting standard's projection angle (`FirstAngleProjection`).

In your rule the section lines land wherever the user clicked, while the placement points march left to right at a fixed step (`n = 5, 10, 15, 20, 25, 30`). As soon as a placement point overtakes its own section line, that view is created facing the other way. I reproduced your exact picture with 6 sections: A–D looked one way, E and F flipped.

The second half of the bug

`SectionDrawingView.ReverseDirection` is a method — a pure toggle, not a settable property, and there is no getter for the current direction. Calling it unconditionally after every creation just inverts whatever Inventor chose, so an already inconsistent set stays inconsistent.

Also worth knowing: the direction is baked in at creation. Setting `Aligned = False` and then `Center` moves the view anywhere you like without touching its direction.

The fix

Create the view on a fixed side of the section line, then park it where you actually want it. Your section line sits exactly at `oP2D.X` on the sheet, so seeding the view a couple of centimetres to the right of it always produces a view that looks left:

 

' the section line sits at oP2D.X on the sheet; seeding the view 2 cm to the
' RIGHT of it always produces a view that looks LEFT
Dim oSeedPos As Point2d = oInvApp.TransientGeometry.CreatePoint2d( _
oP2D.X + 2, oParentView.Center.Y)

Dim SectionView As Inventor.SectionDrawingView
SectionView = oSheet.DrawingViews.AddSectionView(oParentView, oSketch, oSeedPos, _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle, oScale, , SectionViewName, , False, 50)

' do NOT call SectionView.ReverseDirection any more
SectionView.Aligned = False
SectionView.Center = oDPP



Everything after that in your loop stays as it is. Keep the seed offset non-zero — a `Position` landing exactly on the line is a silent tie-break.

If you ever need it to be bulletproof

For a rotated parent view or a non-vertical section line, ask the view which way it looks and flip only when it is wrong:

If LookDirectionX(SectionView, oParentView) > 0 Then SectionView.ReverseDirection()

' Sheet-space X component of the direction a section view looks in, measured through
' its parent view. Negative = the view looks to the LEFT of the sheet, positive = right.
Function LookDirectionX(oSecView As SectionDrawingView, oParentView As DrawingView) As Double
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oM As Matrix = oSecView.DrawingViewToModelTransform
' third column is the view's +Z in model space, pointing at the viewer,
' so the camera looks along its negative
Dim dx As Double = -oM.Cell(1, 3)
Dim dy As Double = -oM.Cell(2, 3)
Dim dz As Double = -oM.Cell(3, 3)
Dim oFrom As Point2d = oParentView.ModelToSheetSpace(oTG.CreatePoint(0, 0, 0))
Dim oTo As Point2d = oParentView.ModelToSheetSpace(oTG.CreatePoint(dx, dy, dz))
Return oTo.X - oFrom.X
End Function

 

INV 2026.4
0 Likes
Message 3 of 3

Kai_S_SR
Participant
Participant

Many thanks!
It seems to work

0 Likes