Part TopoShape: Difference between revisions

From FreeCAD Documentation
(Some of the most important objects with Part TopoShape are the following: Part, PartDesign_Body, Part_Part2DObject, Sketcher_SketchObject.)
mNo edit summary
 
(13 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{TOCright}}
<translate>
<translate>


Line 8: Line 9:


<!--T:3-->
<!--T:3-->
The topological shapes, as well as their methods, are defined by the OpenCASCADE Technology kernel (OCCT). FreeCAD uses these shapes, and builds [[App_DocumentObject|App DocumentObjects]] around them.
The topological shapes, as well as their methods, are defined by the [[OpenCASCADE|OpenCASCADE Technology]] kernel (OCCT). FreeCAD uses these shapes, and builds [[App_DocumentObject|App DocumentObjects]] around them.

<!--T:18-->
Another type of class is that of [[Mesh|meshes]]; this class is not very parametric because it can't be redefined easily except by specifying individual vertices and triangular surfaces.

<!--T:19-->
[[File:Shape_and_mesh.svg]]

<!--T:20-->
{{Caption|Left: parametric [[Part_TopoShape|Part TopoShape]] defined by properties. Right: non-parametric [[Mesh|mesh]], defined by vertices and triangular surfaces.}}


<!--T:4-->
<!--T:4-->
Line 16: Line 26:
{{Caption|Simplified diagram of the relationships between the core objects in the program. The {{incode|Part::TopoShape}} class is embedded in the {{incode|Part::Feature}} object and from there it is propagated to all objects that are derived from it.}}
{{Caption|Simplified diagram of the relationships between the core objects in the program. The {{incode|Part::TopoShape}} class is embedded in the {{incode|Part::Feature}} object and from there it is propagated to all objects that are derived from it.}}


== How to use == <!--T:6-->
==Usage== <!--T:6-->


<!--T:7-->
<!--T:7-->
The Part TopoShape is an object that is assigned to some [[App_DocumentObject|App DocumentObjects]].
The Part TopoShape is an object that is assigned to some [[App_DocumentObject|App DocumentObjects]].


<!--T:9-->
In particular, the basic object that handles these types of attributes is the [[Part_Feature|Part Feature]] ({{incode|Part::Feature}} class). All objects derived from this class will have access to a Part TopoShape.
In particular, the basic object that handles these types of attributes is the [[Part_Feature|Part Feature]] ({{incode|Part::Feature}} class). All objects derived from this class will have access to a Part TopoShape.


<!--T:10-->
Some of the most important objects with Part TopoShape are the following:
Some of the most important objects with Part TopoShape are the following:
* Any primitive solid created with the [[Part_Workbench|Part Workbench]].
* Any primitive solid created with the [[Part_Workbench|Part Workbench]].
Line 28: Line 40:
* Any object derived from [[Part_Part2DObject|Part Part2DObject]], like most objects created with the [[Draft_Workbench|Draft Workbench]].
* Any object derived from [[Part_Part2DObject|Part Part2DObject]], like most objects created with the [[Draft_Workbench|Draft Workbench]].
* Any [[Sketch|sketch]], that is, [[Sketcher_SketchObject|Sketcher SketchObject]], created with the [[Sketcher_Workbench|Sketcher Workbench]].
* Any [[Sketch|sketch]], that is, [[Sketcher_SketchObject|Sketcher SketchObject]], created with the [[Sketcher_Workbench|Sketcher Workbench]].
* Any object created by importing a STEP, BREP, and similar solid format files.

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

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

<!--T:13-->
All objects derived from {{incode|Part::Feature}} will have a [[Part TopoShape|Part TopoShape]], which is normally accessible from its {{incode|Shape}} attribute.
</translate>
{{Code|code=
import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("Part::Box", "Box")
print(obj.Shape)
}}
<translate>

<!--T:14-->
A TopoShape has many attributes (variables) and methods that contain information about it, and which allow doing operations with it. These variables and methods can be tested in the [[Python_console|Python console]].
</translate>
{{Code|code=
print(obj.Shape.Area)
print(obj.Shape.BoundBox)
print(obj.Shape.CenterOfMass)
print(obj.Shape.ShapeType)

obj.Shape.check()
obj.Shape.copy()
obj.Shape.exportStep("my_file.step")
obj.Shape.exportStl("my_file.stl")
}}
<translate>

<!--T:15-->
For a full list of attributes and methods, consult the [[Source_documentation|source documentation]], and the {{Button|[[File:Std PythonHelp.svg|16px]] [[Std_PythonHelp|Std PythonHelp]]}} tool.

<!--T:21-->
You can obtain a quick summary of all methods using Python's built-in {{incode|help()}} function.
</translate>
{{Code|code=
help(obj.Shape)
}}
<translate>



<!--T:8-->
{{Part Tools navi}}
{{Userdocnavi}}
</translate>
</translate>
{{Part Tools navi{{#translation:}}}}
{{Document objects navi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}

Latest revision as of 11:40, 13 November 2021

Introduction

A Part TopoShape, or formally a Part::TopoShape, is a class that defines a parametric topological shape in the software. Objects in the document that show something in the 3D view normally have a TopoShape.

The topological shapes, as well as their methods, are defined by the OpenCASCADE Technology kernel (OCCT). FreeCAD uses these shapes, and builds App DocumentObjects around them.

Another type of class is that of meshes; this class is not very parametric because it can't be redefined easily except by specifying individual vertices and triangular surfaces.

Left: parametric Part TopoShape defined by properties. Right: non-parametric mesh, defined by vertices and triangular surfaces.

Simplified diagram of the relationships between the core objects in the program. The Part::TopoShape class is embedded in the Part::Feature object and from there it is propagated to all objects that are derived from it.

Usage

The Part TopoShape is an object that is assigned to some App DocumentObjects.

In particular, the basic object that handles these types of attributes is the Part Feature (Part::Feature class). All objects derived from this class will have access to a Part TopoShape.

Some of the most important objects with Part TopoShape are the following:

Scripting

See also: FreeCAD Scripting Basics, and scripted objects.

All objects derived from Part::Feature will have a Part TopoShape, which is normally accessible from its Shape attribute.

import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("Part::Box", "Box")
print(obj.Shape)

A TopoShape has many attributes (variables) and methods that contain information about it, and which allow doing operations with it. These variables and methods can be tested in the Python console.

print(obj.Shape.Area)
print(obj.Shape.BoundBox)
print(obj.Shape.CenterOfMass)
print(obj.Shape.ShapeType)

obj.Shape.check()
obj.Shape.copy()
obj.Shape.exportStep("my_file.step")
obj.Shape.exportStl("my_file.stl")

For a full list of attributes and methods, consult the source documentation, and the Std PythonHelp tool.

You can obtain a quick summary of all methods using Python's built-in help() function.

help(obj.Shape)