CUSTOM VIEW ORIENTATION ALTERNATIVE

CUSTOM VIEW ORIENTATION ALTERNATIVE

NOEL_GETTINGBYCZTUC
Advocate Advocate
970 Views
14 Replies
Message 1 of 15

CUSTOM VIEW ORIENTATION ALTERNATIVE

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Hi all, hopefully I'm not asking something that has been answered dozens of time before 😉

 

It quite obvious that using Custom View Orientation for parametrically modelled parts is a massive productivity killer. I.E. whenever the geometry changes and the face (or work plane) used for the custom view "Look At" changes angle relative to the view cube, the Custom Views need to updated manually.

Would it be possible to run an iLogic script to create/update a saved view orientation in the model based on a work plane named FRONT_VIEW_PLANE?

How would I also control the view rotation?

There's only a few dozen parts per assembly (out of 200+) that I need this on so I'd probably just run it at the part level triggered when the part geometry changes.

 

Thanks in advance!

Noel

0 Likes
Accepted solutions (2)
971 Views
14 Replies
Replies (14)
Message 2 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Anyone?

0 Likes
Message 3 of 15

Andrii_Humeniuk
Advisor
Advisor

Hi @NOEL_GETTINGBYCZTUC . You need to run this code in the drawing and select the desired view. If you have any questions, I will be happy to answer them.

Public Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oDDoc As DrawingDocument = oInvApp.ActiveDocument
	If oDDoc Is Nothing Then Exit Sub
	Dim oView As DrawingView
	oView = oInvApp.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View...")
	If oView Is Nothing Then Exit Sub
	If Not oView.ViewStyle = kShadedDrawingViewStyle Then
		Call oDDoc.SelectSet.Select(oView)
		call oInvApp.CommandManager.ControlDefinitions("DrawingUpdateViewComponentCmd").Execute
	End If
	Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oPlane As WorkPlane = TryCast(oDoc.ComponentDefinition.WorkPlanes("FRONT_VIEW_PLANE"), WorkPlane)
	If oPlane Is Nothing Then Exit Sub
    Dim oNormalEye As Inventor.Vector = oPlane.Plane.Normal.AsVector
    Dim oPosPoint As Point = Nothing
    Dim oPosVectorX As UnitVector = Nothing
    Dim oPosVectorY As UnitVector = Nothing
	oPlane.GetPosition(oPosPoint, oPosVectorX, oPosVectorY)	
	With oView.Camera
		.Target = oPosPoint
		oPosPoint.TranslateBy(oNormalEye)
	    .Eye = oPosPoint
	    .UpVector = oPosVectorY
		.ApplyWithoutTransition()
	End With	
End Sub

The biggest problem with such code is not understanding how to orient the view. Therefore, it is necessary to conduct tests on a real sample.

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 4 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Hi Andrii,

This seems to be on the right track, but since this requires the user to select a view, I can't see how it will work to keep the view oriented correctly when the geometry changes. Won't this script need to rerun every time the angular geometry changes?

 

Please see the example drawing below of a large conically rolled part with no flat sheet metal surfaces. It was modelled by deriving features from a skeletal reference model.

To display the part normal to the cone axis and as neatly as possible, I have created a plane to use for the Custom View Orientation > Look At reference.

Also shown is the part model in its Right orientation as modelled, which is obviously no good for the drawing.

Depending on the size of the assembly, this part's position and rotation will change relative to the origin planes.

NOEL_GETTINGBYCZTUC_2-1743555868388.png

 

 

NOEL_GETTINGBYCZTUC_1-1743554705834.png

 

My thought was to run a script in the model context to capture the plane and create a design view and camera position.

That design view and camera position could then be used in the drawing.

The script would be triggered to run any time the geometry changes so in theory the base view should automatically remain positioned as intended.

New assembly models are created by Copy Design and I don't want to have to update these part drawing views manually.

 

I've tried doing this with the help of ChatGPT (I'm not good at coding) with no luck.

 

Am I on the right track? Does anyone have a similar script they could share?

0 Likes
Message 5 of 15

