draftutils.gui_utils Namespace Reference

Functions

def autogroup (obj)
 
def dim_dash (p1, p2)
 
def dim_symbol (symbol=None, invert=False)
 
def format_object (target, origin=None)
 
def get_3d_view ()
 
def get_selection (gui=App.GuiUp)
 
def get_selection_ex (gui=App.GuiUp)
 
def load_texture (filename, size=None, gui=App.GuiUp)
 
def remove_hidden (objectslist)
 
def select (objs=None, gui=App.GuiUp)
 

Variables

def dimDash = dim_dash
 
def dimSymbol = dim_symbol
 
def formatObject = format_object
 
def get3DView = get_3d_view
 
def getSelection = get_selection
 
def getSelectionEx = get_selection_ex
 
def loadTexture = load_texture
 
def removeHidden = remove_hidden
 

Function Documentation

◆ autogroup()

def draftutils.gui_utils.autogroup (   obj)
Add a given object to the defined Draft autogroup, if applicable.

This function only works if the graphical interface is available.
It checks that the `App.draftToolBar` class is available,
which contains the group to use to automatically store
new created objects.

Originally, it worked with standard groups (`App::DocumentObjectGroup`),
and Arch Workbench containers like `'Site'`, `'Building'`, `'Floor'`,
and `'BuildingPart'`.

Now it works with Draft Layers.

Parameters
----------
obj: App::DocumentObject
    Any type of object that will be stored in the group.

◆ dim_dash()

def draftutils.gui_utils.dim_dash (   p1,
  p2 
)
Return a SoSeparator with a line used to make dimension dashes.

It is used by `dim_symbol` to create line end symbols
like `'Tick-2'`, `'DimOvershoot'`, and `'ExtOvershoot'` dashes.

Parameters
----------
p1: tuple of three floats or Base::Vector3
    A point to define a line vertex.

p2: tuple of three floats or Base::Vector3
    A point to define a line vertex.

Returns
-------
Coin.SoSeparator
    A Coin object with a `SoLineSet` created from `p1` and `p2`
    as vertices.

◆ dim_symbol()

def draftutils.gui_utils.dim_symbol (   symbol = None,
  invert = False 
)
Return the specified dimension symbol.

Parameters
----------
symbol: int, optional
    It defaults to `None`, in which it gets the value from the parameter
    database, `get_param("dimsymbol", 0)`.

    A numerical value defines different markers
     * 0, `SoSphere`
     * 1, `SoMarkerSet` with a circle
     * 2, `SoSeparator` with a `soCone`
     * 3, `SoSeparator` with a `SoFaceSet`
     * 4, `SoSeparator` with a `SoLineSet`, calling `dim_dash`
     * Otherwise, `SoSphere`

invert: bool, optional
    It defaults to `False`.
    If it is `True` and `symbol=2`, the cone will be rotated
    -90 degrees around the Z axis, otherwise the rotation is positive,
    +90 degrees.

Returns
-------
Coin.SoNode
    A `Coin.SoSphere`, or `Coin.SoMarkerSet` (circle),
    or `Coin.SoSeparator` (cone, face, line)
    that will be used as a dimension symbol.

References draftutils.gui_utils.dimDash.

◆ format_object()

def draftutils.gui_utils.format_object (   target,
  origin = None 
)
Apply visual properties from the Draft toolbar or another object.

This function only works if the graphical interface is available
as the visual properties are attributes of the view provider
(`obj.ViewObject`).

Parameters
----------
target: App::DocumentObject
    Any type of scripted object.

    This object will adopt the applicable visual properties,
    `FontSize`, `TextColor`, `LineWidth`, `PointColor`, `LineColor`,
    and `ShapeColor`, defined in the Draft toolbar
    (`Gui.draftToolBar`) or will adopt
    the properties from the `origin` object.

    The `target` is also placed in the construction group
    if the construction mode in the Draft toolbar is active.

origin: App::DocumentObject, optional
    It defaults to `None`.
    If it exists, it will provide the visual properties to assign
    to `target`, with the exception of `BoundingBox`, `Proxy`,
    `RootNode` and `Visibility`.

◆ get_3d_view()

def draftutils.gui_utils.get_3d_view ( )
Return the current 3D view.

Returns
-------
Gui::View3DInventor
    Return the current `ActiveView` in the active document,
    or the first `Gui::View3DInventor` view found.

    Return `None` if the graphical interface is not available.

◆ get_selection()

def draftutils.gui_utils.get_selection (   gui = App.GuiUp)
Return the current selected objects.

This function only works if the graphical interface is available
as the selection module only works on the 3D view.

It wraps around `Gui.Selection.getSelection`

