I try to create a Dynamic Component to represent wood boards of specific dimensions, say e.g. 2"x4". The idea is to have one DC for each dimension, while each instance (board) may be of various lengths. The board is represented by a simple box, with LenX representing the length of the board, LenY the width, and LenZ the thickness. I want LenY and LenZ to be fixed while LenX should be given by the user through the DC options dialog, or by using the Scale tool. This setup, I expect will be helpful in keeping track of the needs for various materials in a project.
If I just create a box with the appropriate LenY and LenZ, and make a normal (non-dynamic) component of it, it does the job to some extent: I can adjust the length (LenX) by using the Scale tool, but I must take care not to change the other dimensions. To achieve the latter, I have to put the simple board component into a DC, expose the LenX attribute to the users by the Options dialog, and lock LenY and LenZ in the inner component. But then I get a behaviour which I think is an error: When I make an instance of the DC, and then either use the Scale tool or the DC options dialog to set the actual length of the board (LenX), a new component type is created automatically, as if I had given the “Make Unique” command. Changing the value of a defined parameter should not lead to the creation of a new DC type. And that doesn’t happen when instances of normal component types are scaled, as is the behaviour I would expect.
This is the probably the reason you are getting automatic unique copies:
Here is a quick test. First with the internal box not set to retain its dimensions and the second with setting the internal box dimensions to a fixed size.
So, in your case try making the wood board at the starting size before making it into a component rather than setting its starting size in the component attributes.
A short explanation:
BoardA (yellow): Dynamic component with LenX exposed to the user. Stretched or LenX set without generating a new components class
BoardB (green): Like Board A: Created by “Make Unique” and then renamed to BoardB. Board B keeps the Attribute and Options dialog from BoardA. Minor problem, but disturbing
BoardD (red) with Board C inside: LenX exposed to the user. (LenY and LenZ in the inner BoardC not locked). Stretches without generating a new component class. (Had to be created by making a component of two instances of BoardC and then delete one of them. Should not be necessary with such a workaround.)
BoardF (blue) wiht Board E inside: Equal to BoardD, but with LenY and LenZ in the inner BoardE locked. Creates a new component (like “Make Unique”) if one makes a copy and then stretches the copy.
I expected that changing any of the defined and exposed attributes in a DC instance would be permitted without automatic creation of a new component type. Given my background with object oriented languages (Java, C# etc), I am inclined to think of SketchUps component definitions as classes and component instances as objects in the terminology of object-oriented programming. But might be that’s not the right approach?
Thank you for your anwer! I see that setting the board dimensions (width and thickness) at start is a possible solution. (That is the same as the BoardD case in my test.) The problem with that solution, is that it makes it possible for the user to stretch not only the length (LenX) but also width and thickness, which is exactly what I wanted to prevent.
If the feature with automatic creation of new component definitions caused by stretching an instance of a DC instance is made by design, I still don’t understand why.
I took a quick look at your component. One thing is try to add the scale tool within the component. Add it then click on the details of that field (at ths right side of the field) That allows you to disable any of the axis allowed to be scaled or dis able scaling all together. Im not sure what your final goal is but it looks to me that you could have the options menu have a list to choose a board size (2x4, 2x6 2x8) or what ever size your wanting then either a list for length or key in the exact length. Does that sound like what would be better?
You are going about this slightly the wrong way. To restrict scaling to only one axis, set what can be scaled using the Scale Tool attributes in the parent Component (as @ivanjones has explained).
I have rebuilt your BoardF to work as I think you want it to work. You can download and try it out:
Now draw some temporary thing next to this component (such as a short line). Select both the “Board” component and the short line and make into a component. I called the parent component “Board Dynamic”. Now you can delete the short line - (it was just there to allow you to make a parent component enclosing your “Board” component).
Set a Scale Tool attribute in the parent component so that scaling is only allowed along the X axis.
Do not set the child board component to any fixed size (as I mentioned in my first post). This will prevent instances being created when you scale copies of the component.
When you select this board and scale it, only one scale handle is shown, preventing any other scaling i.e. it can only be scaled along its length by the user.
If you have set it up this way, you can also enter the length manually:
And scaling copies of a dynamic component built this way will not make new instances (your original request).
This approach solves the problem, and gives me exactly that functionality I wanted. I’m in the process of learning both dynamic components and writing extensions, aside from getting a deeper understanding of Sketchup itself. My idea, mostly as an excercise for myself in writing an extension, is to define component types for each of the standard board dimensions. If I can trust that the board dimension (width and thickness) are fixed for all instances of a given board component type, I thought it would be quite simple to make a simple cut list, and get the total amount (meters or foot) needed for each board type in a project. I would guess this is already solved excellently in some of the available extensions in Extension Warehouse or other places. For me this is only ment as an example task to learn writing extensions.
Thanks a lot for your lucid and comprehensive explanation! This solves the problem and give me exactly the functionality I was searching for. I would have marked this as a solution, but as @IvanJones already mentioned the crucial element - limiting the scaling options - that was marked as a solution.