Andrii_Humeniuk
Advisor
Advisor

Hi @NOEL_GETTINGBYCZTUC . You can place the following iLogic code in the part document and set up Event Triggers to fire when the part geometry changes. This code positions the camera on the FRONT_VIEW_PLANE plane and creates a new FRONT view. All you have to do is set up the DrawingView binding to the FRONT view cube.

Public Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
	If oPDoc Is Nothing Then Exit Sub
	Dim oPlane As WorkPlane = TryCast(oPDoc.ComponentDefinition.WorkPlanes("FRONT_VIEW_PLANE"), WorkPlane)
	If oPlane Is Nothing Then Exit Sub
	Dim oTG As Transaction = oInvApp.TransactionManager.StartTransaction(oPDoc, "Set Camera...")
	Dim oNormalEye As Inventor.Vector = oPlane.Plane.Normal.AsVector()
    Dim oPosPoint As Point = Nothing
    Dim oPosVectorX As UnitVector = Nothing
    Dim oPosVectorY As UnitVector = Nothing
	oPlane.GetPosition(oPosPoint, oPosVectorX, oPosVectorY)
	With oInvApp.ActiveView.Camera
		.Target = oPosPoint
		oPosPoint.TranslateBy(oNormalEye)
	    .Eye = oPosPoint
	    .UpVector = oPosVectorY
		.ApplyWithoutTransition()
		.Parent.SetCurrentAsFront()
	End With
	oTG.End()
End Sub

 Sometimes the new view is rotated 90 degrees, in which case you need to change line 17 to the following:

.UpVector = oPosVectorX

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 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Thanks Andrii,

I see that the script above is setting the view cube front to match the workplane and indeed seems to work well in the part context.
The problem I have is that the drawing templates I am using are using the XY plane as the Front  View Plane as determined by the Styles Editor > Standard > View Preference > Front View Plane setting.
I know I can change this setting on a case by case basis on my drawings but I am not in charge of the Styles themselves.

The other thing is that this setting change appears to only apply to new views, not to existing views meaning that I would have to redo a large amount of work to implement this fix.

 

Would it be possible to save the camera as a new model view named something like DWG_FRONT which can then be used on the existing base view?

This method works I just don't know the scripting required to create the model view.

NOEL_GETTINGBYCZTUC_0-1743580694164.png

 

0 Likes
Message 7 of 15

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

I liked your idea of ​​creating a new ViewRepresentation. So try the new code:

Public Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
	If oPDoc Is Nothing Then Exit Sub
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oPlane As WorkPlane = TryCast(oPDef.WorkPlanes(sNamePlane), WorkPlane)
	If oPlane Is Nothing Then Exit Sub
	If oPDoc.Dirty Then oPDoc.Update()
	Dim oTG As Transaction = oInvApp.TransactionManager.StartTransaction(oPDoc, "Set Camera...")
	Dim oNewView As DesignViewRepresentation
	Dim oActView As DesignViewRepresentation
	With oPDef.RepresentationsManager
		oActView = .ActiveDesignViewRepresentation
		Try : oNewView = .DesignViewRepresentations(sNameView)
		Catch : oNewView = .DesignViewRepresentations.Add(sNameView)
		End Try
	End With
	oNewView.Activate()
	Dim oNormalEye As Inventor.Vector = oPlane.Plane.Normal.AsVector()
    Dim oPosPoint As Point = Nothing
    Dim oPosVectorX As UnitVector = Nothing
    Dim oPosVectorY As UnitVector = Nothing
	oPlane.GetPosition(oPosPoint, oPosVectorX, oPosVectorY)
	With oNewView.Camera
		.Target = oPosPoint
		oPosPoint.TranslateBy(oNormalEye)
	    .Eye = oPosPoint
	    .UpVector = oPosVectorX
		.ApplyWithoutTransition()
	End With
	Try : oActView.Activate() : Catch : End Try
	oTG.End()
End Sub

Property sNamePlane As String = "FRONT_VIEW_PLANE"
Property sNameView As String = "DWG_FRONT"

Line 35 for the plane name, line 36 for the ViewRepresentation name.

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

