【问题标题】:Sketchup Dynamic Component Options manipulating from ruby从 ruby​​ 操作的 Sketchup 动态组件选项
【发布时间】:2012-01-20 09:42:15
【问题描述】:

我创建了一个依赖于其选项的动态组件。 我只需要从 ruby​​ api 以编程方式更改此选项。但我不明白该怎么做。

【问题讨论】:

    标签: ruby sketchup


    【解决方案1】:

    来自为 SketchUp 创建动态组件并将此代码发布到 the SketchUcation Forum 的 Google 工程师:

    UI.menu("Plugins").add_item('Make Sang Red') {
    
    # Assumes that sang is the 1st entity in model.
    sang = Sketchup.active_model.entities[0]
    sang_def = sang.definition
    
    # Override sang's shirt color to red. ("material"
    # is a special attribute that requires
    # you to set a formula to "take control" 
    # over the default material the user has painted.)
    sang_def.set_attribute 'dynamic_attributes', 'material', 'red'
    sang_def.set_attribute 'dynamic_attributes', '_material_formula', '"red"'
    
    # Add a new configurable option to Sang.
    # (Any attribute that starts with an underscore
    # is a "meta attribute" that describes behavior.)
    sang_def.set_attribute 'dynamic_attributes', 'weight', '145'
    sang_def.set_attribute 'dynamic_attributes', '_weight_label', 'weight'
    sang_def.set_attribute 'dynamic_attributes', '_weight_formlabel', 'My Weight'
    sang_def.set_attribute 'dynamic_attributes', '_weight_units', 'STRING'
    sang_def.set_attribute 'dynamic_attributes', '_weight_access', 'TEXTBOX'
    
    # Change the description that shows
    # up in the configure box with a custom
    # formula.
    sang_def.set_attribute 'dynamic_attributes', '_description_formula', '"Sang is now red and weighs " & weight'
    
    # There is a global handle into the plugin that
    # allows you to make the same calls that the
    # plugin does, like so...
    dcs = $dc_observers.get_latest_class
    dcs.redraw_with_undo(sang)
    }
    

    【讨论】:

    • 谢谢@Jim!你能在最后解释更多关于全局句柄/$dc_observers 的事情吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多