DesignViewRepresentation not updating visibility upon .Activate

DesignViewRepresentation not updating visibility upon .Activate

josh.nieman
Advocate Advocate
758 Views
3 Replies
Message 1 of 4

DesignViewRepresentation not updating visibility upon .Activate

josh.nieman
Advocate
Advocate

I'm running into an odd problem I can't figure out regarding DesignViewRepresentations

 

via VB I'm opening a document, setting the activeview (whatever it is, upon opening) 

 

 

Private Sub ViewMaker()

Dim curDoc As AssemblyDocument = InvApp.ActiveDocument
Dim curDocDef As AssemblyComponentDefinition = curDoc.ComponentDefinition
Dim dViewRepper As RepresentationsManager = curDocDef.RepresentationsManager
Dim actView As DesignViewRepresentation = dViewRepper.ActiveDesignViewRepresentation

dCurView = actView.Name


'See if it's there, first
Try
dNewView = dViewRepper.DesignViewRepresentations.Item("CMM")

Catch ex As Exception

dNewView = dViewRepper.DesignViewRepresentations.Add("CMM")
End Try

dNewView.Activate()
dNewView.Locked = False
dNewView.ShowAll()

dNewView.Camera = InvApp.ActiveView.Camera
dNewView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
dNewView.Camera.Fit()
dNewView.Camera.Apply()

End Sub

 

Then I call "ViewReverter" on the same document

 

 

Private Sub ViewReverter()
dNewView.Locked = True

Dim vAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

vAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(dCurView).Activate()

End Sub

So the resultant condition is that:

The "current view" is active, but the visibility of the objects is incorrect.  I'm creating a new view, turning visibility off, then activating the previous view, and moving on to the next document to do likewise.
However, it activates the previous view, but doesn't update the visibility - everything looks as it does in the new "CMM" view with many things not visibile.
Say the previous view was 'Default': I can double-click the CMM view - it looks accurate, then double-click the 'Default' view and it now looks correct.


It's like it's activating the view, but not updating something important.

Any ideas?

 

0 Likes
Accepted solutions (1)
759 Views
3 Replies
Replies (3)
Message 2 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

@josh.nieman,

 

After creation of new DesignViewRepresentation, need to update DesignViewRepresentation as shown below. Hoping that below code (highlighted in red color) may be helpful.

Private Sub ViewMaker()

Dim curDoc As AssemblyDocument = InvApp.ActiveDocument
Dim curDocDef As AssemblyComponentDefinition = curDoc.ComponentDefinition
Dim dViewRepper As RepresentationsManager = curDocDef.RepresentationsManager
Dim actView As DesignViewRepresentation = dViewRepper.ActiveDesignViewRepresentation

dCurView = actView.Name


'See if it's there, first
Try
dNewView = dViewRepper.DesignViewRepresentations.Item("CMM")

Catch ex As Exception

dNewView = dViewRepper.DesignViewRepresentations.Add("CMM")
End Try

dNewView.Activate()
dNewView.Locked = False
dNewView.ShowAll()

dNewView.Camera = InvApp.ActiveView.Camera
dNewView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
dNewView.Camera.Fit()
dNewView.Camera.Apply()
dNewView.update()
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 4

josh.nieman
Advocate
Advocate

Thanks for chiming in!

 

Earlier, I noticed that if I open the offending document, right click on "default" view rep (the 'dCurView' I revert back to before closing) and I click 'activate' and everything works... the visibility changes to what it should be.  I am curious what is happening when the user clicks "Activate" on the right-click-menu for a design view representation on the Model Browser.  Maybe I can replicate that in my code.

 

However--- "update" does not appear a method of DesignViewRepresentation as you suggest.  Am I missing something?

 

There is an 'update' method on a View object (separate from DesignViewRepresentation) tried that with the following line:

InvApp.ActiveView.Update()

 

 

There is an 'update' method on Document object.  Tried that.  Same results.

 

InvApp.ActiveDocument.Update()

 
I also tried adding both to the end of the "ViewReverter" sub, and that did not work either.

 

I even tried deleting the offending view rep, and making a new one, just to see if there was something buggy sticking with the 'Default' view.  No luck.  Same results.

 

Any ideas on what is causing this behavior?

 

0 Likes
Message 4 of 4

josh.nieman
Advocate
Advocate
Accepted solution

Got it.


I was attacking the wrong thing all along.

 

In between

ViewMaker()

and

ViewReverter()


I add a bunch of ComponentOccurrence objects to a list.  Then I turn visibility=false for all those components.  I do this on many documents as I iterate through a large assembly of subassemblies

It opens Document01, creates a new view, hides a bunch of stuff, reverts to the old view, saves, closes.

It opens Document02, creates a new view, hides a bunch of stuff, reverts to the old view, saves, closes.

etc

Well I never clear the list. 

So even though it's closed Document01, when it adds things to the list to hide in Document02, it then hides everything on the list from Document01 again.

 

Adding "hideme.clear()" after running the operations performed on the list solved it.

 

0 Likes