Public Sub DebugObject_b()
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim oObj As Object
Set oObj = oDoc.SelectSet.Item(1)
Call oObj.SetDesignViewRepresentation("Default")
Call oObj.SetLevelOfDetailRepresentation("ilogic")
Debug.Print oObj.ActiveDesignViewRepresentation
Debug.Print oObj.ActiveLevelOfDetailRepresentation
End Sub
i am trying to set the ActiveDesignViewRepresentation of a selected assembly but it just doesn't set? the activelevelofdetail is setting just fine. is the ActiveDesignViewRepresentation locked? because i can't change the empty string(it becomes empty when i switch visibbility on/off) to for example a string with value "Default"
Solved! Go to Solution.
Solved by gerard87. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi gerard87,
Here is a link that might help. It's written in iLogic, but you can adjust for straight VB as needed. Note it has an example file set attached.
http://forums.autodesk.com/t5/Autodesk-Inventor/pos-rep-view-rep-and-ilogic/m-p/3371837
There is also this link that has some example code that sets the view representation in a subassembly (again using iLogic):
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
i see that you can set a design view of the main assembly like this but i want the code to run in the main assembly but set the design views of subassemblies. is this possible? because i can do it manually by right click on a subassembly -->represenations and set it.
code to set the design view of the mian assembly:
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = oDoc.ComponentDefinition
Call oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate
Sub designview()
''------------------------------------------------
ThisApplication = InventorVb.Application
Dim oDoc As Document = ThisDoc.Document
Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
For Each oCompOcc in oCompDef.Occurrences
oCompOcc. ' now i want to set the design view of a subassembly here but the SetDesignViewRepresentation()
doesn't set it.
Next
RuleParametersOutput() ' use this before DocumentUpdate
InventorVb.DocumentUpdate() ' Update now
End Sub
Hi gerard87,
Try something along these lines.
' set a reference to the assembly component definintion. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'define the Component Occurrence collection Dim oCompOcc As Inventor.ComponentOccurrence 'set top level view rep to Default oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate For each oCompOcc in oAsmCompDef.Occurrences 'example:
'CompOcc.SetDesignViewRepresentation("MyViewRep", "c:\Temp\PrivateVRepFile.idv", True) oCompOcc.SetDesignViewRepresentation("Red",, True) 'True sets the view rep to be associative Next
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
hoi.
thnx for your help, but if i try to set the design for an occurence with:
oCompOcc.SetDesignViewRepresentation("Default", True)
'The activedesignviewrepresentation string of the occurence still remains empty? it just doesn't set it?
but if i try to set the level of detail for the occurence with:
SetLevelOfDetailRepresentation("Default")
The string is set to Default.
So is there a bug in the occurences were you just can't set the design view?
Hi gerard87,
Try it with 2 commas:
oCompOcc.SetDesignViewRepresentation("Default",, True)
Tthere are 3 variables:
So you if you were to set the associative option to True, then you need the extra comma. Otherwise it reads False as the Private view rep file and fails.
When you specify just the view rep name like this:
oCompOcc.SetLevelOfDetailRepresentation("Default")
the private view rep file variable is assumed to be N/A and the associative variable is automatically set to False.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi Curtis,
Why when I try it 2 commas in VBA is rejected ?? (red line)
oCompOcc.SetDesignViewRepresentation("Default",, True)
Thanks in advance.
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
As much as i struggled to understand why my code was failing i finally came up with a solution for (Inventor 2017)
After i created the rule, i activated it in Event Triggers to be used after Open a document.
But because this can only run in Assy mode it creates errors in DWG and IPT(Derived)
My code takes care of that below while accomplishing everything you guys wanted to do above. Hope i helped somebody.
doc = ThisDoc.ModelDocument 'check to see that its not a derived document or drawing If Not ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then ' set a reference to the assembly component definintion. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'define the Component Occurrence collection Dim oCompOcc As Inventor.ComponentOccurrence 'set top level view rep to Default oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate Else Exit Sub End If
I used the code
doc = ThisDoc.ModelDocument 'check to see that its not a derived document or drawing If Not ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then ' set a reference to the assembly component definintion. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'define the Component Occurrence collection Dim oCompOcc As Inventor.ComponentOccurrence 'set top level view rep to Configurator oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Configurator").Activate Else Exit Sub End If
but this doesn't change the representations of my subassemblies. Can someone help me?