AnsweredAssumed Answered

Toggle Sketch Visibility in a Drawing

Question asked by Casey Balderson on Sep 30, 2020
Latest reply on Oct 7, 2020 by Casey Balderson

I have a 3DSketch that I want to identify whether it is hidden or visible in each drawing view. Using ITreeControlItem, I successfully get the sketches I am interested in, but when I cast as a feature, IFeature::Visible returns the value at the model, not in the drawing view.
For clarification, I am not trying to use IModelDoc2::.SetUserPreferenceToggle (swUserPreferenceToggle_e.swDisplaySketches, bool) because the sketches are set to hidden in the model, and I need them temporarily in the drawing view for a convert entities scenario.
Here's what I have so far. I assume I need something after "Private Sub SetVisVal" at line 74. I just don't know what command identifies the visibility state of a TreeControlItem.

How do I return the visibility of the sketch at the drawing view, and not the model within the drawing view?

 

 

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim vViews As Variant
Dim swDraw As DrawingDoc
Dim swView As View
Dim feat As Feature
Dim featMgr As FeatureManager
Dim swSheet As Sheet
Dim focusFeat As Feature
Dim visible As swVisibilityState_e
Dim swSketch As sketch
Dim selMgr As SelectionMgr
Dim rootNode As TreeControlItem
Dim sheetNode As TreeControlItem
Dim sheetFeat As Feature
Dim viewNode As TreeControlItem
Dim viewFeat As Feature
Dim modelNode As TreeControlItem
Dim featNode As TreeControlItem
Dim subFeatNode As TreeControlItem
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set selMgr = swModel.SelectionManager
    visible = swVisibilityStateUnknown
    Set featMgr = swModel.FeatureManager
    Set rootNode = featMgr.GetFeatureTreeRootItem2(swFeatMgrPane_e.swFeatMgrPaneTop)
    While Not rootNode Is Nothing
        Set sheetNode = rootNode.GetFirstChild
        While Not sheetNode Is Nothing
            Set sheetFeat = sheetNode.Object
            'Debug.Print sheetFeat.name & " - " & sheetFeat.GetTypeName2
            If sheetFeat.GetTypeName2 = "DrSheet" Then
                Set viewNode = sheetNode.GetFirstChild
                While Not viewNode Is Nothing
                    Set viewFeat = viewNode.Object
                    'Debug.Print viewFeat.name & " - " & viewFeat.GetTypeName2
                    If viewFeat.GetTypeName2 = "AbsoluteView" Or viewFeat.GetTypeName2 = "UnfoldedView" Then
                        Set modelNode = viewNode.GetFirstChild
                        If Not modelNode Is Nothing Then
                            Set featNode = modelNode.GetFirstChild
                            While Not featNode Is Nothing
                                Set feat = featNode.Object
                                'Debug.Print feat.name & " - " & feat.GetTypeName2
                                If feat.name = "SkRoute1" Then
                                    'found
                                    SetVisVal featNode
                                Else
                                    Set subFeatNode = featNode.GetFirstChild
                                    If Not subFeatNode Is Nothing Then
                                        Set feat = subFeatNode.Object
                                        If Not feat Is Nothing Then
                                            If feat.name = "SkRoute1" Then
                                                'found
                                                SetVisVal subFeatNode
                                            End If
                                        End If
                                    End If
                                End If
                                Set featNode = featNode.GetNext
                            Wend
                        End If
                    End If
                    Set viewNode = viewNode.GetNext
                Wend
            End If
            Set sheetNode = sheetNode.GetNext
        Wend
        Set rootNode = rootNode.GetNext
    Wend
    Debug.Assert Null
End Sub
Private Sub SetVisVal(thisNode As TreeControlItem)
    Dim thisFeat As Feature
    Set thisFeat = thisNode.Object
    Debug.Print thisNode.Text
    If visible = swVisibilityStateUnknown Then
        visible = thisFeat.visible
    End If
    thisFeat.Select2 False, -1
    Select Case visible
        Case 1 'hidden
        swModel.UnblankSketch
        Case 2 'shown
        swModel.BlankSketch
    End Select
End Sub

Outcomes