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: 

Hiding all work features in an assembly

9 REPLIES 9
Reply
Message 1 of 10
meGVGMF
977 Views, 9 Replies

Hiding all work features in an assembly

meGVGMF
Advocate
Advocate

Hello,

 

I'm trying to hide any visible work features in assemblies. Both assembly and component parts have multiple model states.

 

I found this post on GitHub, but even implementing it exactly as-is causes an error to be thrown when trying to set a visible work feature's `.Visible` to false.

 

Is there anyone able to help me understand the dynamics of this process?

 

Thanks

0 Likes

Hiding all work features in an assembly

Hello,

 

I'm trying to hide any visible work features in assemblies. Both assembly and component parts have multiple model states.

 

I found this post on GitHub, but even implementing it exactly as-is causes an error to be thrown when trying to set a visible work feature's `.Visible` to false.

 

Is there anyone able to help me understand the dynamics of this process?

 

Thanks

Labels (4)
9 REPLIES 9
Message 2 of 10
WCrihfield
in reply to: meGVGMF

WCrihfield
Mentor
Mentor

Hi @meGVGMF.  Visibility of things like work features is controlled by the DesignViewRepresentation (DVR) objects in the DesignViewRepresentations (DVR's) collection of each document.  Their main purpose is to record your settings for the visibility of things, record their colors/appearances, save view angles, save section view set-ups, and that sort of thing.  When you put a document into an assembly, represented by an assembly component object, you can set the DVR of that component to one that exists within the document it represents, and you can make that assigned DVR 'associative', which means that if changes are made to the model that effect that specific DVR, those changes will immediately effect that component.  If that 'associative' setting is turned on, it will warn you about making changes to that component that may break that relationship, and if you agree to go ahead, it will usually break that relationship, meaning that your component will no longer stay up to date with visual changes made to the model it represents.  If you have that 'associative' setting turned off for all your components, you shouldn't have much trouble changing visibility settings within components, but they will no longer stay up to date with any new visibility related changes made to the source model.

 

When ModelStates are involved, that mainly just complicates the process of making sure you are referencing the right version of the document, but the ModelState does not record things like the visibility of work features.  You just need to make sure you are working with the 'factory' version of those documents that have custom ModelStates (more than the one original ModelState, which is usually named "Master" or "Primary").  The 'factory' version of the document is simply the version of that document that is under the influence of that document's 'active' ModelState.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Hi @meGVGMF.  Visibility of things like work features is controlled by the DesignViewRepresentation (DVR) objects in the DesignViewRepresentations (DVR's) collection of each document.  Their main purpose is to record your settings for the visibility of things, record their colors/appearances, save view angles, save section view set-ups, and that sort of thing.  When you put a document into an assembly, represented by an assembly component object, you can set the DVR of that component to one that exists within the document it represents, and you can make that assigned DVR 'associative', which means that if changes are made to the model that effect that specific DVR, those changes will immediately effect that component.  If that 'associative' setting is turned on, it will warn you about making changes to that component that may break that relationship, and if you agree to go ahead, it will usually break that relationship, meaning that your component will no longer stay up to date with visual changes made to the model it represents.  If you have that 'associative' setting turned off for all your components, you shouldn't have much trouble changing visibility settings within components, but they will no longer stay up to date with any new visibility related changes made to the source model.

 

When ModelStates are involved, that mainly just complicates the process of making sure you are referencing the right version of the document, but the ModelState does not record things like the visibility of work features.  You just need to make sure you are working with the 'factory' version of those documents that have custom ModelStates (more than the one original ModelState, which is usually named "Master" or "Primary").  The 'factory' version of the document is simply the version of that document that is under the influence of that document's 'active' ModelState.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 10
meGVGMF
in reply to: WCrihfield

meGVGMF
Advocate
Advocate
I'm not sure I follow. Just to be absolutely sure we're talking about the same thing, I don't need to know anything about what the part files are doing, but for an active file, I need the work features to be hidden.

In an assembly, do I need to access the DVR of the part files? And then what do I do with it? I can't seem to find my way to the right properties.

So if the model state doesn't record the visibility of the work features, theoretically I would change it in the DVR of the factory document and it would propagate to each?
0 Likes

I'm not sure I follow. Just to be absolutely sure we're talking about the same thing, I don't need to know anything about what the part files are doing, but for an active file, I need the work features to be hidden.

