sketchucation logo sketchucation
    • Login
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Get instance parent of selected entity

    scheduled pinned locked moved Developers' Forum
    5 Posts 3 Posters 237 Views 3 Watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • 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

      one-reply-to-this-post last-reply-time 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

        one-reply-to-this-post last-reply-time 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

          one-reply-to-this-post last-reply-time 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

            one-reply-to-this-post last-reply-time 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

              one-reply-to-this-post last-reply-time 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