Forgot password?

Create an account!

Forum

« back

RhinoScript – Script doing something strange

Messages

Please log in to write a message.

  • 3. Hanno (Sep 18, 2012 20.51):

    Have a closer look at your layer loop. You loop through all layers and turn them off if one of your target layers is visible. So in fact you turn off all layers that come before your target layers in the layer table.
    Just get rid of the whole layer loop. Just do

    Rhino.LayerVisible "Whatever layer you want to turn off", False

    Hanno

  • 2. aamom2004 (Sep 18, 2012 19.45):

    New finding:
    If I move the two layers I want turned off to the end of the layers list, it does everything right. It no longer turns off the other layers??? I'm sooooo confused!!

  • 1. aamom2004 (Sep 18, 2012 19.06):

    I have recently started working on some scripts for work, and I, nor anyone else here, cannot figure out the glich in here. The script is being used to export only the curves of the drawing I am working on to AutoCAD. It is supposed to print the paper space (does), turn off the A_dimref and A-jigref layers (does), and export (does). So it does everything it supposed to, BUT.... when it turns off the two layers, it also turns off other layer it was not asked to turn off (all the titleblock layers, and layer 0 if it isn't current). We tried making it turn them back on at the end, as it is not a big deal if they initially get turned off, but turning them back on would be much needed. Why would it turn them off in the first place, and then why would it not turn them back on? I will copy a the layer list as it appears and the script (which has been put back to its original semi-working form, which does not include trying to turn layers back on).

    Script:
    Option Explicit

    Sub ExportObjectsDXF

    ' Declare local variables
    Dim strPath, strFile
    Dim arrLayers, strLayer
    Dim arrSelected

    'Print the Layout
    Rhino.Command "_Print"

    ' Get the path to and name of the current document.
    ' Surround with double-quotes in case path includes spaces.
    strPath = Chr(34) & Rhino.DocumentPath & Rhino.DocumentName & Chr(34)


    ' Disable redrawing
    Rhino.EnableRedraw False

    ' Unselect all
    Rhino.Command "_-SelNone", 0


    ' Get names of all layers
    arrLayers = Rhino.LayerNames

    If IsArray(arrLayers) Then

    For Each strLayer In arrLayers

    If Rhino.LayerVisible("A-Dim_Ref") = True Then

    Rhino.LayerVisible strLayer, False

    End If

    If Rhino.LayerVisible("A-Jig_Ref") = True Then

    Rhino.LayerVisible strLayer, False

    End If

    Next

    End If

    ' Select all curve objects.
    Rhino.Command "_-SelCrv", 0

    ' Make sure some objects were selected
    arrSelected = Rhino.SelectedObjects
    If IsArray(arrSelected) Then

    ' Generate a modified path string
    ' that includes the file name
    strFile = strPath
    strFile = Replace(strFile, ".3dm", ".dxf")

    ' Export the selected objects
    Rhino.Command "_-Export " & strFile, 0

    End If

    ' Unselect all
    Rhino.Command "_-SelNone", 0

    ' Enable redrawing
    Rhino.EnableRedraw True

    End Sub


    List of layers:
    0
    A_TITLEBLOCK
    A_TITLECOLOR
    A_TITLECOLOR-2
    A_TITLETEXT
    A-Dim_Ref
    A-Jig_Ref
    H03
    H04
    H05
    H06
    H07
    H08
    H09
    H10
    H11
    H12
    H13
    H14
    H15
    P-Bottom
    P-Left
    P-Right
    P-Top
    V01
    V02
    V03
    V04
    V05
    V06
    V07
    V08
    V09
    V10
    V11
    V12
    V13
    Z01
    Z02
    Z03
    C-702-A2-13-003
    NODE_POINT

    The only layers that do not have curves on them, if that matters, are
    0
    A_TITLEBLOCK
    A_TITLECOLOR
    A_TITLECOLOR-2
    A_TITLETEXT
    A-Dim_Ref
    A-Jig_Ref
    C-702-A2-13-003
    NODE_POINT

Recommend

Why are these buttons gray?