Part Part2DObject: Difference between revisions

From FreeCAD Documentation
(→‎Introduction: New image File:Tree_Part2D.svg)
(Part_Attachment -> Part_EditAttachment)
(37 intermediate revisions by 4 users not shown)
Line 2: Line 2:
<translate>
<translate>


== Introduction ==
== Introduction == <!--T:1-->


</translate>
A [[Part Part2DObject|Part Part2DObject]], or formally a {{incode|Part::Part2DObject}}, is a simple element with a topological {{incode|Shape}} associated that can be displayed in the [[3D view|3D view]].
[[File:Tree_Part2D.svg|32px]]
<translate>


<!--T:2-->
The {{incode|Part::Part2DObject}} is derived from a [[Part Feature|{{incode|Part::Feature}}]], but is specialized for 2D geometry, given that its shape will lie on a plane. This plane is defined by its {{PropertyData|Placement}} property (position, normal, and rotation). However, the plane can also be defined by supporting geometrical elements, such as the plane created by three arbitrary vertices, or a face of a solid body.
A [[Part Part2DObject|Part Part2DObject]], or formally a {{incode|Part::Part2DObject}}, is a simple element with a [[Part_TopoShape|topological shape]] associated that can be displayed in the [[3D view|3D view]].


<!--T:3-->
The {{incode|Part::Part2DObject}} is defined in the [[Part Workbench|Part Workbench]] but can be used as the base class for [[scripted objects|scripted objects]] in all [[Workbenches|workbenches]] that produce 2D geometrical shapes. For example, it is the base object for sketches ({{incode|Sketcher::SketchObject}}) in the [[Sketcher Workbench|Sketcher Workbench]], and for most objects created in the [[Draft Workbench|Draft Workbench]].
The {{incode|Part::Part2DObject}} is derived from a [[Part Feature|Part Feature]], but is specialized for 2D geometry, given that its shape will lie on a plane. This plane is defined by its {{PropertyData|Placement}} property (position, normal, and rotation). However, the plane can also be defined by supporting geometrical elements, such as the plane created by three arbitrary vertices, or a face of a solid body.


<!--T:24-->
Workbenches can add more properties to this basic element to produce an object with complex behavior.
[[File:FreeCAD_core_objects.svg|800px]]


<!--T:25-->
[[File:Tree_Part2D.svg|32px]]
{{Caption|Simplified diagram of the relationships between the core objects in the program. The {{incode|Part::Part2DObject}} class is specialized for 2D shapes, so it is the base class for planar objects created with the Draft and Sketcher workbenches. It includes an extension that allows it to be attached to faces and planes.}}


==Usage== <!--T:20-->
== Properties ==


<!--T:21-->
The [[Part Part2DObject|Part Part2DObject]] is an internal object, so it cannot be created from the graphical interface, only from the [[Python console|Python console]] as described in the [[Part_Part2DObject#Scripting|Scripting]] section.

<!--T:4-->
The {{incode|Part::Part2DObject}} is defined in the [[Part Workbench|Part Workbench]] but can be used as the base class for [[scripted objects|scripted objects]] in all [[Workbenches|workbenches]] that produce 2D geometrical shapes. For example, it is the base object for sketches ([[Sketcher_SketchObject|Sketcher SketchObject]]), and for most objects created with the [[Draft Workbench|Draft Workbench]].

<!--T:5-->
Workbenches can add more properties to this basic element to produce an object with complex behavior.

== Properties == <!--T:7-->

<!--T:8-->
See [[Property|Property]] for all property types that scripted objects can have.
See [[Property|Property]] for all property types that scripted objects can have.


<!--T:22-->
In addition to the properties described in [[Part Feature|Part Feature]], the Part Part2DObject has the following properties in the [[property editor|property editor]].
A [[Part_Part2DObject|Part Part2DObject]] ({{incode|Part::Part2DObject}} class) is derived from a [[Part_Feature|Part Feature]] ({{incode|Part::Feature}} class), therefore it shares all the latter's properties.


<!--T:9-->
=== Data ===
In addition to the properties described in [[Part Feature|Part Feature]], the Part Part2DObject has the following properties in the [[property editor|property editor]]. Hidden properties can be shown by using the {{MenuCommand|Show all}} command in the context menu of the [[property editor|property editor]].


=== Data === <!--T:10-->

<!--T:11-->
{{TitleProperty|Attachment}}
{{TitleProperty|Attachment}}
* {{PropertyData|Map Mode}}: "Deactivated" by default. This property determines a plane which the object will use as reference for 2D geometry. Clicking on the ellipsis (three dots), to the right of the entry field opens the [[Part Attachment|Part Attachment]] [[task panel|task panel]] that allows selecting the supporting plane by picking different elements in the [[3D view|3D view]]. The different modes are: Deactivated, Translate origin, Object's XY, Object's XZ, Object's YZ, Plane face, Tangent to surface, Normal to edge, Frenet NB, Frenet TN, Frenet TB, Concentric, Revolution section, Plane by 3 points, Normal to 3 points, Folding, Inertia 2-3, Align O-N-X, Align O-N-Y, Align O-X-Y, Align O-X-N, Align O-Y-N, Align O-Y-X. See [[Part Attachment|Part Attachment]] for more information on all mapping modes.
* {{PropertyData|Map Mode|Enumeration}}: {{value|Deactivated}} by default. This property determines a plane which the object will use as reference for 2D geometry. Clicking on the ellipsis {{KEY|...}} (three dots), to the right of the entry field opens the [[Part_EditAttachment|Part EditAttachment]] [[task panel|task panel]] that allows selecting the supporting plane by picking different elements in the [[3D view|3D view]]. The different modes are: {{value|Deactivated}}, {{value|Translate origin}}, {{value|Object's XY}}, {{value|Object's XZ}}, {{value|Object's YZ}}, {{value|Plane face}}, {{value|Tangent to surface}}, {{value|Normal to edge}}, {{value|Frenet NB}}, {{value|Frenet TN}}, {{value|Frenet TB}}, {{value|Concentric}}, {{value|Revolution section}}, {{value|Plane by 3 points}}, {{value|Normal to 3 points}}, {{value|Folding}}, {{value|Inertia 2-3}}, {{value|Align O-N-X}}, {{value|Align O-N-Y}}, {{value|Align O-X-Y}}, {{value|Align O-X-N}}, {{value|Align O-Y-N}}, {{value|Align O-Y-X}}.


<!--T:23-->
=== View ===
See [[Part_EditAttachment|Part EditAttachment]] for more information on all mapping modes.


<!--T:31-->
The following two properties are normally hidden. They become visible once {{PropertyData|Map Mode}} is something other than {{value|Deactivated}}.
* {{PropertyData|Map Reversed|Bool}}: it defaults to {{FALSE}}; if it is {{TRUE}} the Z direction will be reversed. For example, a [[sketch|sketch]] will be flipped upside down.
* {{PropertyData|Attachment Offset|Placement}}: the position of the object in the [[3D view|3D view]], with respect to the attachment object's placement. The placement is defined by a {{incode|Base}} point (vector), and a {{incode|Rotation}} (axis and angle). See [[Placement|Placement]].

==== Hidden properties Data ==== <!--T:26-->

<!--T:35-->
{{TitleProperty|Base}}

<!--T:36-->
* {{PropertyData|Proxy|PythonObject}}: a custom class associated with this object. This only exists for the [[Python|Python]] version. See [[Part_Part2DObject#Scripting|Scripting]].

<!--T:27-->
{{TitleProperty|Attachment}}

<!--T:28-->
* {{PropertyData|Attacher Type|String}}: class name of the attach engine object driving the attachment. It defaults to {{incode|Attacher::AttachEnginePlane}}.
* {{PropertyData|Support|LinkSubList}}: it is the plane or face supporting the 2D geometry. It defaults to an empty list {{incode|[]}}.
* {{PropertyData|Map Path Parameter|Float}}: sets point of curve to map a [[sketch|sketch]] to. It goes from {{value|0}} to {{value|1}}, which corresponds to the {{value|start}} and {{value|end}}. It defaults to {{value|0}}.

=== View === <!--T:12-->

<!--T:13-->
{{TitleProperty|Grid}}
{{TitleProperty|Grid}}
* {{PropertyView|Grid Size}}: a float that determines the size of the spacing of the local grid lines in the [[3D view|3D view]].
* {{PropertyView|Grid Size|Length}}: the size of the spacing of the local grid lines in the [[3D view|3D view]]; it defaults to {{value|10 mm}}.
* {{PropertyView|Grid Snap}}: if {{TRUE}} the grid can be used to snap points.
* {{PropertyView|Grid Snap|Bool}}: it defaults to {{FALSE}}; if {{TRUE}} the grid can be used to snap points.
* {{PropertyView|Grid Style}}: Dashed or Light; the style of the grid lines.
* {{PropertyView|Grid Style|Enumeration}}: the style of the grid lines; {{value|Dashed}} (default) or {{value|Light}}.
* {{PropertyView|Show Grid}}: if {{TRUE}} a grid local to the object will be displayed in the [[3D view|3D view]]. This grid is independent of the [[Draft_ToggleGrid|Draft grid]].
* {{PropertyView|Show Grid|Bool}}: it defaults to {{FALSE}}; if {{TRUE}} a grid local to the object will be displayed in the [[3D view|3D view]]. This grid is independent of the [[Draft_ToggleGrid|Draft Grid]].
* {{PropertyView|Tight Grid}}: if {{TRUE}} the local grid will be localized around the origin of the shape, otherwise it will extend itself more.
* {{PropertyView|Tight Grid|Bool}}: if {{TRUE}} (default) the local grid will be localized around the origin of the shape, otherwise it will extend itself more.


==== Hidden properties View ==== <!--T:29-->
== Scripting ==


<!--T:37-->
{{TitleProperty|Base}}

<!--T:38-->
* {{PropertyView|Proxy|PythonObject}}: a custom view provider class associated with this object. This only exists for the [[Python|Python]] version. See [[Part_Part2DObject#Scripting|Scripting]].

<!--T:30-->
All other view properties, including hidden properties, are those of the base [[Part_Feature|Part Feature]] object.

== Scripting == <!--T:14-->

<!--T:15-->
{{Emphasis|See also:}} [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]], and [[scripted objects|scripted objects]].
{{Emphasis|See also:}} [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]], and [[scripted objects|scripted objects]].


<!--T:16-->
See [[Part_Feature|Part Feature]] for the general information.
See [[Part_Feature|Part Feature]] for the general information on adding objects to the document.


<!--T:17-->
A Part Part2DObject is created with the {{incode|addObject()}} method of the document.
A Part2DObject is created with the {{incode|addObject()}} method of the document.
</translate>
{{Code|code=
{{Code|code=
import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("Part::Part2DObject", "Name")
obj = App.ActiveDocument.addObject("Part::Part2DObject", "Name")
obj.Label = "Custom label"
obj.Label = "Custom label"
}}
}}
<translate>

<!--T:32-->
This basic {{incode|Part::Part2DObject}} doesn't have a Proxy object so it can't be fully used for sub-classing.

<!--T:33-->
Therefore, for [[Python|Python]] subclassing, you should create the {{incode|Part::Part2DObjectPython}} object.

</translate>
{{Code|code=
import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", "Name")
obj.Label = "Custom label"
}}
<translate>

<!--T:34-->
For example, most tools from the [[Draft_Workbench|Draft Workbench]], like [[Draft_Line|Draft Line]], [[Draft_Rectangle|Draft Rectangle]], [[Draft_Polygon|Draft Polygon]], etc., are {{incode|Part::Part2DObjectPython}} objects with a custom icon and additional properties.


{{Part Tools navi}}
{{Userdocnavi}}
</translate>
</translate>
{{Part Tools navi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
{{clear}}

Revision as of 08:35, 3 September 2021

Introduction

A Part Part2DObject, or formally a Part::Part2DObject, is a simple element with a topological shape associated that can be displayed in the 3D view.

The Part::Part2DObject is derived from a Part Feature, but is specialized for 2D geometry, given that its shape will lie on a plane. This plane is defined by its DataPlacement property (position, normal, and rotation). However, the plane can also be defined by supporting geometrical elements, such as the plane created by three arbitrary vertices, or a face of a solid body.

Simplified diagram of the relationships between the core objects in the program. The Part::Part2DObject class is specialized for 2D shapes, so it is the base class for planar objects created with the Draft and Sketcher workbenches. It includes an extension that allows it to be attached to faces and planes.

Usage

The Part Part2DObject is an internal object, so it cannot be created from the graphical interface, only from the Python console as described in the Scripting section.

The Part::Part2DObject is defined in the Part Workbench but can be used as the base class for scripted objects in all workbenches that produce 2D geometrical shapes. For example, it is the base object for sketches (Sketcher SketchObject), and for most objects created with the Draft Workbench.

Workbenches can add more properties to this basic element to produce an object with complex behavior.

Properties

See Property for all property types that scripted objects can have.

A Part Part2DObject (Part::Part2DObject class) is derived from a Part Feature (Part::Feature class), therefore it shares all the latter's properties.

In addition to the properties described in Part Feature, the Part Part2DObject has the following properties in the property editor. Hidden properties can be shown by using the Show all command in the context menu of the property editor.

Data

Attachment

  • DataMap Mode (Enumeration): Deactivated by default. This property determines a plane which the object will use as reference for 2D geometry. Clicking on the ellipsis ... (three dots), to the right of the entry field opens the Part EditAttachment task panel that allows selecting the supporting plane by picking different elements in the 3D view. The different modes are: Deactivated, Translate origin, Object's XY, Object's XZ, Object's YZ, Plane face, Tangent to surface, Normal to edge, Frenet NB, Frenet TN, Frenet TB, Concentric, Revolution section, Plane by 3 points, Normal to 3 points, Folding, Inertia 2-3, Align O-N-X, Align O-N-Y, Align O-X-Y, Align O-X-N, Align O-Y-N, Align O-Y-X.

See Part EditAttachment for more information on all mapping modes.

The following two properties are normally hidden. They become visible once DataMap Mode is something other than Deactivated.

  • DataMap Reversed (Bool): it defaults to false; if it is true the Z direction will be reversed. For example, a sketch will be flipped upside down.
  • DataAttachment Offset (Placement): the position of the object in the 3D view, with respect to the attachment object's placement. The placement is defined by a Base point (vector), and a Rotation (axis and angle). See Placement.

Hidden properties Data

Base

  • DataProxy (PythonObject): a custom class associated with this object. This only exists for the Python version. See Scripting.

Attachment

  • DataAttacher Type (String): class name of the attach engine object driving the attachment. It defaults to Attacher::AttachEnginePlane.
  • DataSupport (LinkSubList): it is the plane or face supporting the 2D geometry. It defaults to an empty list [].
  • DataMap Path Parameter (Float): sets point of curve to map a sketch to. It goes from 0 to 1, which corresponds to the start and end. It defaults to 0.

View

Grid

  • ViewGrid Size (Length): the size of the spacing of the local grid lines in the 3D view; it defaults to 10 mm.
  • ViewGrid Snap (Bool): it defaults to false; if true the grid can be used to snap points.
  • ViewGrid Style (Enumeration): the style of the grid lines; Dashed (default) or Light.
  • ViewShow Grid (Bool): it defaults to false; if true a grid local to the object will be displayed in the 3D view. This grid is independent of the Draft Grid.
  • ViewTight Grid (Bool): if true (default) the local grid will be localized around the origin of the shape, otherwise it will extend itself more.

Hidden properties View

Base

  • ViewProxy (PythonObject): a custom view provider class associated with this object. This only exists for the Python version. See Scripting.

All other view properties, including hidden properties, are those of the base Part Feature object.

Scripting

See also: FreeCAD Scripting Basics, and scripted objects.

See Part Feature for the general information on adding objects to the document.

A Part2DObject is created with the addObject() method of the document.

import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("Part::Part2DObject", "Name")
obj.Label = "Custom label"

This basic Part::Part2DObject doesn't have a Proxy object so it can't be fully used for sub-classing.

Therefore, for Python subclassing, you should create the Part::Part2DObjectPython object.

import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", "Name")
obj.Label = "Custom label"

For example, most tools from the Draft Workbench, like Draft Line, Draft Rectangle, Draft Polygon, etc., are Part::Part2DObjectPython objects with a custom icon and additional properties.