I have several assemblies that have invisible parts in them. When I place these assemblies into a parent assembly and toggle the visability off/on my invisible parts show up. Is there an iLogic code I could run that would activate the default view representation in all of those assemblies instead of the default "Master" view rep? Here is the code I've written so far:
Dim aDoc As AssemblyDocument
aDoc = ThisApplication.ActiveDocument
Dim iDoc As Document
For Each iDoc In aDoc.AllReferencedDocuments
Dim ocompdef As ComponentDefinition
ocompdef = iDoc.ComponentDefinition
ocompdef.RepresentationsManager.DesignViewRepresentations.Item("TEST").Activate
Next
Any help would be greatly appreciated.I've also attached photos
Solved! Go to Solution.
Hi,
"SetDesignViewRepresentation" works for setting occurance view in an assembly.
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
For Each oCompOcc in oAsmCompDef.Occurrences
oCompOcc.SetDesignViewRepresentation("Default", True)
Next
ThisApplication.ActiveView.Fit
@atotiace wrote:
As a follow up, that code worked for a while but infrequently I get this error message.
I took a look at this code because it seemed similar to something I've been looking for a way to do. I think you are seeing that error message because the view representation you are trying to set doesn't exist in some of the files.
In particular, the code that Carthik_Babu provided references the "Default" view representation. There is a Default view rep in assemblies, but there is not a representation by that name in part files unless you have created it yourself.
Carthik_Babu,
How is your code intended to work?
I have been looking for a way to set all components in an assembly to a particular view representation and set them as Associative. When I was first looking at your posted code, I thought that was what it would do, but my results were different.
Instead, what I actually seem to be getting is that the components get an assembly-level appearance override that matches the color of the target view representation, but the representation of the component actually gets set to Master. Is that the way this is supposed to behave?
FYI, I'm still running Inventor 2013 here. If this is something that doesn't work properly without 2014 I can just wait to implement it until our next upgrade
I using inventor 2012 and this code is supposed to take all subassemblies that are set to "Master" and set them to be "Default". I have a lot of invisible parts in my assemblies therefore when the subassemblies get set to "Master" they show all parts even the invisible ones. I found a fix to the error message I was getting because I think you're right when it found a part file it will try to set it to "Default" view rep even when one doesn't exist in the part file.
Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
For Each oCompOcc in oAsmCompDef.Occurrences
oCompOcc.SetDesignViewRepresentation("Default",, True)
On Error Resume Next
Next
ThisApplication.ActiveView.Fit
Not sure why, but this message posted blank at first. Hopefully this time it will work.
I was trying to modify the code to accomplish something I've been looking for a way to do for a while. It almost (but not quite) worked, which is what my questions were regarding. While trying to do so, I changed the name of the view rep in the code to my intended one, and the error went away.
If you actually need your code to set assemblies to Default and parts to Master, you could use an If/Then to check whether the component is an assembly or part file, and set the view rep accordingly.
I ran into this problem again some months later and you're right you need to distinguish between "Part" and "Assembly" occurences therefore I came up with the following code:
Dim aDoc As AssemblyDocument aDoc = ThisApplication.ActiveDocument Dim oAsmCompDef As ComponentDefinition oAsmCompDef = aDoc.ComponentDefinition Dim oCompOcc As Inventor.ComponentOccurrence Dim iDoc As Document For Each iDoc In aDoc.AllReferencedDocuments If iDoc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then oCompOcc.SetDesignViewRepresentation("Default", True) Else End If On Error Resume Next Next ThisApplication.ActiveView.Fit
Let me know if this helps you out any.
Not sure if you needed this still but I finally figured out how to properly distinguish between a component occurence subassembly and part(it also makes sure the components that are visible get changed to "default" and not the ones I've made invisible or "suppressed"):
Dim doc As AssemblyDocument = ThisDoc.Document Dim oAsmCompDef As ComponentDefinition Dim oCompOcc As Inventor.ComponentOccurrence oAsmCompDef = doc.ComponentDefinition For Each oCompOcc in oAsmCompDef.Occurrences If oCompOcc.Visible = True Then If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then oCompOcc.SetDesignViewRepresentation("Default", True) Else End If Else End If On Error Resume Next Next
i tried to copy and paste your code in a vba environment (Inventor 2017)...it has issues with "oCompOcc.SetDesignViewRepresentation("Default", True)"
...?
Finally...tweak it a bit to run in VBA environment..well at least for anybody, who may still find this useful...
Public Sub test_VRSubComponent()
Dim aDoc As AssemblyDocument
Set aDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
Set oAsmCompDef = aDoc.ComponentDefinition
For Each oCompOcc In oAsmCompDef.Occurrences
If oCompOcc.Visible = True Then
If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call oCompOcc.SetDesignViewRepresentation("SH - MB", , True)
Else
End If
Else
End If
On Error Resume Next
Next
End Sub
Finally...tweak it a bit to run in VBA environment..well at least for anybody, who may still find this useful...
Public Sub test_VRSubComponent()
Dim aDoc As AssemblyDocument
Set aDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
Set oAsmCompDef = aDoc.ComponentDefinition
For Each oCompOcc In oAsmCompDef.Occurrences
If oCompOcc.Visible = True Then
If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call oCompOcc.SetDesignViewRepresentation("SH - MB", , True)
Else
End If
Else
End If
On Error Resume Next
Next
End Sub
Your code was helpful. Thanks.
It does well, I suggest you accept it as a solution. It will be highlighted with the green border and more viewers look at it.
'Representation op Configurator en associative Dim doc As AssemblyDocument = ThisDoc.Document Dim oAsmCompDef As ComponentDefinition Dim oCompOcc As Inventor.ComponentOccurrence oAsmCompDef = doc.ComponentDefinition For Each oCompOcc In oAsmCompDef.Occurrences If oCompOcc.Visible = True Then If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then oCompOcc.SetDesignViewRepresentation("Default",, True) Else End If Else End If On Error Resume Next Next ThisApplication.ActiveView.Fit
Can't find what you're looking for? Ask the community or share your knowledge.