Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 8546

My script is flawed both logically and programatically, extra eyes needed

$
0
0

i’ve got a script that i have hacked away at. it originally might have been @Helvetosaur or @pascal script.

what i’m looking to do is find layers that have hidden objects in them, select from a list the layers that have hidden objects, show the hidden objects isolated with the option to either keep that isolated display state or revert back to the original display state pre script.

first, if i hit cancel on the layer list that comes up, it’s not reverting to it’s original state, it’s keeping the state with all the layers turned on and i can’t remember exactly why i had to turn them all on at the start but i’m missing something and it’s probably obvious.

second, i’m using a lot of hacks with Rhino.Command i think there maybe a better way to go about the saving and reverting layer states. is this the best way to do this? are there any improvements i could make?

thank you

sorry it isn’t that readable, for some reason it is double spacing my copy paste :frowning:

IsolateHiddenObjects.rvb (2.2 KB)

' https://developer.rhino3d.com/api/rhinoscript/layer_state_methods/layer_state_methods.htm

Option Explicit

'Call IsolateHiddenObjects()

Sub IsolateHiddenObjects()

    ' turn off refresh

    'Call Rhino.EnableRedraw(False)

    ' enable LayerTools

    Dim objPlugIn

    On Error Resume Next

    Set objPlugIn = Rhino.GetPluginObject("Rhino Bonus Tools")

    If Err Then

        MsgBox Err.Description

        Exit Sub

    End If

    

    ' save current layer state

    Call objPlugIn.SaveLayerState("temp")

    ' turn all layers on

    Dim strLayer

    Dim arrLayers: arrLayers = Rhino.LayerNames

    If IsArray(arrLayers) Then

        For Each strLayer In arrLayers

            If Rhino.LayerVisible(strLayer) = False Then

                Rhino.LayerVisible strLayer, True

            End If

        Next

    End If

        

    ' check for hidden

    Dim aHid : aHid = Rhino.HiddenObjects

    If Not IsArray(aHid) Then

        Rhino.Print "There are no hidden objects in this file."

        Rhino.EnableRedraw(True)

        Exit Sub

    End If

    ' prepare for dialog display

    Dim sHid, n

    Dim aLayers()

    n = 0

    For Each sHid In aHid

        ReDim Preserve aLayers(n)

        aLayers(n) = Rhino.ObjectLayer(sHid)

        n = n + 1

    Next

    Dim aCull: aCull = Rhino.CullDuplicateStrings(aLayers)

    n = 0

    Dim sLayer

    For Each slayer In aCull:

        ReDim Preserve aStates(n)

        aStates(n) = False

        n = n + 1

    Next

    
    

    ' display checklist

    Dim ShowLayers : Showlayers = Rhino.CheckListBox(aCull, aStates, "Select layers to show objects", "Layers with hidden objects")

    If Not IsArray(ShowLayers) Then Exit Sub

    Dim Id

    For n = 0 To UBound(aCull)

        If ShowLayers(n) = True Then

            For Each ID In Rhino.ObjectsByLayer(aCull(n))

                Rhino.ShowObject(Id)

            Next

        End If

    Next

    

    ' display results

    Call Rhino.SelectObjects(aHid)

    Dim hObjects : hObjects = rhino.UnselectedObjects

    Call rhino.HideObjects(hObjects)

    Call rhino.UnselectObjects(aHid)

    ' turn refresh back on

    'Call rhino.EnableRedraw(True)

    

    ' restore or not?

    Dim question : question = Rhino.MessageBox("Restore previous state?", 1)

    If (question = 1) Then

        ' restore to pre command

        Call rhino.HideObjects(aHid)

        Call objPlugIn.RestoreLayerState("temp", 2)

        Call rhino.ShowObjects(hObjects)

        Call objPlugIn.DeleteLayerState("temp")

        Exit Sub

    End If

    

    Call objPlugIn.DeleteLayerState("temp")

    

End Sub

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 8546

Trending Articles