show / hide ucs triad, origin planes, sketches ...

show / hide ucs triad, origin planes, sketches ...

wolfgang_nickl
Advocate Advocate
3,658 Views
12 Replies
Message 1 of 13

show / hide ucs triad, origin planes, sketches ...

wolfgang_nickl
Advocate
Advocate

Hello together,

I found a lot of examples to individually hide origin planes, sketches or ucs triads.

In ribbon View -> visibility panel -> Object Visibility you can hide all 3d Sketches or UCS Triad

for the whole assembly. The individual setting isn't overwritten.

Is it possible to do the same via vba or iLogic?

 

Best Regards

Wolfgang

0 Likes
Accepted solutions (1)
3,659 Views
12 Replies
Replies (12)
Message 2 of 13

FINET_Laurent
Advisor
Advisor

Hi @wolfgang_nickl,

 

I'm not aware that you can create 3D sketches inside an assembly. Do you want to look into each individual parts inside the assembly and hide their 3D sketches ? 

 

If yes, here is a small code that does the trick : 

Dim Doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim AssyCompDef As Inventor.AssemblyComponentDefinition = Doc.ComponentDefinition

For Each Occ As Inventor.ComponentOccurrence In AssyCompDef.Occurrences.AllLeafOccurrences
	If Occ.ReferencedDocumentDescriptor.ReferencedDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then 
		Dim def As Inventor.PartComponentDefinition = Occ.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition
		For Each s As Inventor.Sketch3D In def.Sketches3D
			s.Visible = False
			
		Next
	End If
Next

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 13

wolfgang_nickl
Advocate
Advocate

Hello Finet,

thank you for your repley.

this solution I know. But that isn't what I want. In an assembly I have some origin planes or sketches visible while others are unvisible. With the switches from the menu I don't overwrite this settings. With your solution this will be overwriten and that isn't wanted.

 

Best Regards 

Wolfgang

0 Likes
Message 4 of 13

FINET_Laurent
Advisor
Advisor

@wolfgang_nickl,

 

Are you saying the code will break the link with the design view repsresentation ? And that is to be avoided ? 

Then we would have to open the part and it's current design view representation in the assembly, then remove the 3D sketch, save & close it. It would keep the link. 

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 5 of 13

wolfgang_nickl
Advocate
Advocate

Hello Finet,

I think we talk of different things. In the following picture you see simple example.

In Part F004 a 3D Sketch is invisible an in F003 a 3D Sketch is visible. 

In reality this will be more complex.

Now I want to hide all 3d sketches, UCS... to make for Example a screenshot. Afterwards I want have

the orignal view state. With the way over the menu I can have this, but

I want to make a button that I only have to click once an all is invisble. 

And a second click brings back the old state.

 

But to set all visibilities don't allow me to get back.

 

Best Regards

Wolfgang

0 Likes
Message 6 of 13

FINET_Laurent
Advisor
Advisor

@wolfgang_nickl,

 

Correct me if I'm wrong. The workflow would be two buttons.

 

For the fist button :

1.1. Search for each part in the assembly 

1.2. For each part, check for visible 3D sketch

1.3. Is there is one or more, turn it to invisible, then create a custom iProperty that save the name of the previously visible 3d sketches.

 

For the next button :

2.1. Search for each part in the assembly 

2.2. If a part has an ipropery with names of 3D sketches, turn those back on. Then delete the custom iProperty.

 

Would that be correct ? 

 

Kind regards,

FINET L.

 

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 7 of 13

wolfgang_nickl
Advocate
Advocate

Hallo Finet,
your suggested solution will work. To get back the old state you need the macro.

But the question is, is it possible to use the api to have the same result as if I klick the checkboxes in ribbon View Object visibility. On every Inventor without the macro I can get back to the old state.

I have two situations, for documentation I will uncheck all switches, and for design I want to change uncheck UCS and Sketches. Therefor I want to make two button which switch for and back. When I send the model to any other guy, they will get back with inventor own commands.

Thank you for your interest.

Best Regards

Wolfgang

Message 8 of 13

FINET_Laurent
Advisor
Advisor

Hi @wolfgang_nickl,

 

I now understand your request. There is actually a way but unfortunately I can't work on it as today.

There is indeed a way to fire the command as if you clicked on it with your mouse, using the command manager. 

Here is a quick exemple for the origin work planes : 

Dim cmgr As Inventor.CommandManager = ThisApplication.CommandManager
Dim ctrldef As Inventor.ControlDefinition = cmgr.ControlDefinitions("AppOriginPlanesVisibilityCmd")
ctrldef.Execute

The code above simulate the click on the check box for the origin work planes.

