How to access the Ruby functions in Dynamic Component attribute value

Hi.,
Somebody could help or throw light on how to access the function in a ruby program to use in the Dynamic Component attribute field. ie custom function apart from the standard function available in the sketchup ( like, math, trig, Logical). Reference for the same is attached in the screenshot below.

The dynamic component is inserted from a plugin.


thanks

You cannot, by default.
To call a function from the attributes, the function has to be registered to the dynamic components extension’s function handler.

@kengey.,
Could you explain deeper with some raw code outline about using function handler .

Dynamic Components is a proprietary closed source extension copyrighted by Trimble.

It is not allowed for publicly published extensions to modify the Dynamic Components modules or classes.

The main reason is that modifying the DC classes set up a scenario where DC components are marked as version “1.00” (indicating they need code version “1.00”, but in reality you would have revised the DC class code to some higher version. (It is the privilege and responsibility of the code copyright owner to revise the DC code.)


It would be better and simpler if your extension code inserted a value into the target component’s “dynamic_attributes” dictionary, and then other DC attributes use that value.

For a default value, the attribute/value is inserted into the DC definition’s “dynamic_attributes” dictionary, and any individual overridden value is inserted into the DC instance’s “dynamic_attributes” dictionary. (So the former always exists, and the latter only if an instance uses a value different from the default definition value.)

Thanks @DanRathbun & @kengey.
Seems to understand a little bit :slight_smile:
Even for a custom attribute apart from native attributes, the value cannot be called from ruby, ( i am referring the above image, which has posted earlier.
Forgive if it seems silly…

Sure it can

# At top of your extension submodule with other local constants:
DC_DICT ||= "dynamic_attributes"

# Elsewhere in your extension submodule:

def set_price(object, amount, attribute = "price")
  dyna_cdef = object.respond_to?(:definition) ? object.definition : object
  dyna_cdef.set_attribute(DC_DICT, attribute, amount)
end

def total_price(object, attribute = "price")
  dyna_cdef = object.respond_to?(:definition) ? object.definition : object
  price_each = dyna_cdef.get_attribute(DC_DICT, attribute)
  quantity_used = dyna_cdef.count_used_instances
  price_total = price_each * quantity_used
end

@DanRathbun. Thanks.
will check it out.