jframe移除指定组件_Ruby for SketchUp之组件定义【ComponentDefinition】

jframe移除指定组件_Ruby for SketchUp之组件定义【ComponentDefinition】_第1张图片

我们学习了群组、组件,今天来看看与之相关的组件定义即:ComponentDefinition

它跟群组、组件一样都是Drawingelement的子类。与群组、组件没有子父级关系。

组件定义在实际运用中是非常多的。

ComponentDefinition类用于定义SketchUp组件的内容。组件是实体的集合,可以

在整个模型中对其进行实例化和重用。当我们在改变原始的组件定义时,其它重用的

实例也会跟着改变。从SketchUp 2018+开始,ComponentDefinition类包含一

个名为“ SU_DefinitionSet”的新默认属性字典,其默认键名为“ Price”

,“ Size”,“ Url”。【如下图】无法通过ruby删除字典,并且会引发ArgumentError。

可以安全删除字典中的键/值对。

jframe移除指定组件_Ruby for SketchUp之组件定义【ComponentDefinition】_第2张图片

0 1组件定义【ComponentDefinition】

讲到这个ComponentDefinition,我们

还得去看看ComponentList对象。

DefinitionList对象是保存模型中所有

ComponentDefinition对象的列表。

调用方法:

#[](index) ⇒ Sketchup::ComponentDefinition?
#[](name) ⇒ Sketchup::ComponentDefinition?
#[](guid) ⇒ Sketchup::ComponentDefinition?

[]方法用于从列表中检索组件定义。你可以给出长度范围为0的整数索引,代表GUID的字符串(唯一的内部标识符)或作为定义名称的字符串。调用方法:

path = Sketchup.find_support_file "Bed.skp","Components/Components Sampler/"
model = Sketchup.active_modeldefinitions = model.definitionscomponent
definition = definitions.load path
component = definitions[0]

返回组件定义

1、组件定义根据名称排序<=>(compdef2)

#<=>(compdef2) ⇒ Integer

<=>方法用于比较两个ComponentDefinition对象以进行排序。根据组件名称进行比较。

示例代码:

c1=Sketchup.find_support_file "Bed.skp","Components/Components Sampler/"
c2=Sketchup.find_support_file "Fence.skp","Components/Components Sampler/"
if c1 <=> c2  
     UI.messagebox("c1 sorts before c2")
end

返回值:如果component1小于component2,则为-1。如果component1大于component2则为1

2、判断两个组件定义是否相同==(compdef2)

#==(compdef2) ⇒ Boolean

==方法用于测试两个ComponentDefinition对象是否相同(基于它们在内存中的地址)

示例代码:

c1=Sketchup.find_support_file "Bed.skp", "Components/Components Sampler/"
c2=Sketchup.find_support_file "Fence.skp", "Components/Components Sampler/"
if c1 == c2  
     UI.messagebox("These definitions are the same.")
end

返回值:如果ComponentDefinition对象是同一对象,则为True。如果对象不同,则为False。

3、组件定义分类

# 将给定的分类添加到组件定义
#add_classification(schema_name, schema_type) ⇒ Boolean
# 设置给定键路径的分类属性的值
#set_classification_value(path, value) ⇒ Boolean
# 从给定键路径的分类属性中检索值。
#get_classification_value(path) ⇒ Object?
# 移除给定的分类
#remove_classification(schema_name, schema_type) ⇒ Boolean

示例代码:

definition = Sketchup.active_model.definitions.first
# 将给定的分类添加到组件定义
definition.add_classification("IFC 2x3", "IfcDoor")
# 设置给定键路径的分类属性的值
path = ["IFC 2x3", "IfcDoor", "ObjectType", "IfcLabel"]
success = definition.set_classification_value(path, "Room 101")
# 从给定键路径的分类属性中检索值
value = definition.get_classification_value(path)
# 移除给定的分类
success = definition.remove_classification("IFC 2x3", "IfcDoor")

主要用于检索指定的组件定义

4、插入Point3d对象

#insertion_point ⇒ Geom::Point3d#insertion_point=(point) ⇒ Geom::Point3d

这个方法主要用于检索或设置插入的点对象

示例代码:

point = Geom::Point3d.new(10, 20, 0)
componentdefinition = Sketchup.active_model.definitions[0]
# 设置插入点对象
componentdefinition.insertion_point = point
# 检索插入的点对象
point = componentdefinition.insertion_point

注意:在这里主要说明的的在SketchUp2020已经不支持这个方法了所以在运用时需注意。

5、获取组件定义实例

#instances ⇒ Array

instances方法用于返回此组件定义的组件实例数组。

示例代码:

componentdefinition = Sketchup.active_model.definitions[0]
instances = componentdefinition.instances

返回值:返回存放组件定义实例的数组,组件定义的实例有可能是群组,也有可能是组件。

关注【老顽童与小东邪】公众号获取更多资料
最后祝我党生日快乐!

jframe移除指定组件_Ruby for SketchUp之组件定义【ComponentDefinition】_第3张图片

5fe05047e2fdb99f6afcf9b3d473d4dc.gif

你可能感兴趣的:(jframe移除指定组件)