属性编辑器

From FreeCAD Documentation
Jump to navigation Jump to search
This page is a translated version of the page Property editor and the translation is 6% complete.
Outdated translations are marked like this.
Other languages:
Bahasa Indonesia • ‎Deutsch • ‎English • ‎Türkçe • ‎español • ‎français • ‎hrvatski • ‎italiano • ‎polski • ‎português • ‎português do Brasil • ‎română • ‎svenska • ‎čeština • ‎български • ‎русский • ‎українська • ‎中文(中国大陆)‎

概述

属性编辑器是FreeCAD最重要的工具之一,也是FreeCAD使用的主要元素。 属性编辑器允许管理文档中对象的属性。

The property editor appears when the Model tab of the combo view is active in the interface; it allows managing the publicly exposed properties of the objects in the document.

通常,属性编辑器一次只处理一个对象。属性编辑器中显示的值属于活动文档的活动对象(如果您处理多个文档,请注意哪个文档是真正活动文档)。如果您没有选择任何元素(或没有元素),则属性编辑器将为空。

并不是所有的属性都可以随时修改。根据具体状态,某些属性将显示为只读。

FreeCAD Property editor empty.png

Empty property editor, when no object is selected.


属性定义

一个属性是一条信息,如一个数字或文本字符串,附加到一个FreeCAD文档或文档中的一个对象。可以使用属性编辑器修改属性,如果允许的话。

A property is a piece of information like a number or a text string that is attached to a FreeCAD document or an object in the document.

FreeCAD中的自定义脚本对象可以具有以下类型的属性:

Some of the most commonly used property types are:

App::PropertyBool
App::PropertyFloat
App::PropertyAngle
App::PropertyDistance
App::PropertyInteger
App::PropertyString
App::PropertyMatrix
App::PropertyVector
App::PropertyPlacement

不同的对象可能有不同的属性。然而,一些属性在所有对象中是常见的,例如对象的位置和旋转是可以被操纵的数据属性。

View and Data properties

有两种功能属性类型,可通过属性编辑器下方的选项卡来访问:

ViewView : 关于对象“视觉”显示方面上的各种属性。
DataData : 关于对象“物理”参数的各种属性。

For this reason, Data properties are considered to be more "real", as they truly define the geometry of a shape. On the other hand, View properties are less important because they only affect the superficial appearance of the geometry. For example, a circle of 10 mm radius is different from a circle of 5 mm radius; the color of the circle (view property) doesn't affect its shape, but the radius does (data property). In many instances in this documentation, the word "property" is understood to refer to a "Data property" and not to a "View property".

Basic properties

The most basic scripted object won't show any Data property in the property editor, except for its Label attribute. The Label is a user editable string that identifies the object in the tree view. On the other hand, the Name attribute of an object is assigned at the moment of its creation and cannot be changed; this attribute is read-only, and is not displayed in the property editor either.

A basic parametric object is created as follow

obj = App.ActiveDocument.addObject("App::FeaturePython", "App__FeaturePython")
obj.Label = "Plain_object"
print(obj.Name)
print(obj.Label)

FreeCAD Property editor View basic.png FreeCAD Property editor Data basic.png

View and Data tabs of the property editor, for a basic "App::FeaturePython" scripted object.


Most geometrical objects that can be created and displayed in the 3D view are derived from a Part::Feature. See Part Feature for the most basic properties that these objects have.

For 2D geometry, most objects are derived from Part::Part2DObject (itself derived from Part::Feature) which is the base of Sketches, and most Draft elements. See Part Part2DObject for the most basic properties that these objects have.

Actions

Actions in the property view were implemented in 0.19.

Right clicking in an empty space of the view, or with a property selected, shows only one command:

  • Show all: if active, in addition to the standard properties that appear already, it shows all the hidden Data and View properties in their respective tabs.
    • Data: "Proxy", "Label2", "Expression Engine", and "Visibility".
    • View: "Proxy".

When the Show all option is active, and one property is selected, more actions are available with a second right click:

  • Show all: deactivates the Show all command, hiding the additional Data and View properties.
  • Add Property: adds a dynamic property to the object; this works with both C++ defined objects, and Python scripted objects.
  • Expression: brings up the formula editor, which allows using expressions in the property value.
  • Hidden: if active, sets the property as hidden, meaning that it will only be displayed if Show all is active.
  • Output: if active, sets the property as output.
  • NoRecompute: if active, sets the property as not recomputed when the document is recomputed; this is useful when a property should be kept unaffected by other updates.
  • ReadOnly: if active, sets the property to be read-only; it won't be editable any more until this switch is turned off.
  • Transient: if active, sets the property as transient.
  • Touched: if active, it becomes touched, and ready for recompute.
  • EvalOnRestore: if active, it is evaluated when the document is restored.

