Moving right along Smart Replication

Here's another example: The bookcase in Figure 5-28 is a Dynamic Component that automatically adds shelves as you use the Scale tool to make it taller. When you scale is shorter, it removes shelves. This DC is an example of a behavior I like to call smart replication, meaning that it adds (or removes) copies of a particular part as it changes size. As you can imagine, things like stairways and fences also benefit from this kind of setup.

The key to making DCs that replicate automatically is to use the Copies attribute (which I describe at the end of this section, oddly enough). It takes most new DC-makers a couple of tries to figure out Copies, so don't get discouraged. This stuff isn't rocket science, but it isn't exactly finger painting, either.

The images in Figure 5-28 show three things:

✓ The effect of using the Scale tool on the bookcase. Notice that I've set up this DC to only be able to scale in the blue (height) and red (width) directions.

✓ The subcomponents in the DC. The hierarchy of this Dynamic Component is very simple. The parent (main) component is called Bookcase, and it contains three children (subcomponents):

• Right: The right-hand vertical support.

• Left: The left-hand vertical support.

• Shelf: Even though the bookcase currently has four shelves, this DC actually only has one Shelf component in it. The other three are copies that have been generated based on the bookshelf's total height.

Figure 5-28:

This bookcase automatically adds or removes shelves as you change its height.

Figure 5-28:

This bookcase automatically adds or removes shelves as you change its height.

Axes Tool Sketchup
Main component axis origin

✓ The Component Axes of each component. As always, where you locate the axes for your DCs (and their children) is the single biggest factor in determining how complicated your formulas will be. Take a look at the sidebar "Getting to know your components' axes" for advice.

Here's why I located my components' axes where I did:

• Bookcase: The axis origin is right smack dab in the middle, along the bottom edge of the front of the component. I put it there because Bookcase is symmetrical; it's the same on both sides. If I ever need to add parts that are equidistant (equally far) from the center of the bookcase, specifying their locations (by means of formulas) is a lot easier — one is just the negative of the other.

• Right and Left: Their axes are positioned on the outside edges of the bookcase so that scaling Bookcase to change its width will also move Right and Left. If I hadn't done this, I'd be forced to use a formula to tell each of them where to be, relative to the rest of the component. It's all about making things simpler while retaining the flexibility to make changes later.

• Shelf: Just like its parent component Bookcase, the axis origin for this component is in the center. Putting it there makes it easy to specify its location relative to the rest of the component.

Figure 5-29 is an image of the Component Attributes dialog box for Bookcase. Here's a brief rundown on the attributes (remember those?) for each of the four components:

✓ Bookcase has four visible attributes:

• ScaleTool: Clicking the Details button on the right of the row lets you specify how this component is allowed to be scaled.

• Shelf: The thickness of each shelf, in inches.

• Sides: The thickness of the side pieces, in inches.

• Spacing: The center-to-center spacing between shelves.

✓ Left and Right have only one visible attribute each. It's LenX, and it determines the thickness of the side pieces. Its value is equal to the value of Sides, in Bookcase. Having these two subcomponents refer to an attribute in their parent component makes changing them easier; it's one place instead of two.

✓ Shelf has five visible attributes:

• X: Determines the location of the axis origin of Shelf relative to the axis origin of Bookcase, along the X (red) axis. Because I centered the axes on each component when I set things up, I can make this value 0. Effectively, the center of each shelf should be 0 inches from the center of the bookcase.

.sJABEft

Figure 5-29:

Component Attributes dialog box is the DNA of this — and every — Dynamic Component.

^f Component Attributes sua i info a*

■. Add attributes below to create your component options. Visit our getting started guide for tutorials.

i info

■. Add attributes below to create your component options. Visit our getting started guide for tutorials.

E!

Bookcase

~M1

Behaviors

ScaleTocI

Some scale handles hidden.

Custom

Shelf

1

--w

Sides

15

-

Spacing

10

n

©

Add attribute

Left

Jêl

Size

LenX

=Bookcase!Sides

®

Add attribute

El

Right

im

Size ^^

LenX

=Bookcase!Sides

®

Add attribute

E)

Shelf

Ip"

X Z

-0 ^^^^^ =copy*BookcasetSpacing ----

Size

LenX

=Bookcase!LenX-(Bookcase!Sides*2) -

LenZ

=BookcasefShelf

Behaviors

Copies

=(Bookcase!LenZ-Bookcase!Shelf)/BookcaseiSpacingv

®

Add attribute

■ What the Scale tool does

■ The shelf dimension

■ The side upright dimension The shelf spacing

The size of the upright along the X axis

The position along the ' parent component's X axis

The position along the parent component's Y axis

The size of the shelf along the X axis

The size of the shelf along the Z axis

. How many copies of Shelf to draw

• Z: Determines the location of the axis origin of Shelf relative to the axis origin of Bookcase, along the Z (blue) axis. Basically, it determines the height of each shelf by multiplying two values together: the shelf spacing (Spacing in Bookcase) and the copy number of the shelf.

Here's where it gets interesting. There are four shelves in Bookcase, but only one component called Shelf, right? That's because the other three (the top three, in this case) are copies of the first one. Take a look at my description of the Copies attribute, a couple of paragraphs from now, to get the rest of the story.

The word copy in this formula (Z=copy*Bookcase!Spacing) tells SketchUp to use the copy number of the shelf it's trying to position. If it's drawing the third shelf, it uses the copy number 2 (because it's the second copy) to do the calculation. If the shelf spacing is 8 inches, then the third shelf is 8 x 2 inches high.

• LenX: Determines the dimension of Shelf in the X (red) direction. This attribute's formula takes the overall width of Bookcase and subtracts the thickness of the two side pieces.

• LenZ: Determines the dimension of Shelf in the Z (blue) direction — its thickness. According to this attribute's simple formula, its value is equal to the value of Shelf in Bookcase. By referring to an attribute in the parent component (Bookcase), you can expose its value in the Component Options dialog box. That way, it's easier for anyone to edit. Take a look at the "Pass those attributes up the chain" sidebar to find out more about this.

• Copies: Determines how many copies of this component will be created. Take a look at the formula: I told it to decide how many shelves to draw by taking the overall height of Bookcase (Bookcase!LenZ), subtracting the thickness of a single shelf (Bookcase!Shelf), and dividing by the shelf spacing (Bookcase!Spacing).

The attribute Copies automatically rounds down to the nearest whole number, which is why I don't have to worry about SketchUp trying to draw a fraction of a shelf. When you're building your own smart-replication DCs, you sometimes need to specify the number of shelves in another attribute. In that case, take a look at the ROUND, FLOOR, and CEILING functions listed in the drop-down menu at the top of the Component Attributes dialog box.

0 0

Post a comment

  • Receive news updates via email from this site