Sketcher SketchObject: Difference between revisions

From FreeCAD Documentation
(The Sketcher::SketchObject class is specialized for 2D shapes, and additionally it includes an extension to handle geometrical constraints of its elements.)
(Improved "Properties" information)
Line 47: Line 47:


<!--T:11-->
<!--T:11-->
In addition to the properties described in [[Part_Part2DObject|Part Part2DObject]], the basic Sketcher SketchObject has the following properties in the [[property editor|property editor]].
In addition to the properties described in [[Part_Part2DObject|Part Part2DObject]], the basic Sketcher SketchObject 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:12-->
=== Data === <!--T:12-->
Line 53: Line 53:
<!--T:13-->
<!--T:13-->
{{TitleProperty|Attachment}}
{{TitleProperty|Attachment}}
* {{PropertyData|Map Mode}}: same as [[Part_Part2DObject|Part Part2DObject]]. See [[Part Attachment|Part Attachment]] for more information on all attachment mapping modes.
* {{PropertyData|Map Mode}}, {{PropertyData|Map Reversed}}, {{PropertyData|Attachment Offset}}: same as [[Part_Part2DObject|Part Part2DObject]]. See [[Part Attachment|Part Attachment]] for more information on all attachment mapping modes.


<!--T:14-->
<!--T:14-->
{{TitleProperty|Sketch}}
{{TitleProperty|Sketch}}
* {{PropertyData|Constraints}}: named constraints, if they exist; otherwise it is an empty list {{incode|[]}}.
* {{PropertyData|Constraints|}}: named constraints, if they exist; otherwise it is an empty list {{incode|[]}}.

==== Hidden properties Data ====

See [[Part_Part2DObject|Part Part2DObject]] for the rest of the hidden properties.

{{TitleProperty|Base}}

* {{PropertyData|Proxy|PythonObject}}: a custom class associated with this object. This only exists for the [[Python|Python]] version. See [[Sketcher_SketchObject#Scripting|Scripting]].

{{TitleProperty|Sketch}}

* {{PropertyData|Geometry|GeometryList}}: a list of Part geometries that exist inside the sketch.
* {{PropertyData|External Geometry|LinkSubList}}: a list of Part geometries outside this Sketch that are used for reference.


=== View === <!--T:15-->
=== View === <!--T:15-->
Line 63: Line 76:
<!--T:16-->
<!--T:16-->
{{TitleProperty|Auto Constraints}}
{{TitleProperty|Auto Constraints}}
* {{PropertyView|Autoconstraints}}: if {{TRUE}} it will try setting constraints when the geometry is drawn.
* {{PropertyView|Autoconstraints|Bool}}: if {{TRUE}} it will try setting constraints when the geometry is drawn.


<!--T:17-->
<!--T:17-->
{{TitleProperty|Visibility automation}}
{{TitleProperty|Visibility automation}}
* {{PropertyView|Editing Workbench}}: normally {{incode|SketcherWorkbench}}, it is the name of the workbench to activate when editing the sketch.
* {{PropertyView|Editing Workbench|String}}: name of the workbench to activate when editing the sketch; it defaults to {{value|SketcherWorkbench}}.
* {{PropertyView|Hide Dependent}}: if {{TRUE}} all objects that depend on the sketch are hidden when opening the sketch.
* {{PropertyView|Hide Dependent|Bool}}: if {{TRUE}} all objects that depend on the sketch are hidden when opening the sketch.
* {{PropertyView|Restore Camera}}: if {{TRUE}} the camera position is saved before opening the sketch, and is restored after closing it.
* {{PropertyView|Restore Camera|Bool}}: if {{TRUE}} the camera position is saved before opening the sketch, and is restored after closing it.
* {{PropertyView|Show Links}}: if {{TRUE}} all objects used in links to external geometry are shown when opening the sketch.
* {{PropertyView|Show Links|Bool}}: if {{TRUE}} all objects used in links to external geometry are shown when opening the sketch.
* {{PropertyView|Show Support}}: if {{TRUE}} all objects this sketch is attached to are shown when opening the sketch.
* {{PropertyView|Show Support|Bool}}: if {{TRUE}} all objects this sketch is attached to are shown when opening the sketch.

==== Hidden properties View ====

{{TitleProperty|Base}}

* {{PropertyView|Proxy|PythonObject}}: a custom view provider class associated with this object. This only exists for the [[Python|Python]] version. See [[Sketcher_SketchObject#Scripting|Scripting]].

{{TitleProperty|Visibility automation}}

* {{PropertyView|Tempo Vis|PythonObject}}: a custom class associated with this object, that handles hiding and showing other objects when opening and closing the sketch.

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


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

Revision as of 05:08, 18 January 2020

Introduction

A Sketcher SketchObject, or formally a Sketcher::SketchObject, is the base element to create 2D objects with the Sketcher Workbench.

The Sketcher::SketchObject is derived from Part Part2DObject, which means it is a Part Feature object specialized for 2D geometry. Like Part2DObject, the SketchObject can be attached to planes and faces. In addition, the SketchObject can handle geometrical constraints of the lines and curves that are drawn within it.

Simplified diagram of the relationships between the core objects in FreeCAD. The Sketcher::SketchObject class is specialized for 2D shapes, and additionally it includes an extension to handle geometrical constraints of its elements.

How to use

  1. Switch to the Sketcher Workbench.
  2. Press Sketcher NewSketch.
  3. Select a Sketch orientation: XY-plane, XZ-plane, or YZ-plane. Optionally also choose Reverse direction, and give an Offset value.
  4. Press OK.

Although the SketchObject can be used by itself to draw on a plane, it is most commonly used in conjunction with the PartDesign Workbench to create extruded solids.

  1. Switch to the PartDesign Workbench.
  2. Press PartDesign Body.
  3. Press PartDesign NewSketch.
  4. Select feature: XY_Plane (Base plane), XZ_Plane (Base plane), or YZ_Plane (Base plane).
  5. Press OK.

Properties

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

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

In addition to the properties described in Part Part2DObject, the basic Sketcher SketchObject 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

Sketch

  • DataConstraints: named constraints, if they exist; otherwise it is an empty list [].

Hidden properties Data

See Part Part2DObject for the rest of the hidden properties.

Base

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

Sketch

  • DataGeometry (GeometryList): a list of Part geometries that exist inside the sketch.
  • DataExternal Geometry (LinkSubList): a list of Part geometries outside this Sketch that are used for reference.

View

Auto Constraints

  • ViewAutoconstraints (Bool): if true it will try setting constraints when the geometry is drawn.

Visibility automation

  • ViewEditing Workbench (String): name of the workbench to activate when editing the sketch; it defaults to SketcherWorkbench.
  • ViewHide Dependent (Bool): if true all objects that depend on the sketch are hidden when opening the sketch.
  • ViewRestore Camera (Bool): if true the camera position is saved before opening the sketch, and is restored after closing it.
  • ViewShow Links (Bool): if true all objects used in links to external geometry are shown when opening the sketch.
  • ViewShow Support (Bool): if true all objects this sketch is attached to are shown when opening the sketch.

Hidden properties View

Base

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

Visibility automation

  • ViewTempo Vis (PythonObject): a custom class associated with this object, that handles hiding and showing other objects when opening and closing the sketch.

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.

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

import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("Sketcher::SketchObject", "Sketch")
obj.Label = "Custom label"

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

Therefore, for Python subclassing, you should create the Sketcher::SketchObjectPython object.

import FreeCAD as App

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