sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Selected entity question

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 7.2k Views 3 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.
    • PixeroP Offline
      Pixero
      last edited by

      Short question.
      Is:

      Sketchup.active_model.active_entities[0] 
      

      the selected entity?

      1 Reply Last reply Reply Quote 0
      • jiminy-billy-bobJ Offline
        jiminy-billy-bob
        last edited by

        No, these are the entities in the open group or component instance.

        You want:

        Sketchup.active_model.selection[0]
        

        Link Preview Image
        Class: Sketchup::Selection

        A set of the currently selected drawing elements.

        favicon

        SketchUp Ruby API Documentation (ruby.sketchup.com)

        25% off Skatter for SketchUcation Premium Members

        1 Reply Last reply Reply Quote 0
        • PixeroP Offline
          Pixero
          last edited by

          Thanks. That was what I suspected.
          Now I need to find a way to do what I want to do from the selection.
          A side question. What about getting the selected material?
          Sketchup.active_model.materials[0] won’t do it then either I guess?

          1 Reply Last reply Reply Quote 0
          • jiminy-billy-bobJ Offline
            jiminy-billy-bob
            last edited by

            That would be Sketchup.active_model.materials.current

            25% off Skatter for SketchUcation Premium Members

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

              That method gives you the current 'active' material in the model.
              But... if you want to get a material from the currently selected entity, then you use:

              mat = Sketchup.active_model.selection[0].material
              

              However, you might be better off filtering the selection, until you get an entity of the kind you want... e.g.

              
              face = Sketchup.active_model.selection.grep(Sketchup;;Face)[0]
              mat = nil
              mat = face.material if face
              

              Where the first face in the selection returns its material, or nil...

              TIG

              1 Reply Last reply Reply Quote 0
              • PixeroP Offline
                Pixero
                last edited by

                Thanks, I read in a older post somewhere, and I think it was by Thomthom, that there was a bug that could Bugsplat SU when using materials.current if there wasn't any materials in SU. Do you know if that still is an issue or if it has been fixed?

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

                  Why do you need to get the model.materials.current ?
                  You could pre-set it using model.materials.current = a_material
                  Having previously set a_material = model.materials["A_Name"]

                  You haven't really explained the full context......

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • PixeroP Offline
                    Pixero
                    last edited by

                    They are just for two small snippets that I will need some advise from Thomasz (Thea settings) to make them properly.
                    I'm just preparing for when he will have some time to look into it...

                    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