sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Using Ruby for imported dwg layers to add materials

    Scheduled Pinned Locked Moved Newbie Forum
    sketchup
    2 Posts 2 Posters 2.5k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      austinryan
      last edited by

      Man I thought python and Dynamo were hard. I even had a go at lisp but for some reason I cant get my head a round ruby. have been trying to modify someone else code with no success

      P.S. I am bringing in a dwg (exported from Revit) with 30 or so layers and want to put all the layers to 1 color but windows I want them to be on Translucent Glass Gray

      F.E. all layers to color 123_White except
      0_EX_Glazing it needs to be on Translucent Glass Gray

      Some of the issues

      the import comes in as 1 group (with layers in the group)
      some of the groups come in the main group with groups within groups (doors and Door windows)
      Objects come in with a material not defined ()so a generic material must be placed on all the objects for the script to have a chance.
      using some lings gets me close but doesn’t do the back faces (so windows are not completely see through
      Thanks in advance

      P.S. the code I am trying to modify is on this page
      https://sketchucation.com/forums/viewtopic.php?f=180&t=22337&p=663388#p663388


      blocks.skp

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        The Ruby API only lets you set a layer/tag's color.
        [Note in v2020 'layers' were renamed 'tags', but in the API they're always called 'layers'].
        But you can't [yet] set a layer/tag's material [i.e. there's no access to textures or to transparency settings].

        However, in Ruby you could set up a separate color for the transparent layer [but setting a alpha value does nothing] and when it's set you do a simple edit for the layer/tag's color in the Layer/Tag Browser, and NOW you can add some transparency...

        model=Sketchup.active_model
        model.start_operation("LayerColors",true)
        model.layers.each{|layer|
          if layer.name=="0_EX_Glazing" #grey to get transparency setting later on...
            layer.color=Sketchup;;Color.new(150,150,150,50)
          else # 0128_White ? Set up any RGB you want !
            layer.color=Sketchup;;Color.new(255,255,255)
          end
        }
        model.commit_operation
        

        Ensure your Model is set up to use color by layer/tag - in the layer/tag-browser pop-out...

        Run this in the Ruby Console...

        Next manually edit the "0_EX_Glazing" layer/tag color in the layer/tag-browser to have some transparency...

        There's no option for 'back' material in layer's colors...

        TIG

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement