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,288 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,289 Views
33 Replies
Replies (33)
Message 21 of 34

steveh3
Advisor
Advisor

Both lines appear to be erroring... I attempted to delete both either/or...

steveh_0-1659722963386.png

 

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

steveh3
Advisor
Advisor

Now this...

steveh_0-1659723235602.png

 

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

NachoShaw
Advisor
Advisor

The nuances of VBA. you need to change the 'Set' to 'Call'. You're not setting anything, you're calling the function with parameters

 

Call oDrawView.SetDesignViewRepresentation("Default", True)

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 24 of 34

NachoShaw
Advisor
Advisor

your code should be

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
                Call oDrawView.SetDesignViewRepresentation("Default", True)
            End If
        Next
Next

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.


Message 25 of 34

steveh3
Advisor
Advisor

Thanks.

I see what the this code is doing now.

Call oDrawView.SetDesignViewRepresentation("Default", True)

It's almost what we looking for. 

So, it does check the box for Associative, but I don't want it to change the View Rep.

Can it read the view rep and then toggle it?

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

NachoShaw
Advisor
Advisor

Ok. This will get the name of the current view rep in the view then set the association to true using the SetDesignViewRepresentation function

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 name As String: name = oDrawView.DesignViewRepresentation
            
                Call oDrawView.SetDesignViewRepresentation(name, True)
            End If
        Next
Next

 

you could also add a condition to check the current viewrep and update it to what you need if it was incorrect

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 name As String: name = oDrawView.DesignViewRepresentation
                
                If Not name = "Default" Then
                name = "Default"
                End If
            
                Call oDrawView.SetDesignViewRepresentation(name, True)
            End If
        Next
Next

 

 

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 27 of 34

NachoShaw
Advisor
Advisor

and finally, if you need to toggle the associative on / off (which is the definition of toggle), you can toggle it like this

 

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 name As String: name = oDrawView.DesignViewRepresentation
                
                If Not name = "Default" Then
                name = "Default"
                End If
                
                Dim Assoc As Boolean: Assoc = oDrawView.DesignViewAssociative

                Call oDrawView.SetDesignViewRepresentation(name, Not Assoc)
            End If
        Next
Next

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 28 of 34

steveh3
Advisor
Advisor

That's it...seems to be working!!!

If we want to add in views that are .iams or .ipn's

possible to put an OR in the statement....

 

If oDrawView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

If so...what's the syntax for .ipn's here?

 

DocumentTypeEnum.kAssemblyDocumentObject

 

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

NachoShaw
Advisor
Advisor

Hi

 

I would do a Select Case

Select Case oDrawView.ReferencedDocumentDescriptor.ReferencedDocumentType
   Case DocumentTypeEnum.kAssemblyDocumentObject
   'assembly code here

   Case DocumentTypeEnum.kPresentationDocumentObject
   'presentation code here

   Case DocumentTypeEnum.kPartDocumentObject
   'part code here

End Select

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 30 of 34

steveh3
Advisor
Advisor

Having problem with the Views that are referring to an .ipn.

 

Statement works fine as a "kAssemblyDocumentObject"

 

But, when I change it to a kPresentationDocumentObject

It bugs out...

steveh_0-1659967562950.png

Best,

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

NachoShaw
Advisor
Advisor

Hey

 

Good news & bad news...

 

Good News

you can change the associative type like this

oDrawView.PresentationViewAssociative = True

 

Bad News

Presentation views are different to part & assembly views as in, they dont directly show the view rep but instead, show the list of snapshot views in the presentation file. If you need to change the view rep, the underlying file would need to be opened and the view rep change at file level in the snapshop view.

 

Heres the bad news; there is a function in a DrawingView that is supposed to get the name of the current snapshot view in the drawingview which you would need to correct update the viedwrep of the snapshot in the presentation file however, its been flagged as bug and is currently not working. I found a thread from about 3 yrs ago explaining this so im assuming its yet another one of those things autodesk doesnt care about.

 

to get around it, you will need the name of the view so that you can -

open the underlying presentation file

  1. edit the snapshot
  2. change the viewrep
  3. save and close it
  4. update the drawing sheet
  5. associate the view

 

thanks

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 32 of 34

steveh3
Advisor
Advisor

@NachoShaw 

 

Thanks for all the help!!!

Finally got it working.

It toggles on "Associative" for all views in an .idw's that refer to an .iam or .ipn

Ignores ipt views.

Combined it with an iLogic script that runs the VBA before it saves.

 

Best,

 

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

NachoShaw
Advisor
Advisor

great news.

 

why dont you combine all of the VBA witrh iLogic, seems pointless using both and iLogic supersedes VBA

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 34 of 34

steveh3
Advisor
Advisor

Just using the iLogic to trigger the VBA to run on only idw's.

 

Before a save, a trigger runs the iLogic which tells the VBA to run.

 

'This runs the VBA to check the Associative box on all Assembly views
	InventorVb.RunMacro("ApplicationProject", "Module3", "ViewAssoc3")

Possible to do this otherwise?

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes