Set Section view orientation in iLogic

Set Section view orientation in iLogic

Kai_S_SR
Participant Participant
34 Views
0 Replies
Message 1 of 1

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 it up, the sections are 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
35 Views
0 Replies
Replies (0)