To find the other commands, you would have to go through the list attached and search for "visibility".

I would copy paste the line 2 & 3 and change the command name for each commands.

 

FINET_Laurent_0-1689086476051.png

 

Do you think you can manage the rest? 


Kind regards,

FINET L.

 

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 9 of 13

wolfgang_nickl
Advocate
Advocate

Hello Finet,

this way I tried myself, but this alone didn't work. I used the following command in VBA. The problem is, the command switches the current state. If for example 3d Sketches are invisible and UCS are visible, the first will be visible the other invisible if I fire their two commands.

Sub subVisible()
    ThisApplication.CommandManager.ControlDefinitions("App3DSketchesVisibilityCmd").Execute
End Sub

Is  it possible to invoke this command with a parameter true or false or is it possible to read the current state with the API. I didn't find both. But with one of both it will be the solution.

 

Best Regards

Wolfgang

Message 10 of 13

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi @wolfgang_nickl,

 

There is indeed a way. I had to dig deep but here it is : 

FINET_Laurent_0-1689142614211.png

 

To get there in the tree : 

Dim u As Inventor.UserInterfaceManager = ThisApplication.UserInterfaceManager
Dim r As Inventor.Ribbon = u.Ribbons(3) 'assembly ribbon
Dim t As Inventor.RibbonTab = r.RibbonTabs(11) 'display ribbon tab
Dim p As Inventor.RibbonPanel = t.RibbonPanels(1) 'visibility ribbon pannel
Dim c As Inventor.CommandControl = p.CommandControls.Item(1) 'object visibility command control

Dim cc As Inventor.CommandControl = c.ChildControls.Item(1) 'represents all the check boxes on the window
'command (see picture). In this level you also have the internal command name (useful)
MsgBox(Cc.InternalName)

'Here you have information about the state of the button
Dim def As Inventor.ControlDefinition = cc.ControlDefinition
msgBox(def.Pressed)

You can then check this property before firing each rule. 😃

 

Kind regards,

FINET L.

 

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 11 of 13

wolfgang_nickl
Advocate
Advocate

Hello Finet,

thank you very mutch that's it. I modified your solution a little bit and use names instead of indicies.

Following you find my code.

Sub subINVisible2()
    Dim c As Inventor.CommandControl
    Set c = ThisApplication.UserInterfaceManager.Ribbons("Assembly").RibbonTabs("id_TabView").RibbonPanels("id_PanelA_ViewVisibility").CommandControls.Item("INV_View_ObjectVisibility_Cmd")
    If c.ChildControls.Item("AppAllWorkfeaturesCmd").ControlDefinition.Pressed Then
        ThisApplication.CommandManager.ControlDefinitions.Item("AppAllWorkfeaturesCmd").Execute
    End If
    If c.ChildControls.Item("App3DSketchesVisibilityCmd").ControlDefinition.Pressed Then
        ThisApplication.CommandManager.ControlDefinitions.Item("App3DSketchesVisibilityCmd").Execute
    End If
End Sub

Best Regards

Wolfgang

Message 12 of 13

wfajber
Contributor
Contributor

I found this code elsewhere. I find it quite handy. I couldn't recall where I found it previously, so I am just posting it..

 

'This Rule will Present the user with a multiple choice input box. After the choice is made the rule will set visibility for the selected object to off.
' copied from http://www.hoppend.nl/inventor.htm
' modified Sept 2019 by W Fajber so that it included subassemblies.

Class ThisRule
	' Setup Progress Bar
	Dim ReferenceCount As Integer
	Dim oStep As Integer
	Dim oMessage As String = "Setting visibility for objects to off"
	Dim oProgressBar As Inventor.ProgressBar
	Dim DocFailed As Integer

Sub Main()
	'get the active document
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument

	'check if the rule is run on an Assembly
	Dim Assydoc As AssemblyDocument
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		Assydoc = oDoc
	Else
		MessageBox.Show("Rule needs to be run from Assembly", "Rule: Object visibility")
		Exit Sub
	End If


	'Present user with multiple choice
	Dim Options() As String = {"All", "Only Origin planes", "Work planes and Origin planes", "Axis only", "Work points only", "Sketches only"}
	Result1 = InputListBox("Please select", Options, Options(0), Title := "Object Visibility", ListName := "List")

	'perform actions on basis of multiple choice. First all documents in the assembly are counted, then the objects are turned off whilst the user is presented with a progress bar
	Select Case Result1
		Case options(0)
			CountReferencedDocuments(Assydoc, 4)
			RemoveWorkPlanes(Assydoc)
			RemoveSketches(Assydoc)
			RemoveWorkpoints(Assydoc)
			RemoveAxis(Assydoc)
		Case options(1)
			CountReferencedDocuments(Assydoc, 1)
			RemoveOriginPlanes(Assydoc)
		Case options(2)
			CountReferencedDocuments(Assydoc, 1)
			RemoveWorkPlanes(Assydoc)
		Case options(3)
			CountReferencedDocuments(Assydoc, 1)
			RemoveAxis(Assydoc)
		Case options(4)
			CountReferencedDocuments(Assydoc, 1)
			RemoveWorkpoints(Assydoc)
		Case options(5)
			CountReferencedDocuments(Assydoc, 1)
			RemoveSketches(Assydoc)
	End Select

	oProgressBar.Close

	'Check if there are any failed files, and show user how many files.
	If DocFailed <> 0 Then
		MessageBox.Show(DocFailed & " Objects failed to set to invisible", "Object Visibility")
	End If
	'Update file
	iLogicVb.UpdateWhenDone = True
End Sub

'this sub will count the objects and create the progress bar
Sub CountReferencedDocuments(Assydoc As AssemblyDocument, Passes As Integer)
	For Each doc As Document In Assydoc.AllReferencedDocuments
		If (doc.DocumentType = DocumentTypeEnum.kPartDocumentObject) And doc.IsModifiable = True Then
			ReferenceCount = ReferenceCount + Passes
		End If
	 Next
	oProgressBar = ThisApplication.CreateProgressBar(False, ReferenceCount, oMessage)
End Sub

'This Sub will set visibility for all origin planes to off
Sub RemoveOriginPlanes (Assydoc As AssemblyDocument)
	For Each oWorkPlane In Assydoc.ComponentDefinition.WorkPlanes
		If oWorkPlane.Name = "XY Plane" Or oWorkPlane.Name = "XZ Plane" Or oWorkPlane.Name = "YZ Plane"
		oWorkPlane.Visible = False
		End If
	Next

	For Each doc As Document In Assydoc.AllReferencedDocuments
			Logger.Trace("remove origin planes- document name:" & doc.FullDocumentName)
		If (doc.DocumentType = DocumentTypeEnum.kPartDocumentObject) And doc.IsModifiable = True Then
		Dim Partdoc As PartDocument = doc
			For Each oWorkPlane In Partdoc.ComponentDefinition.WorkPlanes
				If oWorkPlane.Name = "XY Plane" Or oWorkPlane.Name = "XZ Plane" Or oWorkPlane.Name = "YZ Plane"
					Try
						oWorkPlane.Visible = False
					Catch
						DocFailed = DocFailed + 1
					End Try
				End If
			Next
			Partdoc.Update()
		End If 
		If (doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) And doc.IsModifiable = True Then
		Dim Asmdoc As AssemblyDocument = doc
			For Each oWorkPlane In Asmdoc.ComponentDefinition.WorkPlanes
				If oWorkPlane.Name = "XY Plane" Or oWorkPlane.Name = "XZ Plane" Or oWorkPlane.Name = "YZ Plane"
					Try
						oWorkPlane.Visible = False
					Catch
						DocFailed = DocFailed + 1
					End Try
				End If
			Next
			Asmdoc.Update()
			End If
		oProgressBar.Message = ("File " & oStep & " of " & ReferenceCount & ", :Procesed ")
		oProgressBar.UpdateProgress
		oStep = oStep +1
	Next
End Sub

'This Sub will set visibility for all work planes to off
Sub RemoveWorkPlanes (Assydoc As AssemblyDocument)
	For Each oWorkPlane In Assydoc.ComponentDefinition.WorkPlanes
		oWorkPlane.Visible = False
	'	MsgBox(" removing workplane")
	Next

	For Each doc As Document In Assydoc.AllReferencedDocuments
			Logger.Trace("remove workplanes- document name:" & doc.FullDocumentName)
		If (doc.DocumentType = DocumentTypeEnum.kPartDocumentObject) And doc.IsModifiable = True Then
		Dim Partdoc As PartDocument = doc
			For Each oWorkPlane In Partdoc.ComponentDefinition.WorkPlanes
				Try
					oWorkPlane.Visible = False
				'	MsgBox(" removing workplane")
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
			Partdoc.Update()
		End If 
		If (doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) And doc.IsModifiable = True Then
		Dim Asmdoc As AssemblyDocument = doc
			For Each oWorkPlane In Asmdoc.ComponentDefinition.WorkPlanes
				Try
					oWorkPlane.Visible = False
				'	MsgBox(" removing workplane")
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
			Asmdoc.Update()
		End If
		oProgressBar.Message = ("File " & oStep & " of " & ReferenceCount & ", :Procesed ")
		oProgressBar.UpdateProgress
		oStep = oStep +1
	Next
End Sub

'This Sub will set visibility for all work axis to off
Sub RemoveAxis (Assydoc As AssemblyDocument)
	For Each oAxes In Assydoc.ComponentDefinition.WorkPlanes
		oAxes.Visible = False
	Next

	For Each doc As Document In Assydoc.AllReferencedDocuments
			Logger.Trace("remove workpoints - document name:" & doc.FullDocumentName)
		If (doc.DocumentType = DocumentTypeEnum.kPartDocumentObject) And doc.IsModifiable = True Then
		Dim Partdoc As PartDocument = doc
			For Each oAxes In Partdoc.ComponentDefinition.WorkAxes
				Try
					oAxes.Visible = False
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
		Partdoc.Update()
		End If
		If (doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) And doc.IsModifiable = True Then
		Dim Asmdoc As AssemblyDocument = doc
			For Each oAxes In Asmdoc.ComponentDefinition.WorkAxes
				Try
					oAxes.Visible = False
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
			Asmdoc.Update()
		End If
		oProgressBar.Message = ("File " & oStep & " of " & ReferenceCount & ", :Procesed ")
		oProgressBar.UpdateProgress
		oStep = oStep +1
	Next
End Sub

'This Sub will set visibility for all work points to off
Sub RemoveWorkpoints (Assydoc As AssemblyDocument)
	For Each oWorkPoint In Assydoc.ComponentDefinition.WorkPoints
		oWorkPoint.Visible = False
	Next

	For Each doc As Document In Assydoc.AllReferencedDocuments
			Logger.Trace("remove workpoints - document name:" & doc.FullDocumentName)
		If (doc.DocumentType = DocumentTypeEnum.kPartDocumentObject) And doc.IsModifiable = True Then
		Dim Partdoc As PartDocument = doc
			For Each oWorkPoint In Partdoc.ComponentDefinition.WorkPoints
				Try
					oWorkPoint.Visible = False
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
		Partdoc.Update()
		End If
		If (doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) And doc.IsModifiable = True Then
		Dim Asmdoc As AssemblyDocument = doc
			For Each oWorkPoint In Asmdoc.ComponentDefinition.WorkPoints
				Try
					oWorkPoint.Visible = False
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
			Asmdoc.Update()
		End If
		oProgressBar.Message = ("File " & oStep & " of " & ReferenceCount & ", :Procesed ")
		oProgressBar.UpdateProgress
		oStep = oStep +1
	Next
End Sub

'This Sub will set visibility for all sketches to off
Sub RemoveSketches(Assydoc As AssemblyDocument)
	For Each doc As Document In Assydoc.AllReferencedDocuments
		Logger.Trace("remove sketches - document name:" & doc.FullDocumentName)
		If (doc.DocumentType = DocumentTypeEnum.kPartDocumentObject) And doc.IsModifiable = True Then
		Dim Partdoc As PartDocument = doc
			For Each oSketch In Partdoc.ComponentDefinition.Sketches
				Try
					oSketch.Visible = False
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
			For Each o3DSketch In Partdoc.ComponentDefinition.Sketches3D
				Try
				o3DSketch.Visible = False
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
		Partdoc.Update()
		End If
		If(doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) And doc.IsModifiable = True Then
		Dim Asmdoc As AssemblyDocument = doc
			For Each oSketch In Asmdoc.ComponentDefinition.Sketches
				Try
					oSketch.Visible = False
				Catch
					DocFailed = DocFailed + 1
				End Try
			Next
			' only 2d sketches are in assembly files
		End If
		
			
		oProgressBar.Message = ("File " & oStep & " of " & ReferenceCount & ", :Procesed ")
		oProgressBar.UpdateProgress
		oStep = oStep +1
	Next
End Sub


'Functions to parse Filename and folder from complete Path
Public Function FileNameFromPath(strFullPath As String) As String
	FileNameFromPath = Right(strFullPath, Len(strFullPath) - InStrRev(strFullPath, "\"))
End Function

Public Function FileNameFromPathNoExt(strFullPath As String) As String
	Dim FileNameFromPath2 As String = FileNameFromPath(strFullPath)
	FileNameFromPathNoExt = Left(FileNameFromPath2, (InStrRev(FileNameFromPath2, ".")-1))
End Function

Public Function FolderFromPath(strFullPath As String) As String
	FolderFromPath = Left(strFullPath, InStrRev(strFullPath, "\"))
End Function

End Class
0 Likes
Message 13 of 13

Huib.Eggen
Explorer
Explorer

that last code was originally posted on www.hoppend.nl

0 Likes