Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dears,
Is possible active Part's Representation Design Views from an Assembly?
Thanks,
Solved! Go to Solution.
Dears,
Is possible active Part's Representation Design Views from an Assembly?
Thanks,
Solved! Go to Solution.
Hi @ngdnam88,
You could do as folowing :
Dim doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim pcd As Inventor.AssemblyComponentDefinition = doc.ComponentDefinition
Dim o As Inventor.ComponentOccurrence = pcd.Occurrences.ItemByName("Baffle corner LEFT:1") 'change name of occ
o.SetDesignViewRepresentation("Vue1", False, True) 'change name of view rep
Does this suits your needs ?
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"Hi @ngdnam88. If I am understanding your question correctly, you want to know if it is possible to set which DVR (DesignViewRepresentation) a part type component in an assembly is set to from within the assembly, by code. Does that sound accurate? If so, then @FINET_Laurent example above shows a simple way to do that, by using the SetDesignViewRepresentation method of the ComponentOccurrence object (assembly component). But if you mean that you want to change the component's DVR by changing the assembly's DVR, then that is not normally possible, but it may be possible through the use of some custom event handler code. Custom event handler codes are usually best suited for Inventor ApplicationAddIns, but they can be created by iLogic rules too. Below is an example of an iLogic rule you may be able to use for setting up a scenario like that. When you have an assembly open, and that assembly has multiple DVR's of its own, and there are multiple components within the assembly that each have multiple DVRs, and their names match the DVR's of the main assembly...then running this rule just once while that assembly is open will create 2 event 'listeners' that will continue running in the background, until you close that assembly. While it is running, it will 'listen' for the event of you activating a DVR in the assembly, and when that happens, it will run the custom Sub routine which will attempt to iterate through every component within the assembly, and attempt to set the component to the same DVR as the main assembly. Then when you close that assembly, those event 'listeners' will be removed. But do not run this rule more than once while that main assembly is open, or multiple event handlers will be running in the background, and possibly reduce Inventor's performance.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
oADoc = ThisDoc.Document
oDocEvents = oADoc.DocumentEvents
oRepEvents = ThisApplication.RepresentationEvents
AddHandler oRepEvents.OnActivateDesignView, AddressOf oRepEvents_OnActivateDesignView
AddHandler oDocEvents.OnClose, AddressOf oDocEvents_OnClose
End Sub
Dim oADoc As AssemblyDocument
Dim oDocEvents As DocumentEvents
Dim oRepEvents As RepresentationEvents
Sub oRepEvents_OnActivateDesignView(Doc As Inventor.Document, DVR As DesignViewRepresentation, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
If Doc IsNot oADoc Then Exit Sub
UpdateComponentDVR(oADoc.ComponentDefinition.Occurrences, DVR.Name)
End Sub
Sub UpdateComponentDVR(oComps As ComponentOccurrences, sDVRName As String)
If (oComps Is Nothing OrElse oComps.Count = 0) Or sDVRName = "" Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
If oComp.Suppressed Then Continue For
If TypeOf oComp.Definition Is VirtualComponentDefinition Then Continue For
If TypeOf oComp.Definition Is WeldsComponentDefinition Then Continue For
Try : oComp.SetDesignViewRepresentation(sDVRName) : Catch : End Try
If oComp.SubOccurrences.Count > 0 Then
UpdateComponentDVR(oComp.SubOccurrences, sDVRName)
End If
Next 'oComp
End Sub
Sub oDocEvents_OnClose(BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
RemoveHandler oRepEvents.OnActivateDesignView, AddressOf oRepEvents_OnActivateDesignView
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @FINET_Laurent @WCrihfield
Thanks for your helps! I really post a similar post: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/create-link-design-view-representati...
I'm working with this Code:
Sub Main()
Dim oIvnApp As Inventor.Application = ThisApplication
Dim oDoc As Document = oIvnApp.ActiveDocument
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
If oOccs.Count = 0 Then Exit Sub
Dim oRepMng As RepresentationsManager = oAsmDoc.ComponentDefinition.RepresentationsManager
Dim oActView As DesignViewRepresentation = oRepMng.ActiveDesignViewRepresentation
Dim oAsmViewReps As DesignViewRepresentations = oRepMng.DesignViewRepresentations
Dim oOcc As ComponentOccurrence = oOccs(1)
Dim oPartDef As PartComponentDefinition = oOcc.Definition
Dim oViewReps As DesignViewRepresentations = oPartDef.RepresentationsManager.DesignViewRepresentations
For Each oViewRep As DesignViewRepresentation In oViewReps
Dim oAsmViewRep As DesignViewRepresentation
Try
oAsmViewRep = oAsmViewReps(oViewRep.Name)
Catch
oAsmViewRep = oAsmViewReps.Add(oViewRep.Name)
End Try
Next
For Each cActView As DesignViewRepresentation In oAsmViewReps
Dim oAsmViewRep As DesignViewRepresentation = oAsmViewReps(cActView.Name)
oAsmViewRep.Activate()
Try
oOcc.SetDesignViewRepresentation(cActView.Name,, True)
Catch
End Try
oDoc.Save()
Next
End Sub
I found the important key of these code is "oDoc.Save()" because of each Assembly's DVR need to save after change Part's DVR!
@WCrihfield : I'm trying using your code to my InventorAddin, your code is higher level my issue.
The above Code is for one assembly with one part inside. At the moment, I'm trying with more than one part inside the assembly (I only works with one assembly with all part inside not sub.assembly). Is possible take list of all parts's DVR then add to assembly - skip the duplicate part's DVR, of course 😄
It looks like your code is already just about done, so I mainly just added the main loop of the components, while avoiding processing the same referenced document more than once.
Sub Main()
Dim oIvnApp As Inventor.Application = ThisApplication
Dim oDoc As Document = oIvnApp.ActiveDocument
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
If oOccs.Count = 0 Then Exit Sub
Dim oRepMng As RepresentationsManager = oAsmDoc.ComponentDefinition.RepresentationsManager
Dim oActView As DesignViewRepresentation = oRepMng.ActiveDesignViewRepresentation
Dim oAsmViewReps As DesignViewRepresentations = oRepMng.DesignViewRepresentations
Dim oOccDocs As New List(Of Inventor.Document)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If (TypeOf oOcc.Definition Is PartComponentDefinition) = False Then Continue For
Dim oPartDef As PartComponentDefinition = oOcc.Definition
Dim oOccDoc As Document = oPartDef.Document
If oOccDocs.Contains(oOccDoc) Then
Continue For
Else
oOccDocs.Add(oOccDoc)
End If
Dim oViewReps As DesignViewRepresentations = oPartDef.RepresentationsManager.DesignViewRepresentations
For Each oViewRep As DesignViewRepresentation In oViewReps
Dim oAsmViewRep As DesignViewRepresentation = Nothing
Try
oAsmViewRep = oAsmViewReps(oViewRep.Name)
Catch
oAsmViewRep = oAsmViewReps.Add(oViewRep.Name)
End Try
Next 'oViewRep
For Each cActView As DesignViewRepresentation In oAsmViewReps
cActView.Activate
Try
oOcc.SetDesignViewRepresentation(cActView.Name,, True)
Catch
End Try
oDoc.Save()
Next 'cActView
Next 'oOcc
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
Actually that last code I just posted might not work out correctly, because by avoiding processing the same referenced document twice, it also will not set other components referencing that same document to the DVR you want. So we might need to use a 'GoTo' statement, instead of a 'Continue For' statement, when the same referenced document is encountered, to allow it to skip the first internal loop, where it is trying to copy DVRs from the part to the assembly, while allowing the second loop to run, where it sets the component to the assembly's active DVR.
Edit: Maybe try this edited version.
Sub Main()
Dim oIvnApp As Inventor.Application = ThisApplication
Dim oDoc As Document = oIvnApp.ActiveDocument
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
If oOccs.Count = 0 Then Exit Sub
Dim oRepMng As RepresentationsManager = oAsmDoc.ComponentDefinition.RepresentationsManager
Dim oActView As DesignViewRepresentation = oRepMng.ActiveDesignViewRepresentation
Dim oAsmViewReps As DesignViewRepresentations = oRepMng.DesignViewRepresentations
Dim oOccDocs As New List(Of Inventor.Document)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If (TypeOf oOcc.Definition Is PartComponentDefinition) = False Then Continue For
Dim oPartDef As PartComponentDefinition = oOcc.Definition
Dim oOccDoc As Document = oPartDef.Document
If oOccDocs.Contains(oOccDoc) Then
GoTo SetCompDVRs
Else
oOccDocs.Add(oOccDoc)
End If
Dim oViewReps As DesignViewRepresentations = oPartDef.RepresentationsManager.DesignViewRepresentations
For Each oViewRep As DesignViewRepresentation In oViewReps
Dim oAsmViewRep As DesignViewRepresentation = Nothing
Try
oAsmViewRep = oAsmViewReps(oViewRep.Name)
Catch
oAsmViewRep = oAsmViewReps.Add(oViewRep.Name)
End Try
Next 'oViewRep
SetCompDVRs :
For Each cActView As DesignViewRepresentation In oAsmViewReps
cActView.Activate
Try
oOcc.SetDesignViewRepresentation(cActView.Name,, True)
Catch
End Try
oDoc.Save()
Next 'cActView
Next 'oOcc
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
Hi @WCrihfield,
We seem to be getting close to perfect results. How to visibility all other component keep one working only?
And with the same component we only need working in one of them, not all of them.