Resizing a DC via Ruby?
-
If a DC has a formula for its Z length, is there a way to set its size via Ruby?
LenZ: =largest(8, round(current("LenZ")/8)*8)
-
I imagine that Scott posted a sample command one could send to a DC to force it to refresh... don't have the link though....
-
I can simply use a Transformation to scale the DC to any size I need, and then do a redraw. But if it has internal components, everything gets whacked-out.
This is sort of related to this discussion:
-
Here's an example of what I'm trying to do. I have a DC named PeggedPost. This is a component stored in an external file, and used in one or more master files. If the component is then edited, I want to be able to re-load and replace the definition in a master file.
Normal Scaled Instances:
I am using this code at the moment:
model = Sketchup.active_model entities = model.entities selection = model.selection ins = selection[0] ins.definition.save_as("/dev/null") new_post = model.definitions.load("c;/Documents and Settings/Jim/My Documents/PeggedPost.skp") ins.definition = new_post $dc_observers.get_latest_class.redraw_with_undo(ins)
But this falls apart when an instance has been scaled. Note the component on the right - it was scaled, then the above code executed.
Messed Up Instance.
Is this even the right approach, or is there a better way to do it?
(TIG's xref plug-in does not handle this particular situation either.)
(the snippet is stored in a model attribute and can be pulled into my latest version of webconsole automatically: http://bitbucket.org/jimfoltz/webconsole/downloads )
-
Jim,
Couple of things I had to do to get the behavior you want:
-
Rebuild the DC so there is no naked geometry. I turned the "post" into a subcomponent that sets its LENZ to the parent LENZ. (Naked geometry in DCs is particularly dumb. When in doubt, make everything a subcomponent instead of faces and edges.)
-
Add a couple lines of code that store the unscaled size onto the component instance before you redraw it. This gives the plugin the information it needs to scale correctly after the import.
model = Sketchup.active_model entities = model.entities selection = model.selection ins = selection[0] new_post = model.definitions.load("c;/temp/PeggedPost_noNakedGeometry.skp") ins.definition = new_post lenx, leny, lenz = ins.unscaled_size ins.set_last_size(lenx, leny, lenz) $dc_observers.get_latest_class.redraw_with_undo(ins)
Cheers,
-
-
@unknownuser said:
- Rebuild the DC so there is no naked geometry. I turned the "post" into a subcomponent that sets its LENZ to the parent LENZ. (Naked geometry in DCs is particularly dumb. When in doubt, make everything a subcomponent instead of faces and edges.)
What about when you make cutout DC's? Then you need "naked" edges to make the cut.
Advertisement