Okay, by now you've drawn some stuff. You know what a Face and Edge are. But if you're drawing something like a building, chances are you're using the same geometry over and over. That's where Groups and Components come in. They are great.
The thing on the left is a Group (a set of unified edges/faces). The middle bit is just faces and edges.
On on the right? You guessed it. Three instances of the same component.
Groups of faces are like groups of people, only less ornery
Think way back to Lesson 5, where we drew those stairs. We accomplished most of what we needed to so with the Entities.add_face method.
So, any guesses to how you add a Group? That's right, Entities.add_group! Take a sec to go read it's documentation.
CHALLENGE ONE
Add yet another menu item to the Plugins menu named "Create Door"
Make it so when the user selects this menu item, it adds a Group to the model.
Draw a face inside this group that is 36" wide, 72" tall (hint, just like the Model, every Group has its own Entities collection)
Give this group a name of "Door" (hint, group.name)
When it's all done, you should have something kinda like this...
If you right click on your door and select "Entity Info," you should see your name of "Door"
Extra Credit
Give the door a thickness of 2"
Paint the door red. (hint: groups are a subclass of Drawingelement, and every Drawingelement has a material...)
Components are cooler than Groups.
They can be reused.
The difference between a group and a component is that groups are singular. If I copy/paste a group, SketchUp generates a whole clone of that group. If I modify the clone, the original remains unchanged. This isn't so good if I need to represent a thousand windows of the same kind throughout a building.
Components are cool because they can be copied infinitely. Each component maintains a Definition that contains all of its geometry, and when you change the Definition, all of its instances (aka copies) automatically get those changes.
In the Ruby world, it means that to muck with Components, we have to deal with both Definitions and Instances. To add a component, we must first add a definition and insert some faces into it, and THEN insert an instance of that definition into the model.
CHALLENGE TWO
Add yet another menu item to the Plugins menu named "Create Component Door" (hint, copy and paste Challenge one!)
Wherever your old script said "model.entities.add_group", replace with "model.definitions.add" (Yep, the model has a definitions collection.)
Okay, in theory, you now have a menu item that adds a definition to your model containing a 36"x72" door. But when you run the script, you won't see a door in your model! That's because you need an instance.
First, let's do it manually. In SketchUp, run your new script, then select Window > Components and click the little "home" icon. This will show you all of the components in your current model. Scroll down and you should see your door, kinda like this...
Now, drag and drop your new definition into SketchUp, and you can place doors to your heart's content.
CHALLENGE THREE
Now make it so your script not only adds a definition, but also inserts a door at the model origin. (hint: model.entities.add_instance is your friend)
Extra Credit
Insert the same door ten times into the model, each at a different location (say, 100" incrementally to the right)
AFTER you've inserted the door ten times, add some panels to the definition and watch it update all of the doors, kinda like so.
Wow, look at all those paneled doors!
Congrats! If you've gotten this far you're ready to do some freeform hacking. Go make a script that does something really cool.