Transformation method not working in 2018 the same as 2017?

Transformation method not working in 2018 the same as 2017?

Postby Sminky » Tue Dec 12, 2017 3:31 am

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
0
User avatar
Sminky 
 

Re: Transformation method not working in 2018 the same as 20

Postby TIG » Tue Dec 12, 2017 12:33 pm

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...
1
TIG
User avatar
TIG 
Global Moderator
 

Re: Transformation method not working in 2018 the same as 20

Postby Sminky » Wed Dec 13, 2017 8:42 am

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

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 11 guests

Visit our sponsors: