Scaling a component with subcomponents
-
So after starting a topic on DCs and creating only to find out that's more then likely not what I need to do. Topic found here...
http://sketchucation.com/forums/viewtopic.php?f=180&t=48697I started looking into scaling.. which works, somewhat.
Here's the code I've been playing with...
model = Sketchup.active_model entities = model.active_entities ss = model.selection ents = Sketchup.active_model.entities t = Geom;;Transformation.scaling 1,1,0.5 ents.transform_entities t, ss
This works BUT it also scales the subcomponents. I'd like to be able to scale or manipulate those individually if needed.
Basically my plugin creates cabinets and I'd like to be able to change the size of any given value once the component is created. I am using a web dialog and everything works but I'd really liketo integrate this into my plugin. I know I can do it with DCs but again I'd like to be able to do this directly from my plugin.
Hope that gives a clearer understanding of what I'm trying to accomplish.
Thanks,
Frank -
It works just like in regular modeling. So if scale a component in SU using the scale tool, it also scales everything inside that component.
If you want to scale only certain elements inside a component, then you need to look at the components inside the component, determine which one you want to scale and scale only that one.
You can also make components unique in ruby, just like you do in SketchUp so that when you tweak its insides, it won't mess with other components.
-
Thanks, again, for your reply Chris.
Man this is turning out to be more complicated then I first thought! But then again I've said that about everything about my plugin so far.
What you're describing to do sounds a lot like what DCs do, no? Example, resizing the height of a cabinet would only stretch the sides, back and any other components like doors or drawers and then move the othe components to match the height. Seems like scaling is a lot mor 'work' then trying to get DCs working... but again this is all new to me and I might be way out in left field here.
I did find a plugin that does what I'd like to do and that is freescale from Freedo. I'm trying to follow along in the ruby code as to how he goes about doing what his plugin calls 'Box Stretching' but Freedo is a ruby god and so far it hasn't been easy to figure out the code.
-
Honestly yeah, its a bit like a DC because you're trying to make a paramateric component controller. BUT if you actually use the DC structure, I think it could be become even more complex.
But how do you envision it working otherwise? If you scale a component, it scales everything inside it. What were you expecting it to do?
And yes, this will be much more work then getting an actual DC to work. Because you're reprogramming a lot of stuff - reinventing the wheel if you will. the only reason to reinvent the wheel should be if the wheel isn't working for your needs. In other words, if DC's do what you need, then don't remake your own version of DC's.
But if you need different functionality, or if you just want a complex program to write for fun, then go for it!
-
@chris fullmer said:
But how do you envision it working otherwise? If you scale a component, it scales everything inside it. What were you expecting it to do?
Yeah, scaling works fine for the 'outer' dimensions, meaning that if a cabient is 20"w x 20"d x 20"h and the cabinet carcass stock is 5/8" thick and I change the height to 10", which is scaling the by 0.5, the height of the cabinet changes to 10" which is great but the thinknes of 5/8" also gets scaled down by 0.5 and then becomes 5/16". I'm having a hard time explaining what I mean so I included a picture.
@unknownuser said:
And yes, this will be much more work then getting an actual DC to work. Because you're reprogramming a lot of stuff - reinventing the wheel if you will. the only reason to reinvent the wheel should be if the wheel isn't working for your needs. In other words, if DC's do what you need, then don't remake your own version of DC's.
But if you need different functionality, or if you just want a complex program to write for fun, then go for it!
DCs do some of what I want and can probably do more, honestly I didn't play around with it much since yes in part I'm just trying to learn new stuff and kind of make a one stop shop plugin. Not all users would want to or even know how to use DCs so in that sense I want to 'simplify' the process of editing a built cabinet.
Which brings me back to my original post/question, where can I find more info or examples of how to manipulate components/create DCs through ruby?
Frank
-
Well the idea with DC's is that you develop them to work how you want. you're the one who has to go through the hassle of writing the code into them (using the supplied DC tools). Then the user ends up not hardly having to deal with the details. They just scale how wide they want it and magically some things inside do scale while others don't.
I'm not even sure where to find solid examples of controlling DC properties with your own webdialog. But I'm sure there are a few examples here on the forum, possibly one of the Sketchup blog? or the developers blog?
I could be wrong, but I'd suggest you get really familiar with what DC's can and can't do first. Then determine if you want to make your own identical but slightly different system.
BTW, the ONLY reason to make your plugin follow the way the DC's are made is if you want your components to be able to be manipulated with the built in DC tools, like the properties web dialog and the finger tool (Interact). If you don't care if you're components can be modified by those tools, then again, I think wasting your time with DC's is futile.
Maybe something else you're not seeing. DC's are just plain ruby and webdialogs. There is nothing built into sketchup itself that manages DC's. Dc's are made my adding a LOT of tags to each component that specifies how that component can and can't be scaled. Then the DC ruby script watches the model and anytime something is scaled, it iterates through all the components of the Dc and figures out what got messed up and what it needs to do to configure the DC so it works the way its intended.
You'll have to rebuild ALL of that, plus a zillion other things I've not mentioned. Which is fine, but I think you might be happier just looking into actual DC's a little more first. And please don't let my opinion be the one that stops your project!
-
Don't muddle DC and normal code...
When Scaling DON'T type in a 'factor' !
You can type in an actual dimension provided that what you type has a units suffix.
So typing 0.5 makes the object half its height, but typing in 10" makes it exactly that height.
However, vertical elements WILL scale in size using this method...
SO in this illustrated case 'Scale' is the tool of choice...Don't use 'Scale' at all...
First draw a guideline using the Tapemeasure tool, exactly 10" vertically above the base's bottom.
Select the top face AND bottom face of the upper horizontal part of the assembly [hold Ctrl to add to a Selection].
Now invoke the 'Move' tool and click on a top-face's edge and Move the two still-selected faces [and their attached edges] vertically downwards [use Shift or the Arrow-keys to constrain to the blue [Z] axis if needed] and then snap to the guideline. The top parts are relocated now 10" above the base and are still stay the same distance apart as when they started.So the often useful 'Scale' is not the tool for your needs in this case... it's the 'Move' tool for you this time...
Doing this manually or in code via the API is very similar...
-
Well I followed your advice and played with DC interface a little more and paid much more attention to how it works... so I set a value lenx and found this code snipet which modifies it...
cab_instance = Sketchup.active_model.entities[0] cab_definition = cab_instance.definition ad = cab_definition.attribute_dictionary "dynamic_attributes" ad["_lenx_"] = '10' $dc_observers.get_latest_class.redraw_with_undo(cab_instance)
BUT it actually acts in the same way as scaling does but is more complicated lol! Talk about going full circle. And yeah there aren't too many examples of controlling DCs through ruby.
I'll keep trying out some things and see what I can figure out.
-
Yeah, parametric modeling (which is essentially what we're talking about here) get's tricky quickly because you have to add parameters that control hos things are allowed to move, scale, rotate, etc. so in your cabinet example, you would need to specif that when the thing is scaled vertically, certain elements are allowed to be squashed, while others must retain their height thickness. And it only compounds in difficulty what you start adding sub sub components and how that should act.
-
Thanks Tig,
The move tool works fine for a 'simple' cabinet but once doors, drawers and drawer boxes are added it quickly becomes cubersome, if not impossible to do. I was hoping that it was a simple matter of modifying the scale tool or getting DCs figuered out but it seems like it's way more complicated then that, for a simplton like me anyways.
Yes that's exactly right Chris... there's a lot going on in something as 'simple' as a cabinet, I'm surprised I made it this far with this plugin.
Thanks for the ideas and insight, hopefully I can come up with something.
-
@frankn said:
Thanks Tig,
The move tool works fine for a 'simple' cabinet but once doors, drawers and drawer boxes are added it quickly becomes cubersome, if not impossible to do. I was hoping that it was a simple matter of modifying the scale tool or getting DCs figuered out but it seems like it's way more complicated then that, for a simplton like me anyways.
You could use the Stretch tool of FredoScale which is usually well adapted to scaling square things like cabinets. It is actually a generalization of what the SU Move tool can do, but it digs within components and groups.
Fredo
-
Hey Fredo6,
I actually mentionned you plugin in my other post and how I was trying to figure out how you did it. Only problem is you're a ruby/sketchup god and I'm more of a peasant.Thanks to Chris, I now know that what I'm trying to accomplish is called parametric modeling, learn something new everyday . So I did a search for that and came up with this file parametric.rb (attached) and a couple of interesting websites, though I haven't had a chance to go through them so I apologize if they aren't that good.
http://drivingdimensions.com/SketchUp/FAQ/
http://www.sketchup.com/intl/en/download/rubyscripts.html[EDIT: attachment removed by admin]
Advertisement