24
"""Modules that contain functions to create custom scripted objects.
26
These functions represent the basic application programming interface (API)
27
of the Draft Workbench to create custom objects.
29
These functions first create a simple, extensible object defined in C++,
30
for example, `Part::FeaturePython` or `Part::Part2DObjectPython`,
31
and then assign a custom proxy class to define its data properties,
32
and a custom viewprovider class to define its visual properties.
34
The proxy class is imported from `draftobjects` and the corresponding
35
viewprovider from `draftviewproviders`.
40
import draftobjects.my_obj as my_obj
41
import draftviewproviders.view_my_obj as view_my_obj
43
def make_function(input_data):
44
doc = App.ActiveDocument
45
new_obj = doc.addObject("Part::Part2DObjectPython",
50
view_my_obj.ViewProviderObj(new_obj.ViewObject)
54
Assigning the viewprovider class is only possible if the graphical interface
55
is available. In a terminal-only session the viewproviders are not accessible
56
because the `ViewObject` attribute does not exist.
58
If an object is created and saved in a console-only session,
59
the object will not have the custom viewprovider when the file is opened
60
in the GUI version of the program; it will only have a basic viewprovider
61
associated to the base C++ object.
63
If needed, the custom viewprovider can be assigned after opening
64
the GUI version of the program; then the object will have access
65
to additional visual properties.
70
Draft.ViewProviderDraft(new_obj.ViewObject)
72
Most Draft objects are based on two base `Part` objects
73
that are able to handle a `Part::TopoShape`.
75
- `Part::Part2DObjectPython` if they should handle only 2D shapes, and
76
- `Part::FeaturePython` if they should handle any type of shape (2D or 3D).
78
Generic objects that don't need to handle shapes but which
79
can have other properties like `App::PropertyPlacement`,
80
or which can interact with the 3D view through Coin,
81
can be based on the simple `App::FeaturePython` object.