PART VIEW ORIENTATION - SET CURRENT VIEW AS TOP

PART VIEW ORIENTATION - SET CURRENT VIEW AS TOP

hEINSTEIN
Advocate Advocate
457 Views
7 Replies
Message 1 of 8

PART VIEW ORIENTATION - SET CURRENT VIEW AS TOP

hEINSTEIN
Advocate
Advocate

Good day

 

I use multi body part to create my assemblies. All the parts  view orientation is base on the base part.

 

I would like to find out if it would be possable to have a code that will rote the part to be horizontal and then set the current view as front?

 

this is what the part comes out as:

hEINSTEIN_1-1699798572470.png

 I want to look at to top surface:

hEINSTEIN_2-1699798634779.png

 

And then set the current view as top:

hEINSTEIN_3-1699798723677.png

 

is this possible?

 

0 Likes
458 Views
7 Replies
Replies (7)
Message 2 of 8

Andrii_Humeniuk
Advisor
Advisor

Hi @hEINSTEIN . In my work, I sometimes need to align the camera to the geometry of the part. This code constructs a RangeBox and selects the largest plane for the Front view. Try this code, it might be what you need.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 8

Michael.Navara
Advisor
Advisor

This is two tasks.

1) How to orient view to "top face"

You need to define how the face can be selected or located automatically.

Dim face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick planar face")
ThisDoc.Document.SelectSet.Select(face)
ThisApplication.CommandManager.ControlDefinitions("AppLookAtCmd").Execute

 

2) How to set current view orientation as top

This is easy using View.SetCurrentAsTop Method

ThisApplication.ActiveView.SetCurrentAsTop
'or
ThisDoc.Document.Views(1).SetCurrentAsTop

 

0 Likes
Message 4 of 8

hEINSTEIN
Advocate
Advocate

Thanx  @Andrii_Humeniuk 

 

This works for about 90% of my parts, which helps alot with my auto drawing creation.

 

One other thing I'm trying to achieve is getting the extent dimension for transport, I was hoping this will update with the rotation, so for parts thats at an angle extents dimensions (basicaly the envelope dims) are still extracted from the original rotation. Do you know if there is a solution for getting around this? 

 

hEINSTEIN_0-1700071785558.png

 

 

I want the extent dimensions to be taken from the current view orientation.

0 Likes
Message 5 of 8

Andrii_Humeniuk
Advisor
Advisor

The code creates 3 user parameters dLength(MAX), dWidth(MID), dHeight(MIN) (lines 60-65) with the dimensions of the entered box. I hope this is what you needed.

Public Sub Main()
	oAppInv = ThisApplication
	Dim oDoc As Document = oAppInv.ActiveDocument
	Dim oTM As TransactionManager = oAppInv.TransactionManager
	Dim oDocs As Documents = oAppInv.Documents
	Dim oVisDocs As DocumentsEnumerator = oDocs.VisibleDocuments
	Dim newTM As Transaction
	If TypeOf oDoc Is PartDocument Then
		newTM = oTM.StartTransaction(oDoc, "ChangePositionCamera")
		Call PackagingComponent(oDoc)
		newTM.End()
		oAppInv.CommandManager.ControlDefinitions.Item("AppZoomallCmd").Execute()
	Else If TypeOf oDoc Is AssemblyDocument Then
		Dim oADoc As AssemblyDocument = oDoc
		newTM = oTM.StartTransaction(oADoc, "ChangePositionCamera")
		For Each oRefDoc As Document In oADoc.AllReferencedDocuments
			If Not TypeOf oRefDoc Is PartDocument Or _
				Not oRefDoc.IsModifiable Then Continue For
			Dim oPartDoc As PartDocument = oRefDoc
			Dim oPartDef As ComponentDefinition = oPartDoc.ComponentDefinition
			If oPartDef.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Or _
				oPartDoc.DocumentInterests.HasInterest("{C6107C9D-C53F-4323-8768-F65F857F9F5A}") Or _
				oPartDoc.DocumentInterests.HasInterest("{4D39D5F1-0985-4783-AA5A-FC16C288418C}") Or _
				oPartDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") Or _
				oPartDoc.DocumentInterests.HasInterest("{BB8FE430-83BF-418D-8DF9-9B323D3DB9B9}") Then Continue For
			Dim bVisible As Boolean
			For Each oVisDoc As Document In oVisDocs
				If oVisDoc Is oPartDoc Then bVisible = True
			Next
			If bVisible Then
				oPartDoc.Activate()
				Call PackagingComponent(oPartDoc)
				oPartDoc.Save()
			Else
				Dim oVisDoc As Document = oDocs.Open(oPartDoc.FullDocumentName, True)
				Call PackagingComponent(oVisDoc)
				oVisDoc.Save()
				oVisDoc.Close()
			End If
			If Not oADoc.IsOpenExpress Then	oADoc.Activate()
		Next
		newTM.End()
	End If