Message 8 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Hi Andrii,

 

The script above works pretty well and I have marked it as accepted, thank you so much.
The only issue is how do I control the view rotation other than changing line 28 from  .UpVector = oPosVectorX to  .UpVector = oPosVectorY

Which obviously only gives 2 possible orientations out of 4 (8 if we include flipping the reference plane normal)

 

I can just use Rotate > Absolute in the drawing context to achieve that but any time I double click the view or edit the view the rotation returns to 0.0

I guess that this is because in the View definition I have the below options set. I can confirm that if I turn off the Camera View option that the view no longer returns to 0.0 rotation but that defeats the purpose of this exercise. 

 

NOEL_GETTINGBYCZTUC_0-1743653160937.png

 

Any ideas? Is there a particular trick to how I should orient my reference plane?

0 Likes
Message 9 of 15

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

You can get 4 directions as follows:

  1. oCamera.UpVector = oPosVectorX
  2. With oPosVectorX
    	Dim dCoors() As Double = {-.X, -.Y, -.Z }
    	.PutUnitVectorData(dCoors)	
    End With
    oCamera.UpVector = oPosVectorX
  3. oCamera.UpVector = oPosVectorY
  4. With oPosVectorY
    	Dim dCoors() As Double = {-.X, -.Y, -.Z }
    	.PutUnitVectorData(dCoors)	
    End With
    oCamera.UpVector = oPosVectorY

I also add the modernized iLogic code:

Public Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
	If oPDoc Is Nothing Then Exit Sub
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oPlane As WorkPlane = TryCast(oPDef.WorkPlanes(sNamePlane), WorkPlane)
	If oPlane Is Nothing Then Exit Sub
	If oPDoc.Dirty Then oPDoc.Update()
	Dim oTG As Transaction = oInvApp.TransactionManager.StartTransaction(oPDoc, "Set Camera...")
	Dim oNewView As DesignViewRepresentation
	Dim oActView As DesignViewRepresentation
	With oPDef.RepresentationsManager
		oActView = .ActiveDesignViewRepresentation
		If oActView.Name = sNameView Then
			oNewView = oActView
		Else
			Try : oNewView = .DesignViewRepresentations(sNameView)
			Catch : oNewView = .DesignViewRepresentations.Add(sNameView)
			End Try
		End If
	End With
	oNewView.Activate()
	Call SetCamera(oNewView.Camera, oPlane)
	Try : oActView.Activate() : Catch : End Try
	oTG.End()
End Sub

Property sNamePlane As String = "FRONT_VIEW_PLANE"
Property sNameView As String = "DWG_FRONT"

Private Function SetCamera(ByVal oCamera As Camera, ByVal oPlane As WorkPlane)
	Dim oNormalEye As Inventor.Vector = oPlane.Plane.Normal.AsVector()
    Dim oPosPoint As Point = Nothing
    Dim oPosVectorX As UnitVector = Nothing
    Dim oPosVectorY As UnitVector = Nothing
	oPlane.GetPosition(oPosPoint, oPosVectorX, oPosVectorY)
	oCamera.Target = oPosPoint
	oPosPoint.TranslateBy(oNormalEye)
    oCamera.Eye = oPosPoint
'	With oPosVectorY
'		Dim dCoors() As Double = {-.X, -.Y, -.Z }
'		.PutUnitVectorData(dCoors)	
'	End With
	oCamera.UpVector = oPosVectorY
	oCamera.ApplyWithoutTransition()
End Function

For DrawingView, add the Fixed setting to View Justification:

Andrii_Humeniuk_0-1743748685135.png

But this still doesn't update the view automatically, I suspect I need to add some code to update the views in the drawing document.

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 10 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Hi Andrii, this seems to work well, thanks so much for your help.
I think it should be relatively easy to create a script to update the base views of the related drawings; I'll have a play and see how I go.

 

P.S. I added your 4 subscripts to the Rule it make commenting in/out easier, see below.

 

Thanks again,

Noel

 

Public Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
	If oPDoc Is Nothing Then Exit Sub
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oPlane As WorkPlane = TryCast(oPDef.WorkPlanes(sNamePlane), WorkPlane)
	If oPlane Is Nothing Then Exit Sub
	If oPDoc.Dirty Then oPDoc.Update()
	Dim oTG As Transaction = oInvApp.TransactionManager.StartTransaction(oPDoc, "Set Camera...")
	Dim oNewView As DesignViewRepresentation
	Dim oActView As DesignViewRepresentation
	With oPDef.RepresentationsManager
		oActView = .ActiveDesignViewRepresentation
		If oActView.Name = sNameView Then
			oNewView = oActView
		Else
			Try : oNewView = .DesignViewRepresentations(sNameView)
			Catch : oNewView = .DesignViewRepresentations.Add(sNameView)
			End Try
		End If
	End With
	oNewView.Activate()
	Call SetCamera(oNewView.Camera, oPlane)
	Try : oActView.Activate() : Catch : End Try
	oTG.End()
End Sub

Property sNamePlane As String = "FRONT_VIEW_PLANE"
Property sNameView As String = "DWG_FRONT"

Private Function SetCamera(ByVal oCamera As Camera, ByVal oPlane As WorkPlane)
	Dim oNormalEye As Inventor.Vector = oPlane.Plane.Normal.AsVector()
    Dim oPosPoint As Point = Nothing
    Dim oPosVectorX As UnitVector = Nothing
    Dim oPosVectorY As UnitVector = Nothing
	oPlane.GetPosition(oPosPoint, oPosVectorX, oPosVectorY)
	oCamera.Target = oPosPoint
	oPosPoint.TranslateBy(oNormalEye)
    oCamera.Eye = oPosPoint
'-----------------------------------
''	Comment out 3 of the following 4 to achieve the desired camera view orientation
'-----------------------------------
''Y Positive
'		oCamera.UpVector = oPosVectorY
'-----------------------------------
'Y Negative
		With oPosVectorY
			Dim dCoors() As Double = {-.X, -.Y, -.Z }
			.PutUnitVectorData(dCoors)	
		End With
		oCamera.UpVector = oPosVectorY
'-----------------------------------
''X Positive
'		oCamera.UpVector = oPosVectorX
'-----------------------------------
''X Negative
'		With oPosVectorX
'			Dim dCoors() As Double = {-.X, -.Y, -.Z }
'			.PutUnitVectorData(dCoors)	
'		End With
'		oCamera.UpVector = oPosVectorX
'-----------------------------------
	oCamera.ApplyWithoutTransition()
End Function

 

Message 11 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Regarding updating the base views in the drawing; here is a script to do that (credit to ChatGPT), though I might get rid of the Message Boxes to prevent unnecessary user input.

 

' Ensure we're in a drawing document
If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MessageBox.Show("Please run this from a drawing document.", "Wrong Document Type")
Return
End If

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

For Each oSheet As Sheet In oDrawDoc.Sheets
For Each oView As DrawingView In oSheet.DrawingViews
' Base views have no parent
If oView.ParentView Is Nothing Then
Try
' Store original scale
Dim origScale As Double = oView.Scale

' Slightly change the scale to force refresh
oView.Scale = origScale * 1.001

' Set it back
oView.Scale = origScale
Catch ex As Exception
MessageBox.Show("Failed to force-update base view: " & oView.Name & vbCrLf & ex.Message)
End Try
End If
Next
Next

InventorVb.DocumentUpdate()

MessageBox.Show("Base views were force-updated successfully.", "Done")

0 Likes
Message 12 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

All this to get Inventor to do something (parametric custom views based on geometry) that other CADs (Creo, SolidWorks, etc) do out of the box.
Thanks Autodesk 😬

0 Likes
Message 13 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Hi all, I just realised that setting the base view to import the saved camera is not possible if the view has a child detail or section view.

If I create the view, set the design view to DWG_FRONT + Associative + Camera it works fine.

If I then go and add a detail view or section view from that base view, the Camera option deactivates and is greyed out which makes this whole process a waste of time.

Or if the view is already existing and has a child detail or section view and I try to set the design view as above, the Camera option is greyed out to start with.

 

