Unique Component Plugin
-
That shouldn't be too hard to do.
-
I thought something like this already existed. And I thought TIG had done it. Of course, I try not to think too much, but it doesn't do any good.
-
Try this, beta v0.03. Right click components and/or groups, and "Make All Unique". Post if problems, or you find a better solution.make_all_unique.rb
-
To make ALL instances unique across the SKP...copy paste this one-liner into the Ruby Console + <enter> - it's not undo-able!
Sketchup.active_model.definitions.each{|d|next if d.group? or d.image?;d.instances[1..-1].each{|i|i.make_unique}}
-
TIG,
WOW, how compact can you get. Can you explain the code?
- What does
next
do? - Why is it necessary to test for
d.image?
? - What does [1..-1] in
d.instances[1..-1].each
mean? - If I modify
Sketchup.active_model.definitions.each
toSketchup.active_model.selection.definitions.each
, will the code work only on SketchUp selections? - Does
Sketchup.active_model.definitions.each
locates all component instances, and groups in the model; including the nested ones? - Is
;
to indicate new line?
Thanks, hdt
- What does
-
@honoluludesktop said:
TIG,
WOW, how compact can you get. Can you explain the code?
- What does
next
do? - Why is it necessary to test for
d.image?
? - What does [1..-1] in
d.instances[1..-1].each
mean? - If I modify
Sketchup.active_model.definitions.each
toSketchup.active_model.selection.definitions.each
, will the code work only on SketchUp selections? - Does
Sketchup.active_model.definitions.each
locates all component instances, and groups in the model; including the nested ones? - Is
;
to indicate new line?
Thanks, hdt
- The next skips to the next definition IF the definition is for a group or and image - definitions includes all components, groups and images, but we are only interested in components [which will have instances]. We might get a error about an image not having instances or being able to be made_unique etc too...
- See above.
- d.instances returns an array of all of that definition's instances - the first [or only] instance doesn't need to be made_unique so we look at the second instance and then up to the last [1..-1] - the 1 is the second 0 is the first .. means up to and -1 means the last one. If the array is then [] nothing is made_unique, otherwise every other instance is processed wit .make_unique...
- No, the 'definitions' is a method of 'model', not 'model.selection'. The original code processes ALL components. If you want to process only instances in a selection use this alternative [you could of course use Edit>Select-All first !]
Sketchup.active_model.selection.to_a.each{|e|(begin;e.make_unique;rescue;end)if e.class==Sketchup;;ComponentInstance}
I used the begin/rescue in case there's an error message that the instance is the only one etc - this way errors that might stop us are skipped...
5. The 'definitions' way includes ALL instances, including any nested ones.
6. You can always use a ';' instead of a new-line, this is useful if you are writing a 'one-liner' - in the alternative code above I also used () to encapsulate the begin/rescue ';' separated code and then used the 'if' test after it - otherwise using 'if' before it would have required more ';' or a 'then' and also an 'end#if' etc... - What does
-
TIG, Thanks for the mini lesson. I hadn't known that you could use
next if
in that way. Unfortunately (for me), I also have problems visualizing the code levels within{}
and requiredo end
to do so.Thanks again, hdt
-
As well as
next
insidedo...end
or{}
to skip something if 'it doesn't match', you can havebreak
which simply stops looking.
so if you have a selection and the users should pick one edge instead of just failing if there are too many you could useedge=nil Sketchup.active_model.selection.each{|e| (edge=e; break) if e.class==Sketchup;;Edge }
This takes the first edge it comes to and stops.
If you want to tell the user off for making a poor selectionedge=nil Sketchup.active_model.selection.each{|e| next if e.class != Sketchup;;Edge if edge UI.messagebox("You should have selected only one edge!\nUsing the first one found...") break else ### edge not yet assigned! edge=e end#if }
Then...
if edge
do stuffelse
report no edge was selected at allend
! -
Thanks for everyone's quick responses!
Honoluludesktop - Cheers for the plugin, except its operation isn't quite what I was after.
TIG - your ruby text didn't seem to be either, but thank you.
I'll try to explain a little clearer (hopefully!).
I have an apartment block that is a group. Within that each floor is grouped (or a component if repeated). Within each floor I have a number of components (windows, doors, balconies, or apartment types). Now I name the apartment block Scheme 1. Now I want to do a second scheme (scheme 2) that has larger windows and different balconies. Is it possible to have a script where if I right click on scheme 2 apartment group and make all components unique within it? What I didn't explain before is that I still want the windows and balconies in scheme 2 to be instances and be linked (unlike Honoluludesktop plugin). I just want them different to scheme 1 so when I alter them scheme 1 remains unchanged. I know I could manually explode each floor then select all the windows in scheme 2 and 'make unique' but it would be better not to have to as ill have to re-group each floor again afterwards (apartment could have many floors). Also I have to do each component type separately (doors, windows, balcony etc) and if working on a large scheme there are heaps of them. So ideally if i could 'make unique' the whole building so each family of components within it is changed. This would also help as after changing and working on many components I may forget to 'make unique' a element and then accidentally affect the previous scheme. As mentioned in my first post I found I could lock scheme 1 then when opening a component in scheme 2 it would give me the option of releasing the locked components or making the unlocked ones unique. The problem with this is the discipline needed to have all other schemes locked except the one you are working on (could have many schemes), plus the need to go through the menu and click ok for every single component type.
If anyone has any possible methods of working that might be better please let me know!
Thanks again for looking at this!
-
I had hoped that making a component of each apartment, including all of the subcomponent instances; Save_as on each apartment component so it's now an external SKP; then reloading it back in... might make the sub-contents unique to that apartment - but it doesn't !
Any other bright[er] ideas out there ? -
an idea...
make unique with inherit checkboxes... bit like when you create new scenes.
so when you chose a set of items to make unique you could select a subset of things you can or can't change independently of the parent without a full 'make unique' leaving you with things you might change without affecting parent or siblings outside of your new set.
My thought is that you reuse an entire 'set' then redesign only certain elements of any item within the set.
for my example, I'm working on a child's push-chair that needs variants, so I make some items as unique components, but that means if I want to change the width of the 'GT' stripe, I have to do it to each because they are uniquely coloured. If it was possible to 'opt-out' of inheriting materials I'd only need to change the detail on one instance.
john
not necessarily an achievable idea...
-
Actually TIG one work around I found is to use your Xref plugin and then simply work on the Xref component in its own file. This automatically makes the adjusted components unique, although it leaves those components unchanged linked when working within the Master file. That said a plugin like that suggested by Driven would be perfect!
-
@unknownuser said:
I have an apartment block that is a group. Within that each floor is grouped (or a component if repeated). Within each floor I have a number of components (windows, doors, balconies, or apartment types). Now I name the apartment block Scheme 1. Now I want to do a second scheme (scheme 2) that has larger windows and different balconies. Is it possible to have a script where if I right click on scheme 2 apartment group and make all components unique within it?
chaddad, I think this plugin does what you describe.
Advertisement