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

    Transformation method not working in 2018 the same as 2017?

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 1.9k Views 2 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.
    • SminkyS Offline
      Sminky
      last edited by

      Hi all,

      In a script I was happily using in 2017 version I have run in a problem.
      I have selected a group composed of several copies of the same component; I explode it to retrieve the single instances with something like:
      exp=sel[0].explode
      Than I would like to sort it by the x value of the instance origin like this:
      sort=exp.sort_by {|x| x.transformation.origin.x}

      This was working smoothly in 2017 version but now it gives me this error:
      Error: #<NoMethodError: undefined method `transformation' for #Sketchup::AttributeDictionaries:0x0002d167da50f8

      It seems that if i manually pick an element of exp array like exp[0], I can get the transformation origin no problem.

      Does anybody have a solution or advice on this?

      Thanks for your time and best regards

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

        It's not the transformation it's the explode returning objects which don't have a transformation !
        So when you explode the container the reference ' exp' can contain nested containers [groups/instances/images], raw geometry [i.e. faces/edges], AND things like curves, vertices, loops, edge-use and attribute-dictionaries.
        Since you only want to get the transformation of some limited elements in ' exp' you can either grep it to get say just instances or groups, or filter the value x by its 'kind[s]' and then pass those to the 'sort' stage.
        Also look at x.respond_to?(:transformation) which is true if the element has an accessible transformation...

        TIG

        1 Reply Last reply Reply Quote 0
        • SminkyS Offline
          Sminky
          last edited by

          Thank you so much TIG!
          Adding a simple grep for instances solved it.
          Best regards and sorry for the newbyness.

          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