Hey All,
I frequently find myself manually hiding sketches and work planes in my assemblies. I know the view tab has an option to do it, but they all come back as soon as a new sketch or plane is created. Manually, it's a cumbersome process, so I'm writing a macro to do it for me. I've found that I can control the sketches and planes from inside the part, but when I step up a level to the parent assembly, I can't control the visibility. I have a counter in the same block as the visibility switch, and the counter is engaging, but the visibility switch is ineffective. Does anybody know what I'm doing wrong? Here's the code:
Sub HideAllPlanesAndSketches() Dim TopDoc As Document Set TopDoc = ThisApplication.ActiveDocument Dim TopOccs As ComponentOccurrences If TopDoc.DocumentType = kAssemblyDocumentObject Or kPartDocumentObject Then Set TopOccs = TopDoc.ComponentDefinition.Occurrences Else Call MsgBox("Top document is not a part or assembly file", , "Error") End If Dim SketchCounter As Integer SketchCounter = 0 Dim PlaneCounter As Integer PlaneCounter = 0 Dim Sketch As Sketch Dim Sketch3D As Sketch3D Dim WorkPlane As WorkPlane For Each Sketch In TopDoc.ComponentDefinition.Sketches Sketch.Visible = False SketchCounter = SketchCounter + 1 Next For Each WorkPlane In TopDoc.ComponentDefinition.WorkPlanes WorkPlane.Visible = False PlaneCounter = PlaneCounter + 1 Next If TopDoc.DocumentType = kPartDocumentObject Then For Each Sketch3D In TopDoc.ComponentDefinition.Sketches3D Sketch3D.Visible = False SketchCounter = SketchCounter + 1 Next End If Call RecurseForSketchesPlanes(TopOccs, SketchCounter, PlaneCounter) Call MsgBox(SketchCounter & " Sketches" & vbLf & PlaneCounter & " Planes") End Sub Function RecurseForSketchesPlanes(Occs As ComponentOccurrences, SketchCounter As Integer, PlaneCounter As Integer) Dim Occ As ComponentOccurrence Dim Sketch As Sketch Dim Sketch3D As Sketch3D Dim WorkPlane As WorkPlane For Each Occ In Occs If Occ.Definition.Type = kPartComponentDefinitionObject Then For Each Sketch In Occ.Definition.Sketches Sketch.Visible = False SketchCounter = SketchCounter + 1 Next For Each Sketch3D In Occ.Definition.Sketches3D Sketch3D.Visible = False SketchCounter = SketchCounter + 1 Next For Each WorkPlane In Occ.Definition.WorkPlanes WorkPlane.Visible = False PlaneCounter = PlaneCounter + 1 Next ElseIf Occ.Definition.Type = kAssemblyComponentDefinitionObject Then For Each Sketch In Occ.Definition.Sketches Sketch.Visible = False SketchCounter = SketchCounter + 1 Next For Each Sketch3D In Occ.Definition.Sketches3D Sketch3D.Visible = False SketchCounter = SketchCounter + 1 Next For Each WorkPlane In Occ.Definition.WorkPlanes WorkPlane.Visible = False PlaneCounter = PlaneCounter + 1 Next Call RecurseForSketchesPlanes(Occ.SubOccurrences, SketchCounter, PlaneCounter) End If Next End Function
Here's what it looks like unaltered:
Here's the macro being run on the part:
And here's the result on the assembly (note the counter is the same as the part plus the 3 origin planes in the assembly, but nothing was hidden):
The visibility of these planes is driven from:
1. The Part.
2. The Occurrence Proxy.
If you never want the planes visible, you should change them in the part. If you want them sometimes visible, but to pop up again in every different level of the assembly, then changing the proxy/occurrence is what you want.
I never want them visible, so I'm trying to turn them off at the part level, which is what my macro is doing (I think).
Yes, it does look like it is changing it in the file (accessing the componentdefinition).
My guess would be that it's an updating thing or potential limitation of changing the visibility.
Try adding a rebuild or an update to the top level, or even saving the part files after you change it.
Didn't look into it too deep, but these would likely be the first other things I would try.
HI!
I understand your problem, because i suffer due this issue also.
I solve this problem easy and now... i'm nhappy..
Here´s my idea:
Why you just make a User Command tab with the tools you use often avoiding change tabs, and you can toggle on/off in a quick click?
I don't know if it's the cause of the issue, or just a workaround, but on a hunch I tried changing the DesignViewRep of the file in the context of it's parent assembly, and it seems to work to get things right. (see bolded lines below)
Sub HideAllPlanesAndSketches() Dim TopDoc As Document Set TopDoc = ThisApplication.ActiveDocument Dim TopOccs As ComponentOccurrences If TopDoc.DocumentType = kAssemblyDocumentObject Or kPartDocumentObject Then Set TopOccs = TopDoc.ComponentDefinition.Occurrences Else Call MsgBox("Top document is not a part or assembly file", , "Error") End If Dim SketchCounter As Integer SketchCounter = 0 Dim PlaneCounter As Integer PlaneCounter = 0 Dim Sketch As Sketch Dim Sketch3D As Sketch3D Dim WorkPlane As WorkPlane For Each Sketch In TopDoc.ComponentDefinition.Sketches Sketch.Visible = False SketchCounter = SketchCounter + 1 Next For Each WorkPlane In TopDoc.ComponentDefinition.WorkPlanes WorkPlane.Visible = False PlaneCounter = PlaneCounter + 1 Next If TopDoc.DocumentType = kPartDocumentObject Then For Each Sketch3D In TopDoc.ComponentDefinition.Sketches3D Sketch3D.Visible = False SketchCounter = SketchCounter + 1 Next End If Call RecurseForSketchesPlanes(TopOccs, SketchCounter, PlaneCounter) Call MsgBox(SketchCounter & " Sketches" & vbLf & PlaneCounter & " Planes") End Sub Function RecurseForSketchesPlanes(Occs As ComponentOccurrences, SketchCounter As Integer, PlaneCounter As Integer) Dim Occ As ComponentOccurrence Dim Sketch As Sketch Dim Sketch3D As Sketch3D Dim WorkPlane As WorkPlane For Each Occ In Occs If Occ.Definition.Type = kPartComponentDefinitionObject Then For Each Sketch In Occ.Definition.Sketches Sketch.Visible = False SketchCounter = SketchCounter + 1 Next For Each Sketch3D In Occ.Definition.Sketches3D Sketch3D.Visible = False SketchCounter = SketchCounter + 1 Next For Each WorkPlane In Occ.Definition.WorkPlanes WorkPlane.Visible = False PlaneCounter = PlaneCounter + 1 Next ElseIf Occ.Definition.Type = kAssemblyComponentDefinitionObject Then For Each Sketch In Occ.Definition.Sketches Sketch.Visible = False SketchCounter = SketchCounter + 1 Next For Each Sketch3D In Occ.Definition.Sketches3D Sketch3D.Visible = False SketchCounter = SketchCounter + 1 Next For Each WorkPlane In Occ.Definition.WorkPlanes WorkPlane.Visible = False PlaneCounter = PlaneCounter + 1 Next Call RecurseForSketchesPlanes(Occ.SubOccurrences, SketchCounter, PlaneCounter) End If oStr = Occ.ActiveDesignViewRepresentation If oStr = "" And Occ.IsAssociativeToDesignViewRepresentation() = False Then: oStr = "Master" Call Occ.SetDesignViewRepresentation(oStr) Next End Function
Hi All,
Don't forgot, if you set Representation View at "Master" its locked. When save and close, then open that file again, it will show workplanes and sketchs agains.
Set it all assembly and Sub Assembly to "Default" Representation View.
Can't find what you're looking for? Ask the community or share your knowledge.