How to trim a component with more than two components with code

I make four box with code
box a
box b
box c
box d
then i transform them to components
I want to trim a and c with a ,then trim b and c with d
so I try code like this


but when “a.trim(b)” and “a.trim(c)” finished, “d.trim(b)” and “d.trim(c)” failed。
I guess that after “a.trim(b)” and “a.trim(c)”,component b has been changed uid
So the question is ,how can i solve it

I think the API documentation is misleading or at best confusing. When you do a.trim(b), it is b that is modified, not a. The method should perhaps read “tell a to trim b”. That corresponds to the selection order in the GUI solid tools trim. When b is trimmed, the original is erased and a new group is created. If the method succeeded, that new group is returned. If you wanted to then trim (the modified) b using d, you need to use that new return instead of the original b.

b = a.trim(b)
c = a.trim(c)
1 Like

oh, I’m so stupid。thank you !
If I want to trim “b” and “c” with lots of components,is there any sample way to finish it?

I don’t know of a bulk operation for trim. I think you will have to go step by step.

How about …

def trim_multiple(target,*trimmers)
  trimmers.each {|trimmer| target = trimmer.trim(target) }
  return target

Can you log issues for confusing parts of the documentation please? Issues · SketchUp/api-issue-tracker · GitHub