End Sub

Dim oAppInv As Inventor.Application
Dim dLengths(2) As Double

Private Sub PackagingComponent(ByVal oPDoc As PartDocument)
	Dim oTG As TransientGeometry = oAppInv.TransientGeometry
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim minBox As OrientedBox = oPDef.SurfaceBodies.Item(1).OrientedMinimumRangeBox
	Dim oUofM As UnitsOfMeasure = oPDoc.UnitsOfMeasure
	Dim kUnits As UnitsTypeEnum = oUofM.LengthUnits
	dLengths(0) = minBox.DirectionOne.Length
	dLengths(1) = minBox.DirectionTwo.Length
	dLengths(2) = minBox.DirectionThree.Length
	Dim oLength, oHeight, oWidth As UserParameter
	Dim oUsParams As UserParameters = oPDef.Parameters.UserParameters
	Try : oUsParams("dLength").Value = dLengths.Max
	Catch : oUsParams.AddByValue("dLength", dLengths.Max, kUnits) : End Try
	Try : oUsParams("dWidth").Value = dLengths.Sum() -dLengths.Max - dLengths.Min
	Catch : oUsParams.AddByValue("dWidth", dLengths.Sum() -dLengths.Max - dLengths.Min, kUnits) : End Try
	Try : oUsParams("dHeight").Value = dLengths.Min
	Catch : oUsParams.AddByValue("dHeight", dLengths.Min, kUnits) : End Try
	Dim oVectorY As Vector = GetVectorY(minBox)
	If oVectorY Is Nothing Then Exit Sub
	Dim oVectorZ As Vector = GetVectorZ(minBox)
	If oVectorZ Is Nothing Then Exit Sub
	Dim oMaxPlane As Plane = oTG.CreatePlane(minBox.CornerPoint, oVectorZ)
	Call ChangeViewCam(oPDoc.Views.Item(1).Camera, oMaxPlane, oVectorY)
End Sub

Private Function ChangeViewCam(ByVal oCam As Camera, ByVal oPlane As Plane, ByVal oVector As Vector)
	Dim oPoint As Point = oCam.Target.Copy
	Call oPoint.TranslateBy(oPlane.Normal.AsVector())
	oCam.Eye = oPoint
	oCam.UpVector = oVector.AsUnitVector()
	Call oCam.ApplyWithoutTransition
	Call oCam.Parent.SetCurrentAsFront
End Function

Private Function GetVectorY(ByVal minBox As OrientedBox) As Vector
	Dim dMid As Double = dLengths.Sum() -dLengths.Max - dLengths.Min
	Select Case Round(dMid, 3)
	Case Round(minBox.DirectionOne.Length, 3) : Return minBox.DirectionOne
	Case Round(minBox.DirectionTwo.Length, 3) : Return minBox.DirectionTwo
	Case Round(minBox.DirectionThree.Length, 3) : Return minBox.DirectionThree
	End Select
	Return Nothing
End Function

Private Function GetVectorZ(ByVal minBox As OrientedBox) As Vector
	Select Case dLengths.Min
	Case minBox.DirectionOne.Length : Return minBox.DirectionOne
	Case minBox.DirectionTwo.Length : Return minBox.DirectionTwo
	Case minBox.DirectionThree.Length : Return minBox.DirectionThree
	End Select
	Return Nothing
End Function

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 6 of 8

hEINSTEIN
Advocate
Advocate

@Andrii_Humeniuk 

 

Do this code only add the parameters to the part files? And exclude the assemblies?

0 Likes
Message 7 of 8

Andrii_Humeniuk
Advisor
Advisor

@hEINSTEIN 

 

Yes, this code only adds parameters to parts. You can also run it in assemblies, then this code will run through all the parts in the assembly.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 8 of 8

hEINSTEIN
Advocate
Advocate

@Andrii_Humeniuk 

 

Is it possible to add the parameters to assemblies aswell?

0 Likes