我的植物

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 67|回复: 0

[数据转换] 清除动态属性-Clear Dynamic Attributes-1.0.0

[复制链接]

8万

主题

52

回帖

7834

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
7834
发表于 2025-3-21 18:05:26 | 显示全部楼层 |阅读模式
使用此插件可清除选定对象(包括嵌套组或组件)的全部动态属性。

操作前插件会先将选中对象及其嵌套对象唯一化,然后开始清理,清理完成后,选中的对象将变为普通模型,没有任何动态组件的属性信息。

下载地址




操作方法

选中需要清除信息的对象 – 点击 清除动态属性 工具图标 – 等待操作完成后会提示选中项的所有动态属性已被清除。

点击工具后,如果对象比较复杂,需要等待的时间可能会比较长,请耐心等待,此时SketchUp将会是不可操作的状态,清理完成后会恢复正常。
相关代码

下方代码为清除动态属性的操作代码,不过还没有添加设为唯一,会影响到模型中复制出来的其它关联组件。
-------------------

# 清除选中组或组件以及嵌套组/组件的所有 dynamic_attributes
def clear_dynamic_attributes(entity)
  # 确保当前实体有属性字典,并且包含 dynamic_attributes
  if entity.respond_to?(:attribute_dictionaries)
    dict_name = 'dynamic_attributes'
    dictionaries = entity.attribute_dictionaries
    if dictionaries && dictionaries[dict_name]
      # 获取 dynamic_attributes 字典并删除其中所有的属性
      dictionaries[dict_name].each do |key, value|
        entity.delete_attribute(dict_name, key)
      end
    end
  end
  # 如果实体是组件实例,递归清除其定义中的 dynamic_attributes
  if entity.is_a?(Sketchup::ComponentInstance)
    # 获取组件定义并检查其中的 dynamic_attributes
    component_definition = entity.definition
    clear_dynamic_attributes(component_definition)  # 清除组件定义中的动态属性
  end
  # 如果实体是组或组件,递归清除其嵌套的组/组件的动态属性
  if entity.is_a?(Sketchup::Group) || entity.is_a?(Sketchup::ComponentInstance)
    # 获取该实体的所有子实体
    entity.definition.entities.each do |sub_entity|
      clear_dynamic_attributes(sub_entity)  # 递归清除子实体的动态属性
    end
  end
end
# 使用 start_operation 和 commit_operation 来提高效率
def clear_dynamic_attributes_in_selection
  model = Sketchup.active_model
  selection = model.selection
  
  # 在一个操作中执行清除操作,避免每次操作都记录为一个单独的操作
  model.start_operation('清除动态属性', true)
  # 遍历选中的实体并清除其动态属性
  selection.each do |entity|
    clear_dynamic_attributes(entity)
  end
  # 完成操作
  model.commit_operation
  
  UI.messagebox("选中项的所有动态属性已被清除!")
end
# 执行清除操作
clear_dynamic_attributes_in_selection







本站全部资源免费下载。开通权限请联系站长管理员
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|网站地图|我的植物 ( 京ICP备15066774号-2 )|网站地图

GMT+8, 2026-4-6 17:54 , Processed in 0.034498 second(s), 32 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表