In an assembly, do I need to access the DVR of the part files? And then what do I do with it? I can't seem to find my way to the right properties.

So if the model state doesn't record the visibility of the work features, theoretically I would change it in the DVR of the factory document and it would propagate to each?
Message 4 of 10
WCrihfield
in reply to: meGVGMF

WCrihfield
Mentor
Mentor

It's complicated to explain everything you might need to know about all of it right now by just typing up a bunch of stuff here in this post, so instead I'm just going to supply you with the most basic iLogic code for the most basic process for this task.  This does not take any DVR settings into account, so it may not work the way you want, but if you are not familiar with them, they you may not have used them for anything before, which may make this work OK for you.  So, if every assembly component, at every level of your entire assembly structure is still set to its default 'Master' DVR, then I do not foresee any reason why this code would not work OK for you.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	HideAllWorkFeatures(oADoc)
	Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
	If oRefDocs.Count = 0 Then Exit Sub
	For Each oRefDoc As Document In oRefDocs
		HideAllWorkFeatures(oRefDoc)
	Next
	If oADoc.RequiresUpdate Then oADoc.Update2(True)
	If oADoc.Dirty Then oADoc.Save2
	MsgBox("Done Hiding All Work Features In All Referenced Documents.", vbInformation, "Done")
End Sub

Sub HideAllWorkFeatures(oDoc As Document)
	If IsNothing(oDoc) OrElse oDoc.IsModifiable = False Then Exit Sub
	If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
		oDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		Exit Sub
	End If
	Dim oWAs As WorkAxes = oDoc.ComponentDefinition.WorkAxes
	Dim oWPs As WorkPlanes = oDoc.ComponentDefinition.WorkPlanes
	Dim oWPts As WorkPoints = oDoc.ComponentDefinition.WorkPoints
	Dim oWSs As WorkSurfaces = oDoc.ComponentDefinition.WorkSurfaces
	For Each oWA As WorkAxis In oWAs
		If oWA.Visible Then oWA.Visible = False
	Next
	For Each oWP As WorkPlane In oWPs
		If oWP.Visible Then oWP.Visible = False
	Next
	For Each oWPt As WorkPoint In oWPts
		If oWPt.Visible Then oWPt.Visible = False
	Next
	For Each oWS As WorkSurface In oWSs
		If oWS.Visible Then oWS.Visible = False
	Next
	If oDoc.RequiresUpdate Then oDoc.Update2(True)
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

It's complicated to explain everything you might need to know about all of it right now by just typing up a bunch of stuff here in this post, so instead I'm just going to supply you with the most basic iLogic code for the most basic process for this task.  This does not take any DVR settings into account, so it may not work the way you want, but if you are not familiar with them, they you may not have used them for anything before, which may make this work OK for you.  So, if every assembly component, at every level of your entire assembly structure is still set to its default 'Master' DVR, then I do not foresee any reason why this code would not work OK for you.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	HideAllWorkFeatures(oADoc)
	Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
	If oRefDocs.Count = 0 Then Exit Sub
	For Each oRefDoc As Document In oRefDocs
		HideAllWorkFeatures(oRefDoc)
	Next
	If oADoc.RequiresUpdate Then oADoc.Update2(True)
	If oADoc.Dirty Then oADoc.Save2
	MsgBox("Done Hiding All Work Features In All Referenced Documents.", vbInformation, "Done")
End Sub

Sub HideAllWorkFeatures(oDoc As Document)
	If IsNothing(oDoc) OrElse oDoc.IsModifiable = False Then Exit Sub
	If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
		oDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		Exit Sub
	End If
	Dim oWAs As WorkAxes = oDoc.ComponentDefinition.WorkAxes
	Dim oWPs As WorkPlanes = oDoc.ComponentDefinition.WorkPlanes
	Dim oWPts As WorkPoints = oDoc.ComponentDefinition.WorkPoints
	Dim oWSs As WorkSurfaces = oDoc.ComponentDefinition.WorkSurfaces
	For Each oWA As WorkAxis In oWAs
		If oWA.Visible Then oWA.Visible = False
	Next
	For Each oWP As WorkPlane In oWPs
		If oWP.Visible Then oWP.Visible = False
	Next
	For Each oWPt As WorkPoint In oWPts
		If oWPt.Visible Then oWPt.Visible = False
	Next
	For Each oWS As WorkSurface In oWSs
		If oWS.Visible Then oWS.Visible = False
	Next
	If oDoc.RequiresUpdate Then oDoc.Update2(True)
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 10
Maxim-CADman77
in reply to: meGVGMF

Maxim-CADman77
Advisor
Advisor

Thread is not new yet not marked as solved ... thus ...

... maybe you need just this single line?

 

 

ThisApplication.CommandManager.ControlDefinitions("AppAllWorkfeaturesCmd").Execute

 

 

0 Likes

Thread is not new yet not marked as solved ... thus ...

... maybe you need just this single line?

 

 

ThisApplication.CommandManager.ControlDefinitions("AppAllWorkfeaturesCmd").Execute

 

 

Message 6 of 10
meGVGMF
in reply to: Maxim-CADman77

meGVGMF
Advocate
Advocate

Sadly I'm not sure this solves the problem, as this seems to be a master switch which simply overrides the visibility setting per work feature. What is needed is a way to toggle each individually, so as to allow them to be turned on again, one by one, rather than returning to the original state. @WCrihfield may have the solution, but I haven't had time to implement it to see if it works.

0 Likes

Sadly I'm not sure this solves the problem, as this seems to be a master switch which simply overrides the visibility setting per work feature. What is needed is a way to toggle each individually, so as to allow them to be turned on again, one by one, rather than returning to the original state. @WCrihfield may have the solution, but I haven't had time to implement it to see if it works.

Message 7 of 10
WCrihfield
in reply to: meGVGMF

WCrihfield
Mentor
Mentor

I believe the ControlDefinition mentioned above is the one seen in the following location...

While working within a part or assembly, if you go to the View tab, then you will see a control called Object Visibility on the Visibility panel.  It has a drop-down arrow beside it.  When you click that down arrow, you will see a list of object types that you can turn on or off, by checking or un-checking checkboxes beside them.  At the very top of that list is All Workfeatures.  Executing that command likely does the same as toggling that control on/off.  This appears to be a 'per document' type of setting, instead of a per feature setting, or an application wide setting, because I can have two different parts open in different document tabs (that have nothing to do with each other), and can have some WorkPlanes showing in both.  Then turn that setting off while one part is active on my screen, then when I go to the other part (and make it active), those settings are still on within that control drop-down, and its WorkPlanes are still visible.  I am not sure if that setting (the state of that control) is saved per document or not though, since it is not actually applied directly to the individual instances.  If the WorkPlane instances already have their visibility turned off individually, then turning that ribbon control on does not turn on the visibility of all my work features...only the ones that were already set to be visible individually.  So, that ribbon control is only good for temporarily hiding the work features that have not already been hidden individually, but not good for unhiding the ones that were already hidden individually.

 

When you have a Part open, there is usually model browser node near the top of the model browser tree, with its name starting with "View:", followed by the name of the active DesignViewRepresentation (DVR).  Most of the time, there is only the one, Locked DVR named "[Primary]", and no 'custom' ones, until we create some custom ones.  We often do not need to use these in a part, but sometimes we do, if we want to show the same part in multiple colors / appearances, or if the part has multiple solid bodies, and sometimes we want to be able to turn the visibility of some solid bodies on/off.  So, when we drop a part into an assembly, as an assembly component, we can have multiple copies of that same part in the same assembly.  And if that part has multiple DVR's defined within it, we can set one assembly component to one of those DVR's (Red, for example, or certain bodies visible), and set another assembly occurrence of that same part to a different DVR (Blue, for example, or different bodies visible).  The same is true when adding a sub assembly into another assembly, when the sub assembly may have multiple DVRs, and we add multiple instances of that sub assembly into the other assembly, as assembly components.  We can set one sub assembly occurrence to one DVR (some of its components visible, some certain colors), while setting another instance of that sub assembly component to a different DVR (different components visible, other component colors).  However, the DVR's in sub assemblies record much more.  Each DVR in each sub assembly will not only record the visibility, colors/appearances settings defined directly in that sub assembly, but will also record which DVR each individual component within that sub assembly is set to.  This is why these should be set-up from the bottom, to the top, instead of from the top, to the bottom.

 

Because all visibility (not suppression) and color, and appearances are recorded by DVR's, when we want to control those aspects within the documents that assembly components represent, the proper way to do that is by having a DVR defined within the referenced document and set up the way we want it, then setting the assembly component referencing that document to the DVR that is defined within it.  And, because of this, it is always best to define these settings along the way, as we design the parts and sub assemblies, so that all the DVR's we may want to use at a higher level assembly, will already exist and be ready to use.  If we choose not create/define any DVR's along the way, then controlling all those things from the top, down, from the main assembly later becomes much more complicated and more difficult to do properly.

 

On the other hand, if none of the parts, and none of the sub assemblies ever had any custom DVR's created, and all of them were still just set to their original DVR (named "[Primary]"), then a relatively simple code process like the one I posted above may work OK for you.  This would be because...all those types of settings (visibility, colors, appearances) that were set along the way, will all have been recorded by that one, default DVR, and any changes made by the code will also be recorded by that one, default DVR.

 

The following properties & methods of the assembly component (ComponentOccurrence) can be used to get/set the DVR that an individual assembly component is currently set to.

ComponentOccurrence.ActiveDesignViewRepresentation 

ComponentOccurrence.IsAssociativeToDesignViewRepresentation 

ComponentOccurrence.SetDesignViewRepresentation 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

I believe the ControlDefinition mentioned above is the one seen in the following location...

While working within a part or assembly, if you go to the View tab, then you will see a control called Object Visibility on the Visibility panel.  It has a drop-down arrow beside it.  When you click that down arrow, you will see a list of object types that you can turn on or off, by checking or un-checking checkboxes beside them.  At the very top of that list is All Workfeatures.  Executing that command likely does the same as toggling that control on/off.  This appears to be a 'per document' type of setting, instead of a per feature setting, or an application wide setting, because I can have two different parts open in different document tabs (that have nothing to do with each other), and can have some WorkPlanes showing in both.  Then turn that setting off while one part is active on my screen, then when I go to the other part (and make it active), those settings are still on within that control drop-down, and its WorkPlanes are still visible.  I am not sure if that setting (the state of that control) is saved per document or not though, since it is not actually applied directly to the individual instances.  If the WorkPlane instances already have their visibility turned off individually, then turning that ribbon control on does not turn on the visibility of all my work features...only the ones that were already set to be visible individually.  So, that ribbon control is only good for temporarily hiding the work features that have not already been hidden individually, but not good for unhiding the ones that were already hidden individually.

 

When you have a Part open, there is usually model browser node near the top of the model browser tree, with its name starting with "View:", followed by the name of the active DesignViewRepresentation (DVR).  Most of the time, there is only the one, Locked DVR named "[Primary]", and no 'custom' ones, until we create some custom ones.  We often do not need to use these in a part, but sometimes we do, if we want to show the same part in multiple colors / appearances, or if the part has multiple solid bodies, and sometimes we want to be able to turn the visibility of some solid bodies on/off.  So, when we drop a part into an assembly, as an assembly component, we can have multiple copies of that same part in the same assembly.  And if that part has multiple DVR's defined within it, we can set one assembly component to one of those DVR's (Red, for example, or certain bodies visible), and set another assembly occurrence of that same part to a different DVR (Blue, for example, or different bodies visible).  The same is true when adding a sub assembly into another assembly, when the sub assembly may have multiple DVRs, and we add multiple instances of that sub assembly into the other assembly, as assembly components.  We can set one sub assembly occurrence to one DVR (some of its components visible, some certain colors), while setting another instance of that sub assembly component to a different DVR (different components visible, other component colors).  However, the DVR's in sub assemblies record much more.  Each DVR in each sub assembly will not only record the visibility, colors/appearances settings defined directly in that sub assembly, but will also record which DVR each individual component within that sub assembly is set to.  This is why these should be set-up from the bottom, to the top, instead of from the top, to the bottom.

 

Because all visibility (not suppression) and color, and appearances are recorded by DVR's, when we want to control those aspects within the documents that assembly components represent, the proper way to do that is by having a DVR defined within the referenced document and set up the way we want it, then setting the assembly component referencing that document to the DVR that is defined within it.  And, because of this, it is always best to define these settings along the way, as we design the parts and sub assemblies, so that all the DVR's we may want to use at a higher level assembly, will already exist and be ready to use.  If we choose not create/define any DVR's along the way, then controlling all those things from the top, down, from the main assembly later becomes much more complicated and more difficult to do properly.

 

On the other hand, if none of the parts, and none of the sub assemblies ever had any custom DVR's created, and all of them were still just set to their original DVR (named "[Primary]"), then a relatively simple code process like the one I posted above may work OK for you.  This would be because...all those types of settings (visibility, colors, appearances) that were set along the way, will all have been recorded by that one, default DVR, and any changes made by the code will also be recorded by that one, default DVR.

 

The following properties & methods of the assembly component (ComponentOccurrence) can be used to get/set the DVR that an individual assembly component is currently set to.

ComponentOccurrence.ActiveDesignViewRepresentation 

ComponentOccurrence.IsAssociativeToDesignViewRepresentation 

ComponentOccurrence.SetDesignViewRepresentation 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 10
srinivasanyl
in reply to: WCrihfield

srinivasanyl
Contributor
Contributor

Hi, I used this code in assembly, all the orgin planes, axis, points visibilty turned off. but user planes, axis, points not visibility turned off. anybody please for update me.

0 Likes

Hi, I used this code in assembly, all the orgin planes, axis, points visibilty turned off. but user planes, axis, points not visibility turned off. anybody please for update me.

Message 9 of 10
srinivasanyl
in reply to: srinivasanyl

srinivasanyl
Contributor
Contributor
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
HideAllWorkFeatures(oADoc)
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
If oRefDocs.Count = 0 Then Exit Sub
For Each oRefDoc As Document In oRefDocs
HideAllWorkFeatures(oRefDoc)
Next
If oADoc.RequiresUpdate Then oADoc.Update2(True)
If oADoc.Dirty Then oADoc.Save2
MsgBox("Done Hiding All Work Features In All Referenced Documents.", vbInformation, "Done")
End Sub

Sub HideAllWorkFeatures(oDoc As Document)
If IsNothing(oDoc) OrElse oDoc.IsModifiable = False Then Exit Sub
If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
oDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
Exit Sub
End If
Dim oWAs = oDoc.ComponentDefinition.WorkAxes
Dim oWPs = oDoc.ComponentDefinition.workPlanes
Dim oWPts = oDoc.ComponentDefinition.WorkPoints

'oDoc = ThisApplication.ActiveDocument
'Dim oWSs As WorkSurfaces = oDoc.ComponentDefinition.WorkSurfaces
For Each oWA As WorkAxis In oDoc.ComponentDefinition.WorkAxes
If oWA.Visible Then oWA.Visible = False
Next
For Each oWP In oDoc.ComponentDefinition.WorkPlanes
If oWP.Visible Then oWP.Visible = False
Next
For Each oWPt In oDoc.ComponentDefinition.WorkPoints
If oWPt.Visible Then oWPt.Visible = False
Next
'For Each oWS As WorkSurface In oWSs
' If oWS.Visible Then oWS.Visible = False
'Next
If oDoc.RequiresUpdate Then oDoc.Update2(True)
End Sub
0 Likes

Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
HideAllWorkFeatures(oADoc)
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
If oRefDocs.Count = 0 Then Exit Sub
For Each oRefDoc As Document In oRefDocs
HideAllWorkFeatures(oRefDoc)
Next
If oADoc.RequiresUpdate Then oADoc.Update2(True)
If oADoc.Dirty Then oADoc.Save2
MsgBox("Done Hiding All Work Features In All Referenced Documents.", vbInformation, "Done")
End Sub

Sub HideAllWorkFeatures(oDoc As Document)
If IsNothing(oDoc) OrElse oDoc.IsModifiable = False Then Exit Sub
If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
oDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
Exit Sub
End If
Dim oWAs = oDoc.ComponentDefinition.WorkAxes
Dim oWPs = oDoc.ComponentDefinition.workPlanes
Dim oWPts = oDoc.ComponentDefinition.WorkPoints

'oDoc = ThisApplication.ActiveDocument
'Dim oWSs As WorkSurfaces = oDoc.ComponentDefinition.WorkSurfaces
For Each oWA As WorkAxis In oDoc.ComponentDefinition.WorkAxes
If oWA.Visible Then oWA.Visible = False
Next
For Each oWP In oDoc.ComponentDefinition.WorkPlanes
If oWP.Visible Then oWP.Visible = False
Next
For Each oWPt In oDoc.ComponentDefinition.WorkPoints
If oWPt.Visible Then oWPt.Visible = False
Next
'For Each oWS As WorkSurface In oWSs
' If oWS.Visible Then oWS.Visible = False
'Next
If oDoc.RequiresUpdate Then oDoc.Update2(True)
End Sub

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

Post to forums  

Autodesk Design & Make Report