freecad-cam/Mod/Draft/draftviewproviders
2026-02-01 01:59:24 +01:00
..
__pycache__ init 2026-02-01 01:59:24 +01:00
__init__.py init 2026-02-01 01:59:24 +01:00
README.md init 2026-02-01 01:59:24 +01:00
view_array.py init 2026-02-01 01:59:24 +01:00
view_base.py init 2026-02-01 01:59:24 +01:00
view_bezcurve.py init 2026-02-01 01:59:24 +01:00
view_bspline.py init 2026-02-01 01:59:24 +01:00
view_circulararray.py init 2026-02-01 01:59:24 +01:00
view_clone.py init 2026-02-01 01:59:24 +01:00
view_dimension.py init 2026-02-01 01:59:24 +01:00
view_draft_annotation.py init 2026-02-01 01:59:24 +01:00
view_draftlink.py init 2026-02-01 01:59:24 +01:00
view_facebinder.py init 2026-02-01 01:59:24 +01:00
view_fillet.py init 2026-02-01 01:59:24 +01:00
view_hatch.py init 2026-02-01 01:59:24 +01:00
view_label.py init 2026-02-01 01:59:24 +01:00
view_layer.py init 2026-02-01 01:59:24 +01:00
view_orthoarray.py init 2026-02-01 01:59:24 +01:00
view_point.py init 2026-02-01 01:59:24 +01:00
view_polararray.py init 2026-02-01 01:59:24 +01:00
view_rectangle.py init 2026-02-01 01:59:24 +01:00
view_shapestring.py init 2026-02-01 01:59:24 +01:00
view_text.py init 2026-02-01 01:59:24 +01:00
view_wire.py init 2026-02-01 01:59:24 +01:00
view_wpproxy.py init 2026-02-01 01:59:24 +01:00

2020 May

These files define the viewprovider classes for "scripted objects" defined within the workbench. The corresponding proxy object classes should be defined in the modules in draftobjects/.

Each scripted object has a creation function like make_rectangle, a proxy class like Rectangle, and a viewprovider class like ViewProviderRectangle. The view providers define how they are displayed in the tree view and in the 3D view, that is, visual properties such as line thickness, line color, face color, and transparency. These properties are only available when the graphical interface is loaded; in a console only session, these properties cannot be read nor set. These properties aren't very "real" because they don't affect the actual geometrical shape of the object. Each make function in draftmake/ should import its corresponding viewprovider from this package in order to set the visual properties of the new scripted object, as long the graphical interface is available.

These classes were previously defined in the Draft.py module, which was very large. Now Draft.py is an auxiliary module which just loads the individual classes in order to provide backwards compatibility for older files. Other workbenches can import these classes for their own use, including creating derived classes.

import Draft

new_obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", "New")

if App.GuiUp:
    Draft.ViewProviderRectangle(new_obj.ViewObject)


# Subclass
class NewViewProvider(Draft.ViewProviderRectangle):
   ...

As the scripted objects are rebuilt every time a document is loaded, this means that, in general, these modules cannot be renamed without risking breaking previously saved files. They can be renamed only if the old class can be migrated to point to a new class, for example, by creating a reference to the new class named the same as the older class.

For more information see the thread: [Discussion] Splitting Draft tools into their own modules