Cloning components and grouped objects
-
Hello All:
I need to be able to clone a component or grouped object so that the CLONE can be readily named, is UNIQUE, takes the precise position of its parent, and can subsequently be placed on a layer.
The function of: 'COPY --> PASTE IN PLACE' will create a clone in position, however, separating the two items is a JOB because the parent component remains stuck underneath. Accordingly, the parent component should just disappear, with only the CLONE showing on the screen.
Ideas anyone?
-
It's easy enough to do with the native tools...
Select and Edit>Copy, then Edit>Paste-in-Place - now its copy is overlaid on the original.
Use the Outliner to select the one copy of the component-instance.
You can then use make-unique [context-menu] to separate its definition from the original, and then using Entity Info you can rename it and assign a different layer [tag] as desired... -
Yes. Of course! I understand all that. Have been doing it for years. I'm just looking for a more efficient way on how to make a new component instance without all those moves.
-
If you had a custom tool to do this you still need to give it a name [unless you're happy with "compo#123"] and to assign it to a new layer [tag].
So the automated tool just skips the make-unique part, and perhaps also selecting it cleanly...
This one short code does it that for you...m=Sketchup.active_model es=m.active_entities ss=m.selection if ss.length==1 && ss[0].is_a?(Sketchup;;ComponentInstance) UI.add_context_menu_handler{|menu| i=ss[0] menu.add_item("Copy Unique Instance..."){ ii=es.add_instance(i.definition, i.transformation) ii.make_unique ss.clear ss.add(ii) } } end
It adds an item to the context-menu, only if you have selected one component-instance.
When it's done only the new copy is selected and it is listed in Entity Info - where you can assign it a different layer and a new name as desired... -
@tig said:
If you had a custom tool to do this you still need to give it a name [unless you're happy with "compo#123"] and to assign it to a new layer [tag].
So the automated tool just skips the make-unique part, and perhaps also selecting it cleanly...
This one short code does it that for you...m=Sketchup.active_model > es=m.active_entities > ss=m.selection > if ss.length==1 && ss[0].is_a?(Sketchup;;ComponentInstance) > UI.add_context_menu_handler{|menu| > i=ss[0] > menu.add_item("Copy Unique Instance..."){ > ii=es.add_instance(i.definition, i.transformation) > ii.make_unique > ss.clear > ss.add(ii) > } > } > end
It adds an item to the context-menu, only if you have selected one component-instance.
When it's done only the new copy is selected and it is listed in Entity Info - where you can assign it a different layer and a new name as desired...Many thanks! In retrospect, I see that the native tool method is not so bad after all. That is because OUTLINER makes it manageable. I tend to forget to use this tool a lot-- probably one of the most under-rated or least discussed in Skp.
While I'm at this. Is there a tool for PUT ALL ON LAYER..(XYZ), similar to MAKE ALL UNIQUE?
I do a lot of mechanical drawings with objects that contain multiple groupings of sub-components and need to show progression of movement. MAKE ALL UNIQUE is essential to make the progression of movement possible because without it the original component grouping/instance is compromised. Some of the sub-component assemblies are often nested deep into the main object. They need to be toggled onto different layers. This is problematic because each time you create a new INSTANCE to show the next progression, ALL the components within the main grouping MUST be on the same layer (Layer 0). Invariably, a tiny element in a deeply nested grouping can get stuck on an overlooked layer and that creates mayhem. A PUT ALL ON LAYER in combination with MAKE ALL UNIQUE would be a blessing.
Sorry for convoluted explanation. Perhaps this best discussed as a separate topic. (?)
-
My LayerWatcher tool in the PluginStore does [in addition to other things] something like that - ensuring that all selected faces/edges [including those nested inside] get Layer0 [Untaggd]
But nested 'containers' do not get reassigned.This reassigns EVERYTHING inside the selected 'containers' to the default [Layer0 or Untagged]
# encoding; UTF-8 module TIG module ReAssign0 #menu unless @loaded if Sketchup.active_model.selection.grep(Sketchup;;ComponentInstance) || Sketchup.active_model.selection.grep(Sketchup;;Group) UI.add_context_menu_handler{|menu| menu.add_item("ReAssign0..."){ self.do() } } end#menu @loaded=true end ### def self.do() m=Sketchup.active_model s=m.selection is=s.grep(Sketchup;;ComponentInstance) gs=s.grep(Sketchup;;Group) cs=is+gs m.start_operation('ReAssign0',true) cs.each{|c| self.process(c) } m.commit_operation end#do def self.process(cc=nil) return unless cc cc.definition.entities.each{|e| e.layer=nil } is=cc.definition.entities.grep(Sketchup;;ComponentInstance) gs=cc.definition.entities.grep(Sketchup;;Group) cs=is+gs cs.each{|c| self.process(c) } end#process end#module end#module
Copy paste into a plain-text file file named ReAssign0.rb in your Plugins folder.
It should load a context-menu item when SketchUp starts and there's a suitable selection of instance[s]/group[s]... -
Terrific! Much appreciated. This has been a bother for years, much relieved and can now say that this just about makes my workflow near-perfect when drawing progressive movements using component instances and multiple scenes.
For those of you doing similar work, an invaluable plug-in is: CMD Auto-Invisible Layer (plugin store). In native mode, Skp includes and SHOWS all material placed on a newly created layer on all the UPSTREAM SCENES. You must then manually cycle through each scene and toggle OFF the 'down stream' layer to prevent multiple objects showing and clashing with each other. A huge pain! CMD Auto-Invisible Layer is a gem. Also, by CMD, Isolate/Reveal is such a nice touch.
I'm set to go for at least another five years!
PS. TIG, apologies if your 'MyLayerWatcher' does what CMD's does
-
Oops.. spoke too soon.. I get a loading error:
no such file to load -- ./offset.rb Error Loading File ReAssign0.rb
-
Because the code I gave makes no reference to
./offset.rb
I suspect you are conflating two issues.
Provided that you copy/pasted my code into a plain-text file exactly as I explained, then there should be no problem.
Note that it MUST be a plain-text file... use NotePad++ exe...There are a few old scripts which called that kind of file...
I haven't managed to grep many !If you temporarily removed your new RB file do you still get that error ?
Not having access to your Plugins folder, then I can't be sure...One thought
offset.rb
is a Smustard.com plugin used by some of its much older scripts - e.g. clf_greeble, multi_face_scale_offset, windowizer[4] etc... or a few older scripts like WhiteOutPlane, multi-face-offset etc... which also required it ?
If you have inadvertently disabled it in the SketchUcation>Plugin-Manager - despite warnings ! - enable it and restart...
Or have you tried simply reinstalling it from Smustard.com ? -
Okay. A small confession: I still use SKP 8 (and the way things are going with Trimble, will likely do so until the end of time)
Here is the start-up dialog with all the loading errors. Lazy as I am, I just live with it.
I think 'private method' refers to the short 'make unique' script you gave me previously which I had entered in Ruby console. For some reason I did it twice-- returned 'nil' but other time it was '41' or '43' ... forget. The script did work once. Hope I haven't screwed things up..Error Loading File __loader.rb
uninitialized constant TraductorError Loading File attributes.rb
undefined methodGetString' for nil:NilClassError Loading File crate.rb no such file to load -- ./offset.rbError Loading File holes(1).rb no such file to load -- ./offset.rbError Loading File holes.rb no such file to load -- ./offset.rbError Loading File ReAssign0.rb undefined local variable or method
ο»Ώ' for main:ObjectError Loading File shapes.rb
no such file to load -- mesh_additions.rbError Loading File su2pov35Toolbar.rb
private method `split' called for nil:NilClass -
That's probably not the whole message.
You can scroll the dialog and click at the start then scroll to the end, hold shift and click the end, then Ctrl+C to copy all that's selected...The errors seem to have nothing to do with what you've just added [incidentally you can make separate RB files from the two pieces of code as explained before].
The "TraductorError" error is to do with Fredo's extensions.
You need the latest version of his Lib as well as the extensions themselves... however, note that the most recent RBZ files do not suit <v2017 - Fredo has made legacy versions available -https://sketchucation.com/pluginstore?pln=PRIOR_SU2017_LibFredo6
Search for others...Scripts like crate.rb and so on might need ofset.rb...
The error relating to your script ReAssign0.rb seems to be separate and revolves around a typo.
When you copied the whole of my text from the code box, did you paste it into a plain-text Notepad++ file and name it ReAssign0.rb ?
The reference tothrowing an error suggests you didn't as my code didn't have a
in it ! just ' or "Here's a version of the code [with a few improvements too - like making it undoable etc] as two RB files... Put those in your Plugins folder and restart SketchUp, they should load OK. Then you need to fix the other unrelated errors if they persist...
-
Goodness-- you go beyond the call of duty, Tig-- a big thank you! (donation on the way).
Both scripts work-- what a relief. And I did some house cleaning to boot. Got rid of offset.rb -- I can do without the stuff that requires it. Oddly, both crate.rb and hole.rb work, but the system is still looking for offset.rb. Curious. Thought hole.rb to be redundant given 'push-pull' but just now discover it will make holes from multiple circle selections on a surface-- whoa! Instant Swiss cheese!
cheers!
Error Loading File crate.rb
no such file to load -- ./offset.rbError Loading File holes.rb
no such file to load -- ./offset.rb -
Download offset.rb from Smustart.com and install it.
Then all of the error messages should go !
http://www.smustard.com/thanks/Offset
Advertisement