Locking Top View Perpendicular to Part Face Or Updating Via Ilogic

Locking Top View Perpendicular to Part Face Or Updating Via Ilogic

werft60
Contributor Contributor
1,528 Views
5 Replies
Message 1 of 6

Locking Top View Perpendicular to Part Face Or Updating Via Ilogic

werft60
Contributor
Contributor

Hello, 

 

I have created a parametric assembly that changes the angle of some parts within the assembly as dimensions change (See attached pictures). To avoid complicated trigonometry I've designed the angled faces in a way that allows me to not have to know the angle of the miters. However when an overall assembly dimension changes it causes the angled face to physically change angles in its part file. This in turn throws off the camera view on the specific part. 

 

What I'm looking to do is to lock the top view of the part perpendicular to a specific face. Or if that isn't possible then find a way to update it with iLogic automatically. 

 

Apologies, this is somewhat complicated to explain. I hope my description and attached photos are enough to understand what I'm trying to accomplish. I've attached a photo of the full assembly, the three angled faces are the ones that this situation applies to. I've also attached photos of a drawings views when the view if properly perpendicular to the part vs what it looks like after the dimensions of the assembly are changed. 

 

Thank you in advance.

0 Likes
Accepted solutions (2)
1,529 Views
5 Replies
Replies (5)
Message 2 of 6

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

If you create a named face "MyFront" in your part the following script can rotate your base view.

To assign a name to a face, right click on the face in part environment and select "Assign name" from context menu.

The script assumes that the first drawing view in your active drawing sheet is the one we need. This is just to show you how it works. I omit most of prechecksto prevent crashes. Please save your work and test with a backup copy.

If there are several sheets and base views, you have to tell how they should be handled.

 

Option Explicit on
Dim oDrawDoc As DrawingDocument=ThisDoc.Document
Dim oPartDoc As PartDocument = oDrawDoc.ReferencedDocuments(1)
Dim oNamedEntities As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPartDoc)
Dim oFace As Face=oNamedEntities.FindEntity("MyFront")

If oFace Is Nothing Then
    MsgBox("Named face 'MyFront' not found or more than one named face 'MyFront' found. Exit", vbCritical, "ReSetViewDirection")
    Exit Sub
End If

Dim oPlane As Plane= oFace.Geometry
Dim oDrawView As DrawingView = oDrawDoc.ActiveSheet.DrawingViews(1)
Dim oCam As Camera = oDrawView.Camera

' Set Eye or Target
Dim oPoint As Point
If oFace.IsParamReversed Then
    oPoint = oCam.Eye.Copy
    Call oPoint.TranslateBy(oPlane.Normal.AsVector())
    oCam.Target = oPoint
Else
    oPoint = oCam.Target.Copy
    Call oPoint.TranslateBy(oPlane.Normal.AsVector())
    oCam.Eye = oPoint
End If

Call oCam.ApplyWithoutTransition

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 6

werft60
Contributor
Contributor
Accepted solution

Hello Krieg,

 

Thank you for your response, I've figured it out! Using your post and a thread found here: 

 

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-make-specific-view-set-current-v...

 

I pieced together a solution for my issue.

 

'Defining all the variables
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oNamedEntities As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPartDoc)
Dim oFace As Face = oNamedEntities.FindEntity("MyFront")
Dim oPlane As Plane = oFace.Geometry
Dim oCam As Camera = ThisApplication.ActiveView.Camera
Dim oPoint As Point
Dim camUp As UnitVector = oCam.UpVector

'Setting view to the current top view
oCam.ViewOrientationType = ViewOrientationTypeEnum.kTopViewOrientation
Call oCam.ApplyWithoutTransition

'Setting the eye/target Normal to the "MyFront" surface plane
oPoint = oCam.Target.Copy
Call oPoint.TranslateBy(oPlane.Normal.AsVector())
oCam.Eye = oPoint 

'Adjusting the cameras upvector to orientate the view properly
camUp.X = 0 'Up Vector of Current Top View X
camUp.Y = -1 'Up Vector of Current Top View Y
camUp.Z = 0 'Up Vector of Current Top View Z

'Applying the new upvector
oCam.UpVector = camUp

'Setting the view with the new upvector
Call oCam.ApplyWithoutTransition

'Setting the current view as the top view
oCam.Parent.SetCurrentAsTop

 

Basically instead of doing the camera changes in the drawing document I change them directly in the part document. I'm going to add functionality to this code so I can run it directly from the assembly. Either way this is exactly what I was looking for and is a quick and easy way to reset the top camera view normal to a face on a part. 

 

0 Likes
Message 4 of 6

pcrawley
Advisor
Advisor

Sorry for hijacking a post from 2021, but with a tweak (I'm not up to writing), could this code also find an edge called say "myXaxis" and rotate the view after looking at "MyFront"?

 

Example use:  Multisolid body - created from other geometry lies off plane and off axis in 3d space.  When creating the drawing view, the code above can change the drawing view so we look directly at "MyFront", but the face may still be rotated in the view.  If an edge were also specified, the code rotates the view to get something "square" on the page.

 

1.jpg

 

Peter
0 Likes
Message 5 of 6

Ralf_Krieg
Advisor
Advisor

Hello

 

A face and one edge is not enough. Rotate the view as you show or rotate it 180° will possible. You should also add an "myYaxis" to an vertical edge that is orthogonal to "myXaxis". If you do, you can try this code:

'Defining all the variables
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oNamedEntities As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPartDoc)
Dim oFace As Face = oNamedEntities.FindEntity("MyFront")
Dim oXEdge As Edge = oNamedEntities.FindEntity("MyXaxis")
Dim oYEdge As Edge = oNamedEntities.FindEntity("MyYaxis")
Dim oPlane As Plane = oFace.Geometry
Dim oCam As Camera = ThisApplication.ActiveView.Camera
Dim oPoint As Point

' compare start and end point of edge "myXaxis" wich fits the start
' or End point of edge "myYAxis" To find the "root point" and define
' the "myYaxis" as new UpVector of camera
Dim oXLineSeg As LineSegment = oXEdge.Geometry
Dim oYLineSeg As LineSegment = oYEdge.Geometry
Dim oRootPoint As Point
Dim oUpVector As Vector

If oXLineSeg.EndPoint.DistanceTo(oYLineSeg.EndPoint) = 0 Then
	oRootPoint = oXLineSeg.EndPoint
	oUpVector = oRootPoint.VectorTo(oYLineSeg.StartPoint)
ElseIf oXLineSeg.EndPoint.DistanceTo(oYLineSeg.StartPoint) = 0 Then
	oRootPoint = oXLineSeg.EndPoint
	oUpVector = oRootPoint.VectorTo(oYLineSeg.EndPoint)
ElseIf oXLineSeg.StartPoint.DistanceTo(oYLineSeg.EndPoint) = 0 Then
	oRootPoint = oXLineSeg.StartPoint
	oUpVector = oRootPoint.VectorTo(oYLineSeg.StartPoint)
ElseIf oXLineSeg.StartPoint.DistanceTo(oYLineSeg.StartPoint) = 0 Then
	oRootPoint = oXLineSeg.StartPoint
	oUpVector = oRootPoint.VectorTo(oYLineSeg.EndPoint)
End If

Dim camUp As UnitVector = oUpVector.AsUnitVector 

'Setting the eye/target Normal to the "MyFront" surface plane
oPoint = oCam.Target.Copy
Call oPoint.TranslateBy(oPlane.Normal.AsVector())
oCam.Eye = oPoint 

'Applying the new upvector
oCam.UpVector = camUp

'Setting the view with the new upvector
Call oCam.ApplyWithoutTransition

'Setting the current view as the top view
oCam.Parent.SetCurrentAsTop

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 6 of 6

pcrawley
Advisor
Advisor

Thank you @Ralf_Krieg - I really appreciate your help!

Peter
0 Likes