零件对象属性的相关示例

属性

In this section we show some common properties that are visible for a PartDesign Body, and one PartDesign Feature. The specific properties of an object can found in the specific documentation page of that object.

视图

Most of these properties are inherited from the Part Feature basic object.

FreeCAD Property editor View.png

基本信息

  • View包围盒(Bounding Box) : 指示是否显示对象的最小外接立方体值可为False, 或True (默认值为False)。
  • View控制点(Control Point) : 指示是否显示特征控制点。值可为False, 或True (默认值为False)。
  • View偏差(Deviation) : 设置3D视图中模型多边形表示法(polygonal representation)的精准度(曲面细分)。较小的数值 = 更高的渲染质量。此值按对象大小的百分比来计算(以mm表示的偏差 = (w+h+d)/3*valueInPercent/100, 其中w,h,d分别为包围盒的维度)。
  • View显示模式(Display Mode) :对象的显示模式,平直线(Flat lines), 着色(Shaded), 线框(Wireframe), 点(Points) Vue DisplayModePartDesign fr 00.png。 (默认值, 平直线)。
  • View光照(Lighting) : 光照单侧(One side), 两侧(Two side) Vue Lighting fr 00.png. (默认值,两侧)。
  • View线段颜色(Line Color) : 指定线段(边)的颜色(默认值, 25, 25, 25)。
  • View线段宽度(Line Width) : 指定线段(边)的粗细(默认值, 2)。
  • View点的颜色(Point Color) : 指定点(端点)的颜色(默认值, 25, 25, 25)。
  • View点的大小(Point Size) : 指定点的大小(默认值, 2)。
  • View可选择性(Selectable) : 对象是否可以被选中。值为False或True (默认值, True)。
  • View几何形状的颜色(Shape Color) : 指定带有颜色的几何形状(默认值, 204, 204, 204)。
  • View透明度(Transparency) : 设置对象的透明度,取值范围为0 to 100 (默认值, 0)。
  • View可见性(Visibility) : 确定对象的可见性(如同SPACE键的效果)。取值为False或True (默认值, True)。

数据

In this case we observe the properties of the PartDesign Revolution feature.

FreeCAD Property editor Data.png

基本信息

Data标签(Label) : 此标签是为目标对象(特征)指定的名称,此名可按需更改。

Part Design

  • DataRefine: whether to refine the fusion done with other objects.

Revolution

  • DataBase: the point in space that specifies where the revolution takes place. It cannot be modified directly, only when editing the feature.
  • DataAxis: the axis around which the revolution will be performed. It cannot be modified directly, only when editing the feature.
  • DataAngle: the angle that specifies how much of the base element is rotated. By default it is 360 deg, but it can be any fraction of that.

Sketch Based

Data位置(Position) : 本属性指定了与目标对象所有维度有关的基点。此属性取3个参数,通过工具中的x、y、z输入框来传递对应数值。为一个以上的输入框设置同一值,将导致零件在对应坐标轴上按设置的数值移动相应数量的单位。


Scripting

See also: FreeCAD Scripting Basics.

See scripted objects for the full information on adding properties to objects defined through Python.

Most properties that are visible in the property editor can be accessed from the Python console. These properties are just attributes of the class that defines the selected object. For example, if the property editor shows the DataGroup property, this means that the object has the Group attribute.

print(obj.Group)

These attributes (properties) are added with the addProperty method of the base object. At least it is necessary to specify the type of property, and its name.

obj.addProperty("App::PropertyFloat", "Custom")
print(obj.Custom)

Properties follow the CapitalCamelCase or PascalCase convention, meaning that each word starts with a capital letter, and there are no underscores. When the property editor displays such names, it leaves a space between each capital letter, making it easier to read.

obj.addProperty("App::PropertyDistance", "CustomCamelProperty")
obj.CustomCamelProperty = 1000
print(obj.CustomCamelProperty)

FreeCAD Property editor Custom.png

Property editor showing the Data properties of a PartDesign Body, with two additional properties, "Custom" and "Custom Camel Property".


In similar way the View properties are added, not to the base object, but to its ViewObject. Then, it follows that properties like ViewAngular Deflection, ViewBounding Box, ViewDisplay Mode, ViewDisplay Mode Body, ViewLine Color, and others, can be examined and changed from the Python console.

print(obj.ViewObject.AngularDeflection)
print(obj.ViewObject.BoundingBox)
print(obj.ViewObject.DisplayMode)
print(obj.ViewObject.DisplayModeBody)
print(obj.ViewObject.LineColor)

All public properties of the object, and of its view provider, are contained in the corresponding PropertiesList attribute.

print(obj.PropertiesList)
print(obj.ViewObject.PropertiesList)

Template:Interface navi/zh-cn Template:Std Base navi/zh-cn