Rotate a drawing view based on 3D sketch lines

Rotate a drawing view based on 3D sketch lines

ewu9
Enthusiast Enthusiast
422 Views
2 Replies
Message 1 of 3

Rotate a drawing view based on 3D sketch lines

ewu9
Enthusiast
Enthusiast

Hi iLogic people,

I have parts that I'm trying to display on the drawing sheets aligned to their minimum bounding boxes - which I have drawn as 3D lines in the part itself. Now I'd like to rotate them so that the rectangle is orthogonal in the base view, regardless of how the part is oriented. (Looking to automatically convert from view 1 to view 5)

ewu9_0-1710968468474.png

 

I considered accessing the rotate function, and then selecting the longest edge (any of the 4 would do), the problem is that the sketchlines can't be selected. Alternatively I've tried to measure the angle between the sketchline and the horizontal, except I'm not sure how to access a horizontal on drawing view. Any ideas would be appreciated. Thanks


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

ewu9
Enthusiast
Enthusiast
Accepted solution

Figured it out in case anyone else is looking to do this. 

The block before "combinedbodies.orientedMinimumRangeBox" is from here.



Sub Main()
Dim oApp As Inventor.Application
oApp = ThisApplication

Dim oActiveSheet As Sheet
oActiveSheet = oApp.ActiveDocument.ActiveSheet

Dim oBaseView As DrawingView
oBaseView = oActiveSheet.DrawingViews.Item(1)

Dim oDoc As Document = oBaseView.ReferencedDocumentDescriptor.ReferencedDocument

If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	' Get the current Part document.
	Dim partDoc As PartDocument = oBaseView.ReferencedDocumentDescriptor.ReferencedDocument
	
	' Get the TransientBRep and TransientGeometry objects.
	Dim transBRep As TransientBRep = oApp.TransientBRep
	Dim transGeom As TransientGeometry = oApp.TransientGeometry
	
	' Combine all bodies in Part into a single transient Surface Body.
	Dim combinedBodies As SurfaceBody = Nothing
	For Each surfBody As SurfaceBody In partDoc.ComponentDefinition.SurfaceBodies
		If combinedBodies Is Nothing Then
			combinedBodies = transBRep.Copy(surfBody)
		Else
			transBRep.DoBoolean(combinedBodies, surfBody, BooleanTypeEnum.kBooleanTypeUnion)
		End If
	Next
	' Get the oriented minimum range box of all bodies in Part.
	' NOTE: "OrientedMinimumRangeBox" was added in Inventor 2020.3/2021.
	Dim minBox As OrientedBox = combinedBodies.OrientedMinimumRangeBox
	
	' Get the corner points of the oriented minimum range box.
	Dim cornerPoints As Point() = {
	    transGeom.CreatePoint(minBox.CornerPoint.X + minBox.DirectionOne.X, minBox.CornerPoint.Y + minBox.DirectionOne.Y, minBox.CornerPoint.Z + minBox.DirectionOne.Z),
	    transGeom.CreatePoint(minBox.CornerPoint.X + minBox.DirectionOne.X + minBox.DirectionTwo.X, minBox.CornerPoint.Y + minBox.DirectionOne.Y + minBox.DirectionTwo.Y, minBox.CornerPoint.Z + minBox.DirectionOne.Z + minBox.DirectionTwo.Z)
		}
	
	Dim Horiz As Point() = {
	    transGeom.CreatePoint(minBox.CornerPoint.X + minBox.DirectionOne.X + minBox.DirectionOne.X, minBox.CornerPoint.Y + minBox.DirectionOne.Y, minBox.CornerPoint.Z + minBox.DirectionOne.Z)}
	
	angle = ThisApplication.MeasureTools.GetAngle(cornerpoints(1), cornerpoints(0), Horiz(0))
	'MessageBox.Show(angle)

	'True = Clockwise
	oBaseView.RotateByAngle(angle, True)
Else 
	MessageBox.Show("Reference is not a part document")
End If
oActiveSheet.Update()
End Sub

 

0 Likes
Message 3 of 3

Michael.Navara
Advisor
Advisor

You don't need to construct 3D sketch of minimum range box, it is not necessary.

For orientation of drawing view it is the best way to set properties of the Camera of the Drawing view.

 

This sample expects the drawing sheet with the first view from part.

Dim drw As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = drw.ActiveSheet
Dim view1 As DrawingView = sheet.DrawingViews(1)

Dim part As PartDocument = view1.ReferencedDocumentDescriptor.ReferencedDocument
Dim box As OrientedBox = part.ComponentDefinition.OrientedMinimumRangeBox

'Prepare camera parameters
Dim target As Point = box.CornerPoint
Dim eye As Point = box.CornerPoint
eye.TranslateBy(box.DirectionOne)
Dim upVector As UnitVector = box.DirectionTwo.AsUnitVector()

'Set camera of the drawing view
Dim camera As Camera = view1.Camera
camera.Eye = eye
camera.Target = target
camera.UpVector = upVector
camera.Apply()

 

0 Likes