Parameters
----------
gui: bool, optional
    It defaults to the value of `App.GuiUp`, which is `True`
    when the interface exists, and `False` otherwise.

    This value can be set to `False` to simulate
    when the interface is not available.

Returns
-------
list of App::DocumentObject
    Returns a list of objects in the current selection.
    It can be an empty list if no object is selected.

    If the interface is not available, it returns `None`.

◆ get_selection_ex()

def draftutils.gui_utils.get_selection_ex (   gui = App.GuiUp)
Return the current selected objects together with their subelements.

This function only works if the graphical interface is available
as the selection module only works on the 3D view.

It wraps around `Gui.Selection.getSelectionEx`

Parameters
----------
gui: bool, optional
    It defaults to the value of `App.GuiUp`, which is `True`
    when the interface exists, and `False` otherwise.

    This value can be set to `False` to simulate
    when the interface is not available.

Returns
-------
list of Gui::SelectionObject
    Returns a list of `Gui::SelectionObject` in the current selection.
    It can be an empty list if no object is selected.

    If the interface is not available, it returns `None`.

Selection objects
-----------------
One `Gui::SelectionObject` has attributes that indicate which specific
subelements, that is, vertices, wires, and faces, were selected.
This can be useful to operate on the subelements themselves.
If `G` is a `Gui::SelectionObject`
 * `G.Object` is the selected object
 * `G.ObjectName` is the name of the selected object
 * `G.HasSubObjects` is `True` if there are subelements in the selection
 * `G.SubObjects` is a tuple of the subelements' shapes
 * `G.SubElementNames` is a tuple of the subelements' names

`SubObjects` and `SubElementNames` should be empty tuples
if `HasSubObjects` is `False`.

◆ load_texture()

def draftutils.gui_utils.load_texture (   filename,
  size = None,
  gui = App.GuiUp 
)
Return a Coin.SoSFImage to use as a texture for a 2D plane.

This function only works if the graphical interface is available
as the visual properties that can be applied to a shape
are attributes of the view provider (`obj.ViewObject`).

Parameters
----------
filename: str
    A path to a pixel image file (PNG) that can be used as a texture
    on the face of an object.

size: tuple of two int, or a single int, optional
    It defaults to `None`.
    If a tuple is given, the two values define the width and height
    in pixels to which the loaded image will be scaled.
    If it is a single value, it is used for both dimensions.

    If it is `None`, the size will be determined from the `QImage`
    created from `filename`.

    CURRENTLY the input `size` parameter IS NOT USED.
    It always uses the `QImage` to determine this information.

gui: bool, optional
    It defaults to the value of `App.GuiUp`, which is `True`
    when the interface exists, and `False` otherwise.

    This value can be set to `False` to simulate
    when the interface is not available.

Returns
-------
coin.SoSFImage
    An image object with the appropriate size, number of components
    (grayscale, grayscale and transparency, color,
    color and transparency), and byte data.

    It returns `None` if the interface is not available,
    or if there is a problem creating the image.

◆ remove_hidden()

def draftutils.gui_utils.remove_hidden (   objectslist)
Return only the visible objects in the list.

This function only works if the graphical interface is available
as the `Visibility` attribute is a property of the view provider
(`obj.ViewObject`).

Parameters
----------
objectslist: list of App::DocumentObject
    List of any type of object.

Returns
-------
list
    Return a copy of the input list without those objects
    for which `obj.ViewObject.Visibility` is `False`.

    If the graphical interface is not loaded
    the returned list is just a copy of the input list.

◆ select()

def draftutils.gui_utils.select (   objs = None,
  gui = App.GuiUp 
)
Unselects everything and selects only the given list of objects.

This function only works if the graphical interface is available
as the selection module only works on the 3D view.

Parameters
----------
objs: list of App::DocumentObject, optional
    It defaults to `None`.
    Any type of scripted object.
    It may be a list of objects or a single object.

gui: bool, optional
    It defaults to the value of `App.GuiUp`, which is `True`
    when the interface exists, and `False` otherwise.

    This value can be set to `False` to simulate
    when the interface is not available.

Variable Documentation

◆ dimDash

def draftutils.gui_utils.dimDash = dim_dash

◆ dimSymbol

def draftutils.gui_utils.dimSymbol = dim_symbol

◆ formatObject

def draftutils.gui_utils.formatObject = format_object

◆ get3DView

def draftutils.gui_utils.get3DView = get_3d_view

◆ getSelection

def draftutils.gui_utils.getSelection = get_selection

◆ getSelectionEx

def draftutils.gui_utils.getSelectionEx = get_selection_ex

◆ loadTexture

def draftutils.gui_utils.loadTexture = load_texture

◆ removeHidden

def draftutils.gui_utils.removeHidden = remove_hidden