I know this is more of a general Inventor question than an iLogic question, but does anyone know a solution for this?

I'm not sure if this is a glitch or not but if it is working as intended I'd suggest that AutoDesk should make this behaviour optional in the application settings.

 

NOEL_GETTINGBYCZTUC_0-1753783818265.png

 

0 Likes
Message 14 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

It seems that the behaviour above is as intended by Inventor.

The only solution therefore is to not do those detail or section views off the DWG_FRONT saved view.
Oh well.

0 Likes
Message 15 of 15

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Now onto the next problem, now that this rule is embedded into many of my parts and is being rolled out to other users, we're noticing a couple of issues.

 

1. When the parts are checked-in, this is causing multiple error messages to pop up when working on my skeleton.
Now the obvious answer would be to check everything out while working but that is not always possible when working in a team.
So would it be possible to add an exit loop to stop the script if the part is read-only?

 

2. When the part is saved in-context, the DWG_FRONT view gets resaved in the current on-screen orientation.
So I figure that the DWG_FRONT view needs to be locked after creation, however that causes the script to fail.
So, we need a way to find and unlock the DWG_FRONT view before creating/updating it and then lock it again afterwards.


@Andrii_Humeniuk, any chance you could help me out? I just know if I try doing this myself or with the help of ChatGPT that it'll chew up a big chunk of my time and I'm snowed under at the moment.

Thanks in advance.

Here's the current script:

Public Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
	If oPDoc Is Nothing Then Exit Sub
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oPlane As WorkPlane = TryCast(oPDef.WorkPlanes(sNamePlane), WorkPlane)
	If oPlane Is Nothing Then Exit Sub
	If oPDoc.Dirty Then oPDoc.Update()
	Dim oTG As Transaction = oInvApp.TransactionManager.StartTransaction(oPDoc, "Set Camera...")
	Dim oNewView As DesignViewRepresentation
	Dim oActView As DesignViewRepresentation
	With oPDef.RepresentationsManager
		oActView = .ActiveDesignViewRepresentation
		If oActView.Name = sNameView Then
			oNewView = oActView
		Else
			Try : oNewView = .DesignViewRepresentations(sNameView)
			Catch : oNewView = .DesignViewRepresentations.Add(sNameView)
			End Try
		End If
	End With
	oNewView.Activate()
	Call SetCamera(oNewView.Camera, oPlane)
	Try : oActView.Activate() : Catch : End Try
	oTG.End()
End Sub

Property sNamePlane As String = "FRONT_VIEW_PLANE"
Property sNameView As String = "DWG_FRONT"

Private Function SetCamera(ByVal oCamera As Camera, ByVal oPlane As WorkPlane)
	Dim oNormalEye As Inventor.Vector = oPlane.Plane.Normal.AsVector()
    Dim oPosPoint As Point = Nothing
    Dim oPosVectorX As UnitVector = Nothing
    Dim oPosVectorY As UnitVector = Nothing
	oPlane.GetPosition(oPosPoint, oPosVectorX, oPosVectorY)
	oCamera.Target = oPosPoint
	oPosPoint.TranslateBy(oNormalEye)
    oCamera.Eye = oPosPoint
'-----------------------------------
''	Comment out 3 of the following 4 to achieve the desired camera view orientation
'-----------------------------------
''Y Positive
'		oCamera.UpVector = oPosVectorY
'-----------------------------------
''Y Negative
'		With oPosVectorY
'			Dim dCoors() As Double = {-.X, -.Y, -.Z }
'			.PutUnitVectorData(dCoors)	
'		End With
'		oCamera.UpVector = oPosVectorY
'-----------------------------------
''X Positive
'		oCamera.UpVector = oPosVectorX
'-----------------------------------
'X Negative
		With oPosVectorX
			Dim dCoors() As Double = {-.X, -.Y, -.Z }
			.PutUnitVectorData(dCoors)	
		End With
		oCamera.UpVector = oPosVectorX
'-----------------------------------
	oCamera.ApplyWithoutTransition()
End Function

 

0 Likes