Resize DC with ruby
-
I'm trying to resize a DC with a ruby script. But the result is very strange.
I use the .set_last_size function, and the DC size changes but not to the right size.
-
Where is the documentation on .set_last_size?
What happens if you use using a typical scaling Transformation?
-
Dan covered the additional methods added by the DC Extension [including that one] here
http://www.sketchucation.com/forums/viewtopic.php?p=293542&sid=5e9cba98370bfa85f9ab7093e95f2894#p293542 -
If you use .scaled_size and .unscaled_size these return arrays of the xyz size/scales as original or current.
If you use these values in the .set_last_size() with a modifying * or / for x/y/z values you will see that halving the X doubles LenX and so on - so conversely to double the X use /2. To set the X-length to a new value in 'units' just do the cockeyed math to get the correct factor - e.g. x=10" and you want it to be 20" you find the ratio 10/20, and then apply it to the present scaling factor as a / (as 'manual trials' show... to make it *2 you'd actually use /2
)... [do the "/cm conversions to suit...] It just seems weird 
-
@unknownuser said:
I'm trying to resize a DC with a ruby script. But the result is very strange.
I use the .set_last_size function, and the DC size changes but not to the right size.
The .set_last_size function is an internal method that needs to be called at the correct point in the redraw process depending on various factors, as driven by the DCObservers.
A DynamicComponent is not actually a Ruby class in the instance object sense (although it was written as a Singleton class block, it really could have been written as a module, instead.)
So a DC, is really just a Sketchup::ComponentInstance instance object, that has a specially named AttributeDictionary, ie: "dynamic_attributes" and the DC extension has Observers that "watch for" and react upon objects that have that specially named dictionary.
I suggest you use the normal transform! method to scale or move a DC via Ruby, then if you must force a redraw, call the redraw as you did in your example.
Also, if doing rotational transforms, be sure to do them in x, y, z order. -
Hello,
I wrote a small code to add a DC at a specific position and resize it.
So when Sketchup add an instance of a DC its position is 0,0,0. You need to define a transformation to place it where you want.
t1 = Geom;;Transformation.axes(...,...,...) newDC = Sketchup.active_model.entities.add_instance(Sketchup.active_model.definitions["MyDC"],t1)To set the length I used the set_attribute method of the DC definition
len = 13 len2 = 12 newDC.definition.set_attribute "dynamic_attributes","_lenx_nominal",len.to_s newDC.definition.set_attribute "dynamic_attributes","_lenz_nominal",len2.to_s
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement