Calling dynamic components redraw from C importer

Does this importer run from within the SketchUp application process ?

I am guessing NO because the C API is not yet a “live” API that can modify the current model.

The answer weighs upon …

The DC code is implemented in Ruby, so can only run within the SketchUp application process.
But since Ruby is implemented in C, and has it’s own C API, then calls to Ruby object methods (ie, SketchUp’s Ruby API and model objects) can be called from C in several ways.

So, if the answer is yes, your importer is running within SketchUp, then you can call the DC code.
The simpliest is …

rb_eval_string("$dc_observers.get_latest_class.redraw_with_undo(dc_instance)")

… where dc_instance is a Ruby-side reference the the DC instance you wish to draw.

There are also other Ruby C API functions that can be used for more complicated Ruby calls from C.
The subject of Ruby C extensions is too involved for this discussion. See the example posted at GitHub …

The DCs are a bit weird. It really helps if you understand Ruby, and have experience crafting DCs manually in SketchUp.

You cannot set the standard DC attributes directly. So you’d need to create a custom attribute, let’s name it “height” and set it to 114.7244094.
Then set the “_lenz_formula” attribute to point at the “height” attribute.

That said, … the Dynamic Components extension is proprietary closed source and the interaction of the dynamic attributes and it’s code is quite complex. There is no actual public API nor documentation for developers. (Note the the C API only has informational getter functions that are DC specific.)

Any workarounds we post in the forums are really “hacks” and not guaranteed to work in future releases as the DC code could be changed at any time, without notice.

Regardless, your best advice for crafting dynamic components will come from the forum subcategory:

In that subcategory I’ve created a wikilist of DC Resources …

1 Like