Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic to align view to "Home" in a drawing

2 REPLIES 2
Reply
Message 1 of 3
lweymouth5
147 Views, 2 Replies

Ilogic to align view to "Home" in a drawing

Hi all,

In an effort to automate some sheet metal drawings I've managed to write 2 snippets of code (found similar on forums, thanks legends) which firstly run within a part/assembly to set the home view to "work plane1" and secondly an update from drawing that allows me to run the part snipped from the drawing. This so far works well but I've struggled to find any examples of using iLogic to set a drawing view to "Home" on the view cube.

I also tried setting this to "Front view" but couldn't get the view cube in the drawing to match the view cube orientation in the part (Front (part) <> Front (drawing view)). 

I've attached 2 images showing the before and after running the home view code and then manually setting the view cube to home.

lweymouth5_0-1723674983964.png

lweymouth5_1-1723675018730.png
Below is the home view aligning code

 

' Ref: https://forums.autodesk.com/t5/inventor-programming-ilogic/setting-view-cube-orientation-with-ilogic/td-p/8187506

Sub Main()
	Logger.Warn("Running SetHomeViewToWorkplane")
	Dim partDoc As PartDocument = ThisApplication.ActiveDocument 'gets the activedocument in partdocument form
	Dim partDef As PartComponentDefinition = partDoc.ComponentDefinition 'gets the part file definition.
	Dim selectedworkplane As WorkPlane = partDef.WorkPlanes("Work Plane1") 'TODO: In reference to above maybe all home view allignment planes have a specific name?
	SetFrontViewToWorkplane(ThisApplication, partDoc, selectedworkplane)
End Sub

Public Shared Sub SetFrontViewToWorkplane(ByVal InventorApp As Inventor.Application, ByVal partDoc As PartDocument, ByVal selectedWorkPlane As WorkPlane)
    partDoc.SelectSet.Clear()
    partDoc.SelectSet.[Select](selectedWorkPlane)
    Dim selSet As SelectSet = partDoc.SelectSet
    Dim LookAt As ControlDefinition = InventorApp.CommandManager.ControlDefinitions("AppLookAtCmd")
    LookAt.Execute()
    selSet.Clear()
    Dim activeView As View = InventorApp.ActiveView
    activeView.SetCurrentAsHome() 
    ' activeView.SetCurrentAsFront()
End Sub

 


Ideally looking for a snipped that will only align to home if the view is sheet metal but not flat pattern, though I can likely figure that part out if it gets to complicated. Thanks for any help offered!

 

P.s. using 2023 Inventor if this changes anything.

 

2 REPLIES 2
Message 2 of 3
GosponZ
in reply to: lweymouth5

Run this rule in that first view you show

'Pick drawing view
Dim pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select drrawing view")
Dim drwView As DrawingView = pick

'Get camera of selected drawing view
Dim drwViewCamera As Camera = drwView.Camera

'Get referenced model
Dim modelDoc As Document = drwView.ReferencedDocumentDescriptor.ReferencedDocument

'Get model view (first or new one) and its camera
Dim modelView As Inventor.View
If modelDoc.Views.Count = 0 Then
    modelView = modelDoc.Views.Add()
Else
    modelView = modelDoc.Views(1)
End If


'Copy camera from drwaing view to model view
Dim modelViewCamera As Camera = modelView.Camera
modelViewCamera.Eye = drwViewCamera.Eye
modelViewCamera.Target = drwViewCamera.Target
modelViewCamera.UpVector = drwViewCamera.UpVector

'Apply camera to model view
modelViewCamera.ApplyWithoutTransition()

'Apply ViewCube orientation
Dim activeView = ThisApplication.ActiveView
modelView.Activate()
modelView.SetCurrentAsFront()
activeView.Activate()

  

Message 3 of 3
GosponZ
in reply to: GosponZ

i think i reply to fast. This is not rule that will move part.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report