• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Selected entity question

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 3 Posters 7.1k Views
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.
  • P Offline
    Pixero
    last edited by 15 May 2019, 08:29

    Short question.
    Is:

    Sketchup.active_model.active_entities[0] 
    

    the selected entity?

    1 Reply Last reply Reply Quote 0
    • J Offline
      jiminy-billy-bob
      last edited by 15 May 2019, 19:26

      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
      • P Offline
        Pixero
        last edited by 15 May 2019, 21:02

        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
        • J Offline
          jiminy-billy-bob
          last edited by 18 May 2019, 21:23

          That would be Sketchup.active_model.materials.current

          25% off Skatter for SketchUcation Premium Members

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 19 May 2019, 17:28

            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
            • P Offline
              Pixero
              last edited by 19 May 2019, 18:30

              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
              • T Offline
                TIG Moderator
                last edited by 19 May 2019, 18:45

                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
                • P Offline
                  Pixero
                  last edited by 19 May 2019, 18:54

                  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
                  1 / 1
                  • First post
                    8/8
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement