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: 

Set view cube to front by custom workplane

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
b.bosman
199 Views, 4 Replies

Set view cube to front by custom workplane

Hello,

In my parametric model I have 2 parts and 2 subassemblies that change in angle, in a way that my viewcube orientation will change while i dont want it to. Untill now we reset it by hand, but i like it to be automated.  (preferably from my top assembly) I found already the code below that works from the specific part and subassembly but i cant get it working from my topassembly. I hope you guys can help me. Thanks in advance.

 

Sub Main()
	PartDocument.Activate() 
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(4) 'gets the XY plane so swap this with whatever your object is
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.SetCurrentAsFront()
End Sub

 

4 REPLIES 4
Message 2 of 5
Andrii_Humeniuk
in reply to: b.bosman

Hi @b.bosman . This code must be run in the top assembly.

Sub Main()
	Dim oDoc As Document = ThisDoc.Document
	If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
	Dim AsmDoc As AssemblyDocument = oDoc
	Dim oDocs As Documents = ThisApplication.Documents
	Dim oVisDocs As DocumentsEnumerator = oDocs.VisibleDocuments
	For Each oRefDoc As Document In AsmDoc.AllReferencedDocuments
		If TypeOf oRefDoc Is PartDocument Then
			If oRefDoc.IsModifiable Then
				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 SetFrontViewToWorkplane(oRefDoc)
					oPartDoc.Save()
				Else
					Dim oVisDoc As Document = oDocs.Open(oRefDoc.FullDocumentName, True)
					Call SetFrontViewToWorkplane(oVisDoc)
					oVisDoc.Save()
					oVisDoc.Close()
				End If
			End If
		End If
	Next
	If Not AsmDoc.IsOpenExpress Then AsmDoc.Activate()
End Sub

Public Function SetFrontViewToWorkplane(ByVal oDoc As Document)
	Dim XYplane As WorkPlane = oDoc.ComponentDefinition.WorkPlanes(3)
    Dim selSet As SelectSet = oDoc.SelectSet
    selSet.Clear()
    selSet.Select(XYplane)
    Dim LookAt As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppLookAtCmd")
    LookAt.Execute()
    selSet.Clear()
	Call ThisApplication.ActiveView.SetCurrentAsFront()
End Function

 

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

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

EESignature

Message 3 of 5
b.bosman
in reply to: Andrii_Humeniuk

@Andrii_Humeniuk Thanks for your help! The code is doing what i mentioned. But it runs through all my parts (more than 60 parts) while I need it for only 2 parts and 2 subassemblies (Always the same parts en subassemblies). Do you think thats possible? 

Message 4 of 5
Andrii_Humeniuk
in reply to: b.bosman

Of course it is possible, but for the code you need to indicate exactly which components you need. For example, if you need specific components, you can select them by name.
Write the names of your documents in line 7.

Sub Main()
	Dim oDoc As Document = ThisDoc.Document
	If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
	Dim AsmDoc As AssemblyDocument = oDoc
	Dim oDocs As Documents = ThisApplication.Documents
	Dim oVisDocs As DocumentsEnumerator = oDocs.VisibleDocuments
	Dim listName As New List(Of String) From {"Name your part1", "Name your part2", "Name your assembly1"}
	For Each oRefDoc As Document In AsmDoc.AllReferencedDocuments
		If listName.Contains(oRefDoc.DisplayName) Then
			If oRefDoc.IsModifiable Then
				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 SetFrontViewToWorkplane(oRefDoc)
					oPartDoc.Save()
				Else
					Dim oVisDoc As Document = oDocs.Open(oRefDoc.FullDocumentName, True)
					Call SetFrontViewToWorkplane(oVisDoc)
					oVisDoc.Save()
					oVisDoc.Close()
				End If
			End If
		End If
	Next
	If Not AsmDoc.IsOpenExpress Then AsmDoc.Activate()
End Sub

Public Function SetFrontViewToWorkplane(ByVal oDoc As Document)
	Dim XYplane As WorkPlane = oDoc.ComponentDefinition.WorkPlanes(3)
    Dim selSet As SelectSet = oDoc.SelectSet
    selSet.Clear()
    selSet.Select(XYplane)
    Dim LookAt As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppLookAtCmd")
    LookAt.Execute()
    selSet.Clear()
	Call ThisApplication.ActiveView.SetCurrentAsFront()
End Function

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

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

EESignature

Message 5 of 5
b.bosman
in reply to: Andrii_Humeniuk

Sadly nothing is happening with the new code 

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

Post to forums  

Autodesk Design & Make Report