Creating components from existing objects
-
Hello,
I'm trying to do a world-in-miniature kind of concept, whereby I'm taking all existing entities in the world and make it into a component. At a later point, the plan is to make an instance of it.
The part I'm having trouble is adding existing entities into the component definition. My components are showing up empty irrespective of how I add the existing entities. Any help would be greatly appreciated.
Here is my trial code
list = Sketchup.active_model.definitions world_def = list.add "World" world_def.description = "This is all of the world." ents = world_def.entities Sketchup.active_model.entities.each{ |x| if(x.class == Sketchup;;Group) ents.add_group x end } # Create the extrusion and save the definition comp_path = Sketchup.find_support_file "Components", "" world_def.save_as comp_path + "/candle.skp" t1= Geom;;Transformation.translation Geom;;Point3d.new(0,100,0) inst1 = Sketchup.active_model.entities.add_instance world_def, t1
Thanks in advance
Arun -
Are your script also generating the geometry you want to place in the component? If so, then you should just add it directly to the component definition.
-
This seems to work.
mod = Sketchup.active_model ent = mod.entities sel = mod.selection wgrp=ent.add_group ent.to_a #create a group containing all existing entities wcmp=wgrp.to_component #convert the group to a component/instance. wcmp.definition.name="World" #give it a name
-
@thomthom said:
Are your script also generating the geometry you want to place in the component? If so, then you should just add it directly to the component definition.
Hi Tom,
The geometries are generated by the users as they go along. I'm trying to make this a tool so as and when the user switches to the tool, all of the currently existing models (except certain objects) become part of the miniature view
-
@sdmitch said:
This seems to work.
mod = Sketchup.active_model > ent = mod.entities > sel = mod.selection > > wgrp=ent.add_group ent.to_a #create a group containing all existing entities > wcmp=wgrp.to_component #convert the group to a component/instance. > wcmp.definition.name="World" #give it a name >
Ahhh! group to component! Thank you so much
-
Another question on a related note.
Is there a way to set the Level Of Detail on the miniature component instance alone?
It seems to be affecting performance with large models like castles and for the size at which I'm rendering the miniature, I couldn't care if its quality went down -
There is always a way but at what cost. The code would no doubt expand from 3 lines to 3000.
-
Beware... if
ents
ismodel.entities
and that's not the current 'active_entities' context thenents.add_group(ents.to_a)
orents.add_group(model.selection.to_a)
etc will Bugsplat!So... always ensure that the
ents=model.**active_**entities
and the objects you are trying to add to the new group are in the same context - hence the recommendation for 'selection' because the user can't manually select things that are not in the current active context... -
@tig said:
Beware... if
ents
ismodel.entities
and that's not the current 'active_entities' context thenents.add_group(ents.to_a)
orents.add_group(model.selection.to_a)
etc will Bugsplat!So... always ensure that the
ents=model.**active_**entities
and the objects you are trying to add to the new group are in the same context - hence the recommendation for 'selection' because the user can't manually select things that are not in the current active context...TIG thanks. Will keep that in mind
-
You might play with the Fog settings. Adjust the near and far clipping planes. (But this is really not LOD.)
-
@dan rathbun said:
You might play with the Fog settings. Adjust the near and far clipping planes. (But this is really not LOD.)
Thanks Dan. Will give that a try
-
@sdmitch said:
There is always a way but at what cost. The code would no doubt expand from 3 lines to 3000.
I'm on a framerate sensitive medium, so anything I can do to improve frame rate would be useful. It would be great if you have any tips on how to set the LOD for the miniature.
Advertisement