Update all views in a sheet to turn on Associative check box

Update all views in a sheet to turn on Associative check box

GeorgK
Advisor Advisor
2,282 Views
33 Replies
Message 1 of 34

Update all views in a sheet to turn on Associative check box

GeorgK
Advisor
Advisor

Hello together,

 

is there a solution to turn on associative check box in a drawing? How to get the ActiveDesignViewRepresentation name?

 

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oDrawView As DrawingView
For Each oSheet In oDrawDoc.Sheets For Each oDrawView In oSheet.DrawingViews Representation = oDrawView.ActiveDesignViewRepresentation If Representation <> "" Then ' How to get the name 'oDrawView.SetDesignViewRepresentation(Representation, True) End If Next Next

 Zeichnungsansicht.png

 Thank you

Georg

0 Likes
2,283 Views
33 Replies
Replies (33)
Message 2 of 34

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Available design view representations in assembly can be used to check associativity for drawing view in Drawing document. For example, a drawing document contains drawing view which is referenced by assembly document having 2 design view representations namely, "Master" and "Complete". Before running below VBA code, property of drawing view is look like below

 

Before.png

 

Sub Check_Associativity()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews.Item(1)
    
    Call oView.SetDesignViewRepresentation("Complete", True)
End Sub

After running above code, property of drawing view shows that it is checked out to "Complete" design view representation as shown below.

After.png

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 34

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

yes I know this. But how could I get the view list (names) like "Complete"?

 

Thank you Georg

0 Likes
Message 4 of 34

DRoam
Mentor
Mentor

Hi @GeorgK. In order to check the "Associative" box via the API, you have to specify the name of the View Rep to be associative to. And unfortunately, there's currently no way to determine which View Rep is the "current" View Rep for the drawing view.

 

Take a look at this helpful post by @BrianEkinsRe: Ilogic to lock views in drawing (see post 15).

 

What MAY be possible is to determine the View Reps present in the Assembly/Part the drawing view belongs to, and you could either always use the first one, or use one that meets some criteria that you're looking for.

 

However, as of now there's unfortunately no way to simply check the "Associative" box for the current View Rep.

 

Your vote on this functionality request will help get this fixed: API improvement: Reassociate a Drawing View with its Design View Representation.

0 Likes
Message 5 of 34

clutsa
Collaborator
Collaborator

Here's a really annoying way to bring up the edit view dialog for any view that isn't already set to Associative.

Dim app As Application
Set app = ThisApplication
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = app.ActiveDocument
Dim oSheet As Sheet
Dim ViewEdit As ControlDefinition
Set ViewEdit = app.CommandManager.ControlDefinitions("DrawingViewEditCtxCmd")
For Each oSheet In oDrawDoc.Sheets
    For Each oDrawView In oSheet.DrawingViews
        Representation = oDrawView.ActiveDesignViewRepresentation
        If Representation = "" Then
            oDrawDoc.SelectSet.Clear
            oDrawDoc.SelectSet.Select (oDrawView)
            ViewEdit.Execute2 True
        End If
    Next
Next
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 6 of 34

NachoShaw
Advisor
Advisor

Hi

 

A few years ago i did some extensive coding related to View Reps as we needed to be able to specifically change to a view. In that code, im sure i was able to determine what the current view rep was however, i aborted the project because there was at the time, a 8 year bug that wouldn't allow me to change the view rep by code. If thats since changed (which i doubt), great. If not, the whole API on view reps is a waste of time as you cant do anything with it except change the associative check box (only if its not on the master view)

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 7 of 34

GeorgK
Advisor
Advisor

@clutsa

Thank you very much for your solution. Is there no way to check it automatically?

 

@NachoShaw

Please could you post your code or send me a pm.

 

@chandra.shekar.g

Is it possible that you add it to the change request (API)?

0 Likes
Message 8 of 34

clutsa
Collaborator
Collaborator

@GeorgK

The problem I'm running into is I can't figure out what DesignViewRep the drawing view is set to until it's set to associative. Once that is set the "ActiveDesignViewRepresentation" returns real data again and I have something to work with. I can turn it on automatically but will change the DesignViewRep of the view and most likely compromise the integrity of the drawing.

We could pop up a dialog and ask what DVRep to set all the views to or go one step farther and ask what DVRep and which views but at that point your doing as much if not more work to get it set.  

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 9 of 34

DRoam
Mentor
Mentor

@GeorgK wrote:

Thank you very much for your solution. Is there no way to check it automatically?


 

@GeorgK, please see my post above (post # 4). I explain why there currently is no way to check it automatically.

 

Your best bet for efficiently and quickly setting every view to associative is going to be clutsa's code in post #5.

 


@GeorgK wrote:

Is it possible that you add it to the change request (API)?


 

My post above also included a link to a change request that's already been created. Please vote for it if you'd like to see this fixed: API improvement: Reassociate a Drawing View with its Design View Representation.

0 Likes
Message 10 of 34

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

In continuing with same example drawing with 2 design view representations, try below VBA code to change and associate DesignViewRepresentation. In general, "Master" DesignViewRepresentation always returns null string value for Drawing view(oView.ActiveDesignViewRepresentation).

 

Sub Check_Associativity()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews.Item(1)
    
    If oView.ActiveDesignViewRepresentation = "" Then
        If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
        
            Dim oAssyDoc As AssemblyDocument
            Set oAssyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
            
            Dim oAssyDef As AssemblyComponentDefinition
            Set oAssyDef = oAssyDoc.ComponentDefinition
            
            Dim oDesignView As DesignViewRepresentation
            For Each oDesignView In oAssyDef.RepresentationsManager.DesignViewRepresentations
                If Not oDesignView.Name = "Master" Then
                    Call oView.SetDesignViewRepresentation(oDesignView.Name, True)
                    Exit For
                End If
            Next
        End If
    End If
     
End Sub

Please feel free to contact if there is any queries.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 34

clutsa
Collaborator
Collaborator

That should work great if you only have two design views (master and some other view) but what if you have two or three design views other then master? It's always going to end up as the last design view and that could/would compromise the drawing. Inventor should have some way to figure out what design view the drawing view was last set to (the "Edit View" dialog box can figure it out, so it has to be somewhere)

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 12 of 34

steveh3
Advisor
Advisor

Is there any way to get this to run when views come from an .iam?

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 13 of 34

steveh3
Advisor
Advisor

To be more specific....I don't want this routine to run when the idw views are from an ipt. We get prompted for every view because it doesn't apply to .ipt's.

 

Only want this routine to run when the view is from an .iam.

 

Here's the code I used from above...

Dim app As Application
Set app = ThisApplication
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = app.ActiveDocument
Dim oSheet As Sheet
Dim ViewEdit As ControlDefinition
Set ViewEdit = app.CommandManager.ControlDefinitions("DrawingViewEditCtxCmd")
For Each oSheet In oDrawDoc.Sheets
    For Each oDrawView In oSheet.DrawingViews
        Representation = oDrawView.ActiveDesignViewRepresentation
        If Representation = "" Then
            oDrawDoc.SelectSet.Clear
            oDrawDoc.SelectSet.Select (oDrawView)
            ViewEdit.Execute2 True
        End If
    Next
Next

 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 14 of 34

steveh3
Advisor
Advisor

Also...any way to just toggle it on and have no user intervention?

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 15 of 34

NachoShaw
Advisor
Advisor

you could get the underlying files type from the Reference Descriptor and only run it if its an assembly in a Select statement? @chandra.shekar.g has already provided an example of that in post #10

 

 

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 16 of 34

steveh3
Advisor
Advisor

So, I grabbed the code from #10.

For views with iam's, it prompts me with the view dialog box when the Associativity is not toggled. I then toggle the Associative check box and all is good.

 

Now, when I run the code when the view is an .ipt (Master is the View Rep for all views), I'm still getting prompted with the dialog....

steveh_0-1659716461508.png

I don't know VBA but, I'm thinking, the code should skip the dialog box when the view  rep is Master. Am I correct?

 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 17 of 34

NachoShaw
Advisor
Advisor

Hi

 

you're getting the dialog box because you're asking for it here

 

 

Set ViewEdit = app.CommandManager.ControlDefinitions("DrawingViewEditCtxCmd")
'other code
ViewEdit.Execute2 True

 

 

 

Also, you are setting the ViewRepresentation to do something if the value is ""

 

 

Representation = oDrawView.ActiveDesignViewRepresentation
If Representation = "" Then

 

 

at worst, the ViewRep would be Master. You cannot set association with a Master view rep. In this code below, it checks for the document type and only executes if its an assembly. Then it sets the DesignViewRep to "Default" (which is one i made up to test the code so you should change Default to your own)

 

The code line

 

 

oDrawView.SetDesignViewRepresentation("Default", True)

 

 

is setting the viewrep to the currently active drawing view to the view rep you want and setting the association to True.

 

 

Dim app As Application: Set app = ThisApplication
Dim oDrawDoc As DrawingDocument: Set oDrawDoc = app.ActiveDocument
Dim oSheet As Sheet

For Each oSheet In oDrawDoc.Sheets
    Dim oDrawView As DrawingView
    For Each oDrawView In oSheet.DrawingViews	
       If oDrawView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
          Dim Rep As DesignViewRepresentation = oDrawView.ActiveDesignViewRepresentation
				oDrawView.SetDesignViewRepresentation("Default", True)
		End If      
    Next
Next

 

 

 

let me know if this works for you and i can help you out

 

 

Thx

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 18 of 34

steveh3
Advisor
Advisor

Thanks @NachoShaw 

Starting to make sense. 

Default is our preferred view rep.

 

So took you code and swapped it out with what I had...

 

Getting this error now...

steveh_0-1659722586998.png

 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 19 of 34

NachoShaw
Advisor
Advisor

you could delete that line, i was a version of your original line but its now redundant in my code

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 20 of 34

NachoShaw
Advisor
Advisor

The reason for the error is the string construction. I write in VB.Net which is slightly different to VBA

 

example

VB.NET

Dim Rep As DesignViewRepresentation = oDrawView.ActiveDesignViewRepresentation

 

VBA

Dim Rep As DesignViewRepresentation 
Set Rep = oDrawView.ActiveDesignViewRepresentation

 

in VBA you can also compact the string buts the same thing

Dim Rep As DesignViewRepresentation: Set Rep = oDrawView.ActiveDesignViewRepresentation

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes