<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Rule to create view reps in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-to-create-view-reps/m-p/12860561#M168844</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been working on this rule and it works for the most part. there is one spot that I am hung up on. I lost the links but this is concatenated from a bunch of previous posts on this forum. The rule is setup to:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;-create view rep for each unique part in the assembly (filter out the phantom parts)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-scan each part for the custom iproperty "PART DESCRIPTION", if one exists then name the view rep that, if not then name the view rep the same as the part file name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-scan each part for the custom iproperty "CATEGORY", if the iprop exist, group the parts that share the same "CATEGORY" value (ex. WELDMENT), create and name the new view rep WELDMENT.&amp;nbsp; there will be maybe 6 different "CATEGORY" groups eventually.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first two sections work perfectly, and the third section partially works, the rule runs and creates the "CATEGORY" view rep, but there is only one visible part in the view rep, there should be more visible parts. I have tripled checked that the custom iprop does exist in the part files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas? thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;' Define current document
Dim openDoc As Document
openDoc = ThisDoc.Document

Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(openDoc, "Create View Rep's")

On Error Goto ErrorHandler

' Set a reference to the assembly component definition.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = openDoc.ComponentDefinition

' Define the first level components collection
Dim oCompOcc As Inventor.ComponentOccurrence

' Define view rep 
Dim oViewRep As DesignViewRepresentation

' Define an arraylist to hold the list of view rep names
Dim NameList As New Collection

' Look at the view reps in the assembly
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
    ' Set the list of names to the array list
    NameList.Add (oViewRep.Name)
Next

' Check for a Default view rep and create it if not found
If Not NameList.Contains("FULL ASSEMBLY") Then
    ' Create Default view rep 
    oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("FULL ASSEMBLY")
    oViewRep.ShowAll
    oViewRep.Activate
End If

' Zoom all
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute

' Dictionary to store parts by category
Dim CategoryParts As Object
CategoryParts = CreateObject("Scripting.Dictionary")

' Look at all of the unique parts in the assembly
For Each docFile In openDoc.AllReferencedDocuments
    If oCompDef.Occurrences.AllReferencedOccurrences(docFile).Count &amp;gt; 0 Then ' Avoid to create a view rep for base part of derived parts
        If Not docFile.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then
            If docFile.DocumentType = 12290 Then ' 12290 is the part document enumerator
                ' Locate the last backslash position in the full file name
                Dim FNamePos As Long
                FNamePos = InStrRev(docFile.FullFileName, "\", -1)
                ' Remove path from part file name     
                Dim docFName As String
                docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
                ' Remove extension from part file name 
                Dim ShortName As String
                ShortName = Left(docFName, Len(docFName) - 4)

                ' Check for the custom iProperty "PART DESCRIPTION"
                Dim partDescription As String
                partDescription = ""
                On Error Resume Next
                partDescription = docFile.PropertySets.Item("Inventor User Defined Properties").Item("PART DESCRIPTION").Value
                On Error Goto 0

                ' Determine view representation name
                Dim viewRepName As String
                If partDescription &amp;lt;&amp;gt; "" Then
                    viewRepName = partDescription
                Else
                    viewRepName = ShortName
                End If

                ' Check to see if the arraylist contains the desired view rep
                If Not NameList.Contains(viewRepName) Then
                    ' Create new View Rep 
                    oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(viewRepName)
                    oViewRep.Activate
                    oViewRep.Locked = False
                Else
                    ' Reference existing View Rep 
                    oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(viewRepName)
                    oViewRep.Activate
                    oViewRep.Locked = False
                End If

                Dim bSkip As Boolean
                bSkip = False
                ' Look at all of the occurrences
                For Each oCompOcc In oCompDef.Occurrences.AllLeafOccurrences
                    ' Locate the colon position in the occurrence name
                    Dim oCompOccPos As Long
                    oCompOccPos = InStrRev(oCompOcc.Name, ":")
                    If oCompOccPos &amp;lt; 2 Then oCompOccPos = Len(oCompOcc.Name)
                    ' Set occurrence name to everything left of the colon
                    Dim oOccName As String
                    oOccName = Left(oCompOcc.Name, oCompOccPos - 1)
                    ' Set visible if name matches first occurrence
                    If System.IO.Path.GetFileNameWithoutExtension(oCompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName) = ShortName And bSkip = False Then
                        oCompOcc.Visible = True
                        ThisApplication.ActiveView.Update
                        bSkip = True ' Even if there is more than one occurrence named "xyz:1" in different sub-assemblies, we want only one occurrence in our view rep
                    Else
                        oCompOcc.Visible = False
                        ThisApplication.ActiveView.Update
                    End If
                Next

                ' Lock view rep
                oViewRep.Locked = True

                ' Check for the custom iProperty "CATEGORY"
                Dim category As String
                category = ""
                On Error Resume Next
                category = docFile.PropertySets.Item("Inventor User Defined Properties").Item("CATEGORY").Value
                On Error Goto 0

                ' Add part to the corresponding category list
                If category &amp;lt;&amp;gt; "" Then
                    If Not CategoryParts.Exists(category) Then
                        CategoryParts.Add (category, New Collection)
                    End If
                    CategoryParts(category).Add (docFile)
                End If
            End If
        End If
    End If
Next

' Create view representations for each category
For Each category In CategoryParts.Keys
    ' Check to see if the arraylist contains the desired view rep
    If Not NameList.Contains(category) Then
        ' Create new View Rep 
        oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(category)
        oViewRep.Activate
        oViewRep.Locked = False
    Else
        ' Reference existing View Rep 
        oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(category)
        oViewRep.Activate
        oViewRep.Locked = False
    End If

    ' Set visibility for parts in the category
    For Each docFile In CategoryParts(category)
        Dim bSkip As Boolean
        bSkip = False
        For Each oCompOcc In oCompDef.Occurrences.AllLeafOccurrences
            ' Locate the colon position in the occurrence name
            Dim oCompOccPos As Long
            oCompOccPos = InStrRev(oCompOcc.Name, ":")
            If oCompOccPos &amp;lt; 2 Then oCompOccPos = Len(oCompOcc.Name)
            ' Set occurrence name to everything left of the colon
            Dim oOccName As String
            oOccName = Left(oCompOcc.Name, oCompOccPos - 1)
            ' Set visible if name matches first occurrence
            If System.IO.Path.GetFileNameWithoutExtension(oCompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName) = _
                    System.IO.Path.GetFileNameWithoutExtension(docFile.FullFileName) And bSkip = False Then
                oCompOcc.Visible = True
                ThisApplication.ActiveView.Update
                bSkip = True ' Even if there is more than one occurrence named "xyz:1" in different sub-assemblies, we want only one occurrence in our view rep
            Else
                oCompOcc.Visible = False
                ThisApplication.ActiveView.Update
            End If
        Next
    Next

    ' Lock view rep
    oViewRep.Locked = True
Next

' Set Default View Rep active
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("FULL ASSEMBLY").Activate

oTrans.End
Exit Sub

ErrorHandler:
MsgBox (Err.Description)
oTrans.Abort&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 25 Jun 2024 16:20:16 GMT</pubDate>
    <dc:creator>Shag_Bore</dc:creator>
    <dc:date>2024-06-25T16:20:16Z</dc:date>
    <item>
      <title>Rule to create view reps</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-to-create-view-reps/m-p/12860561#M168844</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been working on this rule and it works for the most part. there is one spot that I am hung up on. I lost the links but this is concatenated from a bunch of previous posts on this forum. The rule is setup to:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;-create view rep for each unique part in the assembly (filter out the phantom parts)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-scan each part for the custom iproperty "PART DESCRIPTION", if one exists then name the view rep that, if not then name the view rep the same as the part file name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-scan each part for the custom iproperty "CATEGORY", if the iprop exist, group the parts that share the same "CATEGORY" value (ex. WELDMENT), create and name the new view rep WELDMENT.&amp;nbsp; there will be maybe 6 different "CATEGORY" groups eventually.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first two sections work perfectly, and the third section partially works, the rule runs and creates the "CATEGORY" view rep, but there is only one visible part in the view rep, there should be more visible parts. I have tripled checked that the custom iprop does exist in the part files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas? thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;' Define current document
Dim openDoc As Document
openDoc = ThisDoc.Document

Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(openDoc, "Create View Rep's")

On Error Goto ErrorHandler

' Set a reference to the assembly component definition.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = openDoc.ComponentDefinition

' Define the first level components collection
Dim oCompOcc As Inventor.ComponentOccurrence

' Define view rep 
Dim oViewRep As DesignViewRepresentation

' Define an arraylist to hold the list of view rep names
Dim NameList As New Collection

' Look at the view reps in the assembly
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
    ' Set the list of names to the array list
    NameList.Add (oViewRep.Name)
Next

' Check for a Default view rep and create it if not found
If Not NameList.Contains("FULL ASSEMBLY") Then
    ' Create Default view rep 
    oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("FULL ASSEMBLY")
    oViewRep.ShowAll
    oViewRep.Activate
End If

' Zoom all
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute

' Dictionary to store parts by category
Dim CategoryParts As Object
CategoryParts = CreateObject("Scripting.Dictionary")

' Look at all of the unique parts in the assembly
For Each docFile In openDoc.AllReferencedDocuments
    If oCompDef.Occurrences.AllReferencedOccurrences(docFile).Count &amp;gt; 0 Then ' Avoid to create a view rep for base part of derived parts
        If Not docFile.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then
            If docFile.DocumentType = 12290 Then ' 12290 is the part document enumerator
                ' Locate the last backslash position in the full file name
                Dim FNamePos As Long
                FNamePos = InStrRev(docFile.FullFileName, "\", -1)
                ' Remove path from part file name     
                Dim docFName As String
                docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
                ' Remove extension from part file name 
                Dim ShortName As String
                ShortName = Left(docFName, Len(docFName) - 4)

                ' Check for the custom iProperty "PART DESCRIPTION"
                Dim partDescription As String
                partDescription = ""
                On Error Resume Next
                partDescription = docFile.PropertySets.Item("Inventor User Defined Properties").Item("PART DESCRIPTION").Value
                On Error Goto 0

                ' Determine view representation name
                Dim viewRepName As String
                If partDescription &amp;lt;&amp;gt; "" Then
                    viewRepName = partDescription
                Else
                    viewRepName = ShortName
                End If

                ' Check to see if the arraylist contains the desired view rep
                If Not NameList.Contains(viewRepName) Then
                    ' Create new View Rep 
                    oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(viewRepName)
                    oViewRep.Activate
                    oViewRep.Locked = False
                Else
                    ' Reference existing View Rep 
                    oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(viewRepName)
                    oViewRep.Activate
                    oViewRep.Locked = False
                End If

                Dim bSkip As Boolean
                bSkip = False
                ' Look at all of the occurrences
                For Each oCompOcc In oCompDef.Occurrences.AllLeafOccurrences
                    ' Locate the colon position in the occurrence name
                    Dim oCompOccPos As Long
                    oCompOccPos = InStrRev(oCompOcc.Name, ":")
                    If oCompOccPos &amp;lt; 2 Then oCompOccPos = Len(oCompOcc.Name)
                    ' Set occurrence name to everything left of the colon
                    Dim oOccName As String
                    oOccName = Left(oCompOcc.Name, oCompOccPos - 1)
                    ' Set visible if name matches first occurrence
                    If System.IO.Path.GetFileNameWithoutExtension(oCompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName) = ShortName And bSkip = False Then
                        oCompOcc.Visible = True
                        ThisApplication.ActiveView.Update
                        bSkip = True ' Even if there is more than one occurrence named "xyz:1" in different sub-assemblies, we want only one occurrence in our view rep
                    Else
                        oCompOcc.Visible = False
                        ThisApplication.ActiveView.Update
                    End If
                Next

                ' Lock view rep
                oViewRep.Locked = True

                ' Check for the custom iProperty "CATEGORY"
                Dim category As String
                category = ""
                On Error Resume Next
                category = docFile.PropertySets.Item("Inventor User Defined Properties").Item("CATEGORY").Value
                On Error Goto 0

                ' Add part to the corresponding category list
                If category &amp;lt;&amp;gt; "" Then
                    If Not CategoryParts.Exists(category) Then
                        CategoryParts.Add (category, New Collection)
                    End If
                    CategoryParts(category).Add (docFile)
                End If
            End If
        End If
    End If
Next

' Create view representations for each category
For Each category In CategoryParts.Keys
    ' Check to see if the arraylist contains the desired view rep
    If Not NameList.Contains(category) Then
        ' Create new View Rep 
        oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(category)
        oViewRep.Activate
        oViewRep.Locked = False
    Else
        ' Reference existing View Rep 
        oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(category)
        oViewRep.Activate
        oViewRep.Locked = False
    End If

    ' Set visibility for parts in the category
    For Each docFile In CategoryParts(category)
        Dim bSkip As Boolean
        bSkip = False
        For Each oCompOcc In oCompDef.Occurrences.AllLeafOccurrences
            ' Locate the colon position in the occurrence name
            Dim oCompOccPos As Long
            oCompOccPos = InStrRev(oCompOcc.Name, ":")
            If oCompOccPos &amp;lt; 2 Then oCompOccPos = Len(oCompOcc.Name)
            ' Set occurrence name to everything left of the colon
            Dim oOccName As String
            oOccName = Left(oCompOcc.Name, oCompOccPos - 1)
            ' Set visible if name matches first occurrence
            If System.IO.Path.GetFileNameWithoutExtension(oCompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName) = _
                    System.IO.Path.GetFileNameWithoutExtension(docFile.FullFileName) And bSkip = False Then
                oCompOcc.Visible = True
                ThisApplication.ActiveView.Update
                bSkip = True ' Even if there is more than one occurrence named "xyz:1" in different sub-assemblies, we want only one occurrence in our view rep
            Else
                oCompOcc.Visible = False
                ThisApplication.ActiveView.Update
            End If
        Next
    Next

    ' Lock view rep
    oViewRep.Locked = True
Next

' Set Default View Rep active
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("FULL ASSEMBLY").Activate

oTrans.End
Exit Sub

ErrorHandler:
MsgBox (Err.Description)
oTrans.Abort&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 25 Jun 2024 16:20:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-to-create-view-reps/m-p/12860561#M168844</guid>
      <dc:creator>Shag_Bore</dc:creator>
      <dc:date>2024-06-25T16:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Rule to create view reps</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-to-create-view-reps/m-p/12861458#M168853</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12711543"&gt;@Shag_Bore&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I quickly reviewed the code and couldn't really see the issue, so I can only offer a little advice having done this process before.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If you have narrowed your problem area set up some logger statements and check the occurrence name is being logically reached based on needing to be visible or not.&lt;/LI&gt;&lt;LI&gt;I would suggest to use Try Catch Statements over On Error Resume Next. You really have no indication of what is happening with the On Error methods.&lt;/LI&gt;&lt;LI&gt;I see two leaf occurrences loops are they both needed or could you put it in a function or to store the occurrences as a list of occurrences?&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;i see you create weekly typed Collections rather than to explicitly declare the type. Example for string. this can help narrow down issues if the wrong object type gets added into the collection.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim list as New List  (Of String)

Dim occList as New List  (Of ComponentOccurrence)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If this section of code is designed to get the filename without extension&amp;nbsp; then I would suggest to change it to System IO method as it has less lines. The method here looks more like old VBA methods.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="visual-basic"&gt;' Locate the last backslash position in the full file name
                Dim FNamePos As Long
                FNamePos = InStrRev(docFile.FullFileName, "\", -1)
                ' Remove path from part file name     
                Dim docFName As String
                docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
                ' Remove extension from part file name 
                Dim ShortName As String
                ShortName = Left(docFName, Len(docFName) - 4)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You actually use it further down the code.&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;ShortName = System.IO.Path.GetFileNameWithoutExtension(oCompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In this section there is a good lot of code duplication with the same definition variables used in different places all the way through the code. It will work but it could lead to issues identifying what is going on especially when trying to target sub assemblies etc.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="visual-basic"&gt;' Define current document
Dim openDoc As Document
openDoc = ThisDoc.Document

Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(openDoc, "Create View Rep's")

On Error Goto ErrorHandler

' Set a reference to the assembly component definition.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = openDoc.ComponentDefinition&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 02:55:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-to-create-view-reps/m-p/12861458#M168853</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2024-06-26T02:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Rule to create view reps</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-to-create-view-reps/m-p/12863401#M168890</link>
      <description>&lt;P&gt;Hi, try this code it has a recursive function so it will find every Occurrence in the assembly tree.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;main&lt;/SPAN&gt;
	 &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;CATEGORYVALUE&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;"ex.WELDMENT"&lt;/SPAN&gt;
        &lt;SPAN&gt;' Get the active assembly.&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAsmDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAssyCompdef&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentDefinition&lt;/SPAN&gt; = &lt;SPAN&gt;oAsmDoc&lt;/SPAN&gt;.&lt;SPAN&gt;ComponentDefinition&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;ViewRep&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DesignViewRepresentation&lt;/SPAN&gt; = &lt;SPAN&gt;SetDesignview&lt;/SPAN&gt;(&lt;SPAN&gt;oAssyCompdef&lt;/SPAN&gt;, &lt;SPAN&gt;CATEGORYVALUE&lt;/SPAN&gt;)

        &lt;SPAN&gt;' Call the function that does the recursion.&lt;/SPAN&gt;
        &lt;SPAN&gt;TraverseAssembly&lt;/SPAN&gt;(&lt;SPAN&gt;oAsmDoc&lt;/SPAN&gt;.&lt;SPAN&gt;ComponentDefinition&lt;/SPAN&gt;.&lt;SPAN&gt;Occurrences&lt;/SPAN&gt;, 1, &lt;SPAN&gt;CATEGORYVALUE&lt;/SPAN&gt;)

        &lt;SPAN&gt;ViewRep&lt;/SPAN&gt;.&lt;SPAN&gt;Locked&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;
	
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;


&lt;SPAN&gt;Private&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;TraverseAssembly&lt;/SPAN&gt;(&lt;SPAN&gt;Occurrences&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentOccurrences&lt;/SPAN&gt;, &lt;SPAN&gt;Level&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Integer&lt;/SPAN&gt;, &lt;SPAN&gt;PropValue&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;)
        &lt;SPAN&gt;' Iterate through all of the occurrence in this collection.  This&lt;/SPAN&gt;
        &lt;SPAN&gt;' represents the occurrences at the top level of an assembly.&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentOccurrence&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;value&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
        &lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;Occurrences&lt;/SPAN&gt;
            &lt;SPAN&gt;' Print the name of the current occurrence.&lt;/SPAN&gt;
            &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oCompdef&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentDefinition&lt;/SPAN&gt; = &lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Definition&lt;/SPAN&gt;
            &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Document&lt;/SPAN&gt; = &lt;SPAN&gt;oCompdef&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;
            &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oCustomprop&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Inventor&lt;/SPAN&gt;.&lt;SPAN&gt;Property&lt;/SPAN&gt; = &lt;SPAN&gt;Getproperty&lt;/SPAN&gt;(&lt;SPAN&gt;oDoc&lt;/SPAN&gt;, &lt;SPAN&gt;"CATEGORY"&lt;/SPAN&gt;)
            &lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Visible&lt;/SPAN&gt; = &lt;SPAN&gt;False&lt;/SPAN&gt;
            &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oCustomprop&lt;/SPAN&gt; &lt;SPAN&gt;IsNot&lt;/SPAN&gt; &lt;SPAN&gt;Nothing&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
                &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oCustomprop&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt; = &lt;SPAN&gt;PropValue&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
                    &lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Visible&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;
                &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
            &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
            &lt;SPAN&gt;' Check to see if this occurrence represents a subassembly&lt;/SPAN&gt;
            &lt;SPAN&gt;' and recursively call this function to traverse through it.&lt;/SPAN&gt;
            &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;DefinitionDocumentType&lt;/SPAN&gt; = &lt;SPAN&gt;DocumentTypeEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kAssemblyDocumentObject&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
                &lt;SPAN&gt;TraverseAssembly&lt;/SPAN&gt;(&lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;SubOccurrences&lt;/SPAN&gt;, &lt;SPAN&gt;Level&lt;/SPAN&gt; + 1, &lt;SPAN&gt;PropValue&lt;/SPAN&gt;)
            &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
        &lt;SPAN&gt;Next&lt;/SPAN&gt;
    &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;

&lt;SPAN&gt;Private&lt;/SPAN&gt; &lt;SPAN&gt;Function&lt;/SPAN&gt; &lt;SPAN&gt;Getproperty&lt;/SPAN&gt;(&lt;SPAN&gt;ByVal&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Document&lt;/SPAN&gt;, &lt;SPAN&gt;ByVal&lt;/SPAN&gt; &lt;SPAN&gt;Prop&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;)
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;result&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Inventor&lt;/SPAN&gt;.&lt;SPAN&gt;Property&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
        &lt;SPAN&gt;Try&lt;/SPAN&gt;
            &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oPropertyset&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;PropertySet&lt;/SPAN&gt; = &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;PropertySets&lt;/SPAN&gt;(&lt;SPAN&gt;"Inventor User Defined Properties"&lt;/SPAN&gt;)
            &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oProperty&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Inventor&lt;/SPAN&gt;.&lt;SPAN&gt;Property&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
            &lt;SPAN&gt;Try&lt;/SPAN&gt;
                &lt;SPAN&gt;oProperty&lt;/SPAN&gt; = &lt;SPAN&gt;oPropertyset&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;Prop&lt;/SPAN&gt;)
            &lt;SPAN&gt;Catch&lt;/SPAN&gt; &lt;SPAN&gt;ex&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Exception&lt;/SPAN&gt;
            &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;
            &lt;SPAN&gt;result&lt;/SPAN&gt; = &lt;SPAN&gt;oProperty&lt;/SPAN&gt;
        &lt;SPAN&gt;Catch&lt;/SPAN&gt; &lt;SPAN&gt;ex&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Exception&lt;/SPAN&gt;
            &lt;SPAN&gt;MsgBox&lt;/SPAN&gt;(&lt;SPAN&gt;ex&lt;/SPAN&gt;.&lt;SPAN&gt;ToString&lt;/SPAN&gt;, &lt;SPAN&gt;MsgBoxStyle&lt;/SPAN&gt;.&lt;SPAN&gt;Critical&lt;/SPAN&gt;, &lt;SPAN&gt;"Getproperty"&lt;/SPAN&gt;)
        &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;
        &lt;SPAN&gt;Return&lt;/SPAN&gt; &lt;SPAN&gt;result&lt;/SPAN&gt;
    &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Function&lt;/SPAN&gt;
	
	 &lt;SPAN&gt;Private&lt;/SPAN&gt; &lt;SPAN&gt;Function&lt;/SPAN&gt; &lt;SPAN&gt;SetDesignview&lt;/SPAN&gt;(&lt;SPAN&gt;ByVal&lt;/SPAN&gt; &lt;SPAN&gt;oAssyCompDef&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyComponentDefinition&lt;/SPAN&gt;, &lt;SPAN&gt;ViewRepName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;) &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DesignViewRepresentation&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;result&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DesignViewRepresentation&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;ViewRep&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DesignViewRepresentation&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;ViewReps&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DesignViewRepresentations&lt;/SPAN&gt; = &lt;SPAN&gt;oAssyCompDef&lt;/SPAN&gt;.&lt;SPAN&gt;RepresentationsManager&lt;/SPAN&gt;.&lt;SPAN&gt;DesignViewRepresentations&lt;/SPAN&gt;
        &lt;SPAN&gt;Try&lt;/SPAN&gt;
            &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;ViewRepExist&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Boolean&lt;/SPAN&gt; = &lt;SPAN&gt;False&lt;/SPAN&gt;
            &lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;ViewRep&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;ViewReps&lt;/SPAN&gt;
                &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;ViewRep&lt;/SPAN&gt;.&lt;SPAN&gt;Name&lt;/SPAN&gt; = &lt;SPAN&gt;ViewRepName&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
                    &lt;SPAN&gt;ViewRep&lt;/SPAN&gt;.&lt;SPAN&gt;Activate&lt;/SPAN&gt;()
                    &lt;SPAN&gt;ViewRepExist&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;
                    &lt;SPAN&gt;Exit&lt;/SPAN&gt; &lt;SPAN&gt;For&lt;/SPAN&gt;
                &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
            &lt;SPAN&gt;Next&lt;/SPAN&gt;
            &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;ViewRepExist&lt;/SPAN&gt; = &lt;SPAN&gt;False&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
                &lt;SPAN&gt;ViewRep&lt;/SPAN&gt; = &lt;SPAN&gt;oAssyCompDef&lt;/SPAN&gt;.&lt;SPAN&gt;RepresentationsManager&lt;/SPAN&gt;.&lt;SPAN&gt;DesignViewRepresentations&lt;/SPAN&gt;.&lt;SPAN&gt;Add&lt;/SPAN&gt;(&lt;SPAN&gt;ViewRepName&lt;/SPAN&gt;)
                &lt;SPAN&gt;ViewRep&lt;/SPAN&gt;.&lt;SPAN&gt;Activate&lt;/SPAN&gt;()
            &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
        &lt;SPAN&gt;Catch&lt;/SPAN&gt; &lt;SPAN&gt;ex&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Exception&lt;/SPAN&gt;
        &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;
        &lt;SPAN&gt;result&lt;/SPAN&gt; = &lt;SPAN&gt;ViewRep&lt;/SPAN&gt;
        &lt;SPAN&gt;Return&lt;/SPAN&gt; &lt;SPAN&gt;result&lt;/SPAN&gt;
    &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Function&lt;/SPAN&gt;
	
	&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 20:38:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-to-create-view-reps/m-p/12863401#M168890</guid>
      <dc:creator>nstevelmans</dc:creator>
      <dc:date>2024-06-26T20:38:00Z</dc:date>
    </item>
  </channel>
</rss>

