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!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Get instance parent of selected entity

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 244 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.
    • B Offline
      BillW
      last edited by

      If a user has entered a group and selected say an edge - I want to get the parent of the selected edge ie the group

      Typing in the ruby console
      Sketchup.active_model.selection[0].parent

      responds with #Sketchup::ComponentDefinition:0xd3390f0 which is not the instance of the group

      What I need to get is the transformation of the containing group.

      Is there a way to get a handle to the group instance from the selection?

      Thanks

      BillW

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

        groupsdefinition.instances[0]
        

        should return the instance of the group. Note: to avoid a glitch that's not yet fixed with copied-but-unedited groups sharing the same definition, I suggest you use group.make_unique to help too - in some circumstances - might be irrelevant if you are editing that group as that will automatically make it unique ? ...

        TIG

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          Check out this method. It sounds like it might work, though I've never used it:

          http://code.google.com/apis/sketchup/docs/ourdoc/model.html#edit_transform

          @unknownuser said:

          Returns the transformation of the current component edit session. If a user has double-clicked to edit a component's geometry, this will return the transformation of that component, relative to its parent's origin. This allows one to correctly calculate "local" transformations of a given entity regardless of whether the user is in edit mode.

          but its only available in SU 7.0 (and up). So it might mot help if you know your developing a script that will be run in SU version 6.

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

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

            Assuming you want at least v6 AND 7 compatibility then this should return the transformation of the instance of the group containing the selected edge.

            edge.parent.instances[0].transformation
            

            ???

            TIG

            1 Reply Last reply Reply Quote 0
            • B Offline
              BillW
              last edited by

              Thanks both again

              I tried a different tack originally with an add_group/explode combo but TIG the instances option worked perfectly.

              Chris as I am disallowing component edit sessions for the time being and I am coding for SU 6 upwards, I will bear in mind Model.edit_transform for the future.

              BillW

              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