by shirazbj » Mon Mar 16, 2009 12:25 pm
Hi, I have tried to use two intersected cubes to demonstrate how to use the intersect_with command. This could be a example for the ruby doc. - Code: Select all
model = Sketchup.active_model entities = model.entities
basegroup=entities.add_group basegroupentities=basegroup.entities p1 = Geom::Point3d.new(0, 0, 0) p2 = Geom::Point3d.new(2000, 0, 0) p3 = Geom::Point3d.new(2000, 150, 0) p4 = Geom::Point3d.new(0, 150, 0) p5 = Geom::Point3d.new(0, 0, 0) points = [p1,p2,p3,p4,p5] base = basegroupentities.add_face points normal = base.normal if normal==[0,0,-1] base = base.reverse! end base.pushpull 1000 base_trans=basegroup.transformation
cutgroup=entities.add_group cutgroupentities=cutgroup.entities p1 = Geom::Point3d.new(500, -50, 500) p2 = Geom::Point3d.new(1500, -50, 500) p3 = Geom::Point3d.new(1500, 200, 500) p4 = Geom::Point3d.new(500, 200, 500) p5 = Geom::Point3d.new(500, -50, 500) points = [p1,p2,p3,p4,p5] base = cutgroupentities.add_face points normal = base.normal if normal==[0,0,-1] base = base.reverse! end base.pushpull 1000 cut_trans=cutgroup.transformation cutgroupentities.intersect_with false, cut_trans, basegroup, base_trans , true, basegroup status = basegroup.explode model.active_view.zoom_extents UI.messagebox("Click to delete cut group.") cutgroup.erase!
Last edited by thomthom on Wed Feb 09, 2011 8:30 am, edited 1 time in total.
Reason: Put the code into a code box and renamed the tag
-
shirazbj
-
- Posts: 34
- Joined: Sat Mar 07, 2009 1:05 am
by DavidBoulder » Tue Feb 08, 2011 10:07 pm
Thanks, that was really helpful, but I'm having problems with a simple variation on this.
The basic concept is a model with only groups at the top level. The user selects a group and then runs the script. The script should intersect that group with the model; the new geometry is created inside of that group. My next step after this is working is to let the user multi-select and iterate through their selection. That should be easy if I can just get the basic code working first.
This is what I want for the intersect_with line, but I just can't get it to work. I guess I need to get the name of the group that is in selection[0]? and then use that similar to your code.
selection[0].intersect_with true, selection[0].transformation, selection[0], [0,0,0], true, entities
--
David Goldwasser OpenStudio Developer National Renewable Energy Laboratory
-

DavidBoulder
-
- Posts: 342
- Joined: Tue May 13, 2008 7:22 pm
- Location: Boulder, co
- Name: David Goldwasser
- Operating system: Windows
- SketchUp version: pre-2013
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Tue Feb 08, 2011 10:40 pm
Your selection[0] will be an entity BUT the intersect_with method is for entities - that is the 'container-entities' holding that individual entity... see http://code.google.com/apis/sketchup/do ... rsect_with Recast it something like... selection[0].parent.entities.intersect_with(true, selection[0].transformation, selection[0].parent.entities, selection[0].transformation, true, entities)*** ***I'm not sure what your final argument ' entities' is - it should either be an 'entities object' or an 'array of entities'... it could be selection[0].parent.entities.to_a so all entities in the same context are used in the intersection 
TIG
-

TIG
- Global Moderator
-
- Posts: 20380
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by Dan Rathbun » Tue Feb 08, 2011 11:03 pm
Someone please..
Codebox the script example, parenthesize the intersect_with call (it wraps,) and rename the topic title: [ code ] Entities.intersect_with example .. so that Jim's sticky code index script can find it.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by DavidBoulder » Wed Feb 09, 2011 7:26 am
TIG, thanks for you help. That got me over the hump. Below is what I was looking for. If you select one or more top level groups and run this script, it will iterate through the groups adding necessary intersecting geometry under each group. - Code: Select all
model = Sketchup.active_model entities = model.active_entities selection = model.selection
# loop through selection of top level groups to create new intersecting geomtry under each group. selection.each { |entity| entity.entities.intersect_with(true, entity.transformation, entity.entities.parent, entity.transformation, true, entity.parent.entities.to_a) }
--
David Goldwasser OpenStudio Developer National Renewable Energy Laboratory
-

DavidBoulder
-
- Posts: 342
- Joined: Tue May 13, 2008 7:22 pm
- Location: Boulder, co
- Name: David Goldwasser
- Operating system: Windows
- SketchUp version: pre-2013
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Wed Feb 09, 2011 9:07 am
I suggest you trap for non-groups - Code: Select all
selection.each { |entity| ### next if not entity.class==Sketchup::Group ### entity.entities.intersect_with(true, entity.transformation, entity.entities.parent, entity.transformation, true, entity.parent.entities.to_a) }
Also shouldn't entity.entities.parent be entity.entities.parent.entities 
TIG
-

TIG
- Global Moderator
-
- Posts: 20380
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|