Working with Assembly Design View Representation

Working with Assembly Design View Representation

JBerns
Advisor Advisor
3,088 Views
8 Replies
Message 1 of 9

Working with Assembly Design View Representation

JBerns
Advisor
Advisor

Community,

 

I am developing code (VBA) that will create drawing views from assembly Design View Representations (DVRs).

 

Using this code, I can get the count and names of the DVRs:

Public Sub ListDesignViewReps()
    Dim oView As Inventor.DesignViewRepresentation
    Dim oCompDef As ComponentDefinition
    Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    MsgBox ("Number of DVRs: " & oCompDef.RepresentationsManager.DesignViewRepresentations.Count)
    For Each oView In oCompDef.RepresentationsManager.DesignViewRepresentations
        MsgBox ("DVR Name: " & oView.Name)
    Next
End Sub

However, if the Master DVR is active, the number of DVRs reported is Actual + 1.

For example, an assembly with a Master and Default DVR will report a count of 3 and Master is listed twice.

If Default is active, the count reports as 2 and Master is listed only once.

 

Can anyone explain why having the Master DVR active changes the actual count?

I can likely workaround this issue, but I found it confusing. I have not tested with Pos Reps or LODs.

 

 

Regards,

Jerry 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Accepted solutions (1)
3,089 Views
8 Replies
Replies (8)
Message 2 of 9

Sergio.D.Suárez
Mentor
Mentor

Hi, I really don't know why this error appears. I can only suggest you avoid it.
Then I share a VBA code that may solve this problem.

 

 

Public Sub ListDesignViewReps()
    Dim oView As Inventor.DesignViewRepresentation
    Dim oCompDef As ComponentDefinition
    Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    Dim oActiveDVR As Inventor.DesignViewRepresentation
    Set oActiveDVR = oCompDef.RepresentationsManager.ActiveDesignViewRepresentation

    Dim j As Integer, i As Integer
    j = 0
    
    If oActiveDVR.Name = "Master" Then j = 1
    
    MsgBox ("Number of DVRs: " & oCompDef.RepresentationsManager.DesignViewRepresentations.Count - j)
   
   For i = 1 To oCompDef.RepresentationsManager.DesignViewRepresentations.Count - j
    
        Set oView = oCompDef.RepresentationsManager.DesignViewRepresentations(i)
        oView.Activate
        
        MsgBox ("DVR Name: " & oView.Name)
    Next
End Sub


I hope I can be useful. regards

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 9

JBerns
Advisor
Advisor

@Sergio.D.Suárez,

 

It is a peculiar behavior. I was able to test Pos Reps and LODs. Neither of these exhibit the varying count behavior as the DVRs.

 

My plan is to filter for specifically named DVRs, so I should be able to avoid the issue with the Master DVR. Thank you for the code though.

 

Next, I need to code to create a new drawing from an assembly and then a sufficient number of sheets based on the number of DVRs.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 4 of 9

HideoYamada
Advisor
Advisor

Hello,

 

This code may not work properly in Non-English environments.

    If oActiveDVR.Name = "Master" Then j = 1

 

I have run this test code in Inventor with Japanese language pack,

Sub test()
    Dim rm As RepresentationsManager
    Set rm = ThisApplication.ActiveDocument.ComponentDefinition.RepresentationsManager

    Debug.Print "Name  : " & rm.ActiveDesignViewRepresentation.Name
    Debug.Print "Test1 : " & (rm.ActiveDesignViewRepresentation.Name = "Master")
    Debug.Print "Test2 : " & (rm.ActiveDesignViewRepresentation.Name = rm.DesignViewRepresentations(1).Name)
    Debug.Print "Test3 : " & (rm.ActiveDesignViewRepresentation.DesignViewType = kTransientDesignViewType)
End Sub

and got the result as below.

Name  : マスター
Test1 : False
Test2 : True
Test3 : True

The name "マスター" means "Master" in Japanese.

I don't understand exactly what kTransientDesignViewType means, but Test3 seems to work fine.

 

I hope this helps you.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 5 of 9

fransoze
Explorer
Explorer
Accepted solution

Hello,

You have 3 DVR because "Master" view is active and "Master" view is locked so Inventor make a transient view.

 

If you locked "view1" and activate this, you have 3 DVR too.

 

You must filter with DesignViewType :

        - kTransientDesignViewType ==> Create if active view is locked
        - kMasterDesignViewType ==> For Master view
        - kPublicDesignViewType ==> For all other views

 

Regards

François

Message 6 of 9

k14348
Advocate
Advocate

Hi,

  While run this script if active design view rep is in locked condition it will be counted as 2. That particular rep will be counted as 2. Except master others should be unlocked condition. better before you count unlock all rep and active default view rep then start count. Hope this will help.

 

 

Thanks,

Regards,

Karth

0 Likes
Message 7 of 9

k14348
Advocate
Advocate

Hi,

Hope this script solves your prob.

Option Explicit

Public Sub DesignViewRep()
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    
    Dim oRepMgr As RepresentationsManager
    Set oRepMgr = oAsmDoc.ComponentDefinition.RepresentationsManager
    
    Dim oDVRs As DesignViewRepresentations
    Set oDVRs = oRepMgr.DesignViewRepresentations
    
    Dim oDVR As DesignViewRepresentation
    
    For Each oDVR In oDVRs
        On Error Resume Next
        oDVR.Locked = False
    Next
    
    oDVRs.Item("Default").Activate
    
    MsgBox ("Total No. of DVRs: " & oDVRs.Count)
    
    For Each oDVR In oDVRs
        MsgBox ("DVR Name: " & oDVR.Name)
    Next
   
End Sub

 

Regards,

Karth

Message 8 of 9

JBerns
Advisor
Advisor

@HideoYamada / @fransoze / @k14348 ,

 

Thank you all for the information, explanations, and code. I look forward to using these solutions.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 9 of 9

vinayababu.yerneni
Enthusiast
Enthusiast
Good and clear explanation, it helped me, Thanks!
0 Likes