sketchucation logo sketchucation
    • Login
    šŸ¤‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Adding layers to extension

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 6 Posters 1.1k Views 6 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.
    • medeekM Offline
      medeek
      last edited by

      I've been considering adding the option to specify layers within my plugin (ie. framing, sheathing, blocking etc...)

      I'm still trying to understand SketchUp's concept of layers though. Should each line be drawn on the custom layer or is it enough to create the group or component on the custom layer and the underlying geometry remains on layer0?

      Nathaniel P. Wilkerson PE
      Medeek Engineering Inc
      design.medeek.com

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

        Always assign the 'raw' geometry - faces and edges - to Layer0 [that's what they get if you do nothing !].
        Then assign other layers to their containers - groups or component-instances...

        A simple way to get a reference to a layer is:
        my_layer = Sketchup.active_model.layers.add("my_layer_name")
        If a layer of that name does not exist, then it's created, and also a reference to it is returned.
        Alternatively, if a layer of that name already exists, then it returns a reference to it.

        TIG

        1 Reply Last reply Reply Quote 0
        • medeekM Offline
          medeek
          last edited by

          Is it better to change the active layer to the custom layer and then create the group or component or first create the group/component and then assign it to the custom layer?

          Nathaniel P. Wilkerson PE
          Medeek Engineering Inc
          design.medeek.com

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

            Never change the current layer in code.
            It's unnecessary - and will lead to issues if you forget to reset it afterwards.
            It's much easier to make the geometry already inside a new container.entities context [it'll all be assigned Layer0 [nil] as it's created]
            Then just assign that container.layer=my_layer as desired...
            Much easier and foolproof...

            TIG

            1 Reply Last reply Reply Quote 0
            • G Offline
              Garry K
              last edited by

              If you choose to change the active layer - make sure you set it back the way you found it.

              model = Sketchup.active_model
              layers = model.layers
              original_layer = model.active_layer

              begin
              your_layer = layers.add("your_layer_name")
              model.active_layer = your_layer

              do whatever you need to

              ensure
              model.active_layer = original_layer
              end

              1 Reply Last reply Reply Quote 0
              • medeekM Offline
                medeek
                last edited by

                Thank-you for all of the advice, this will save me from making a bunch of beginner mistakes with regards to layers.

                I've had a number of requests for layers so I'm beginning to explore it a little more seriously.

                I will make the custom layers user definable (name and rename the layers). Are there any more gotchas I should be aware of with layers?

                The default layer names will be something like:

                ROOF_TRUSS
                ROOF_FRAMING
                ROOF_SHEATHING
                ROOF_TRIM

                FLOOR_TRUSS
                FLOOR_FRAMING
                FLOOR_SHEATHING

                Nathaniel P. Wilkerson PE
                Medeek Engineering Inc
                design.medeek.com

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  I'd suggest not yelling your Layer names...
                  e.g.
                  Roof_Truss
                  Roof_Framing
                  Roof_Sheathing
                  Roof_Trim

                  Floor_Truss
                  Floor_Framing
                  Floor_Sheathing

                  to me it's polite and looks more professional...

                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • Paul RussamP Offline
                    Paul Russam
                    last edited by

                    As an very active user of layers could you please precede your layers with your/your plugin name this way they will remain unique, calling them common names like 'Roof' or 'Truss' is just asking them to be mixed in with existing layers.
                    If you did the same with any component and material names your plugin(s) creates it would be very helpful too.

                    Paul Russam
                    English doesn't borrow from other languages. It follows them down dark allies, knocks them over, and goes through their pockets for loose grammar.

                    1 Reply Last reply Reply Quote 0
                    • G Offline
                      Garry K
                      last edited by

                      You could add a sketchup menu option something like "Medeek Truss - Edit Config"
                      Then throw up a simple Sketchup API inputbox where you set each of your granular layers
                      The prompts could be:

                      Roof Truss:
                      Roof Framing:
                      Roof Sheathing:

                      etc.

                      If the input box is empty then use Layer0
                      You can also provide logical defaults like "Roof Framing"
                      Users like Paul can add "Medeek Roof Framing"
                      Users who like underscores "Roof_Framing"
                      Users who want upper case "ROOF_FRAMING"
                      User who speak a different language can call it what ever they want

                      Also if a user wants Roof Framing and Roof Sheathing to appear on the same layer - then all they need to do is use the same layer name for both!!

                      With a bit of effor - you can almost satisfy everyone.

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @medeek said:

                        Are there any more gotchas I should be aware of with layers?

                        Yes, SketchUp layers are not really layers at all. They do not "own" geometric collections of entities (like they do in most CAD applications.) In SketchUp, layers are display behavior property sheets, that can be shared with multiple entities.

                        So in SketchUp, each object descended from Sketchup::Drawingelement has a layer property that can be assigned to point at one of these property sheets (that were misnamed "layers" by the developers.)

                        So, in reality you assign a SketchUp object to "use" a layer, not put an object upon a layer.

                        @paul russam said:

                        ... could you please precede your layers with your/your plugin name this way they will remain unique, ... If you did the same with any component and material names your plugin(s) creates it would be very helpful too.

                        This also applies to Attribute Dictionary names. They should be prefixed with the name of your author name and extension name in some way, so there will not be any clashing of dictionary names. (For example, we all cannot have dictionaries named "Properties".) Something like "Medeek_TrussMaker_TrussProperties" or whatever.

                        I'm not here much anymore.

                        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