Draft AutoGroup: Difference between revisions

From FreeCAD Documentation
No edit summary
(Scripting...)
Line 54: Line 54:


<!--T:10-->
<!--T:10-->
{{Emphasis|See also:}} [[Draft API|Draft API]] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].
See also: [https://freecad.github.io/SourceDoc/ Autogenerated API documentation] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].


<!--T:7-->
<!--T:7-->
If the [[Draft_Module|Draft Workbench]] is active the FreeCADGui application object has a {{incode|draftToolBar}} property. This {{incode|draftToolBar}} object has an {{incode|autogroup}} property, which contains the name of the active autogroup, or is {{incode|None}} if no autogroup is active. To change the active autogroup use the {{incode|setAutoGroup}} method of the {{incode|draftToolBar}} object. To put objects in the active autogroup use the {{incode|autogroup}} method of the Draft module.
Adding objects to the active auto-group can be done in [[macros|macros]] and from the [[Python|Python]] console by using the following function:
</translate>
{{Code|code=
autogroup(obj)
}}
<translate>
<!--T:11-->
* Puts the {{incode|obj}} element in the current auto-group.
* If auto-grouping is disabled (the group is {{incode|None}}), or if [[Draft_ToggleConstructionMode|Construction mode]] is active, or if {{incode|obj}} is already in the auto-group, the function doesn't do anything.
* The function will fail if {{incode|obj}} is already in another group that is different from the auto-group.
* The function only does something if the graphical interface is active, as the auto-group can only be chosen from the graphical interface.


<!--T:12-->
Example:
</translate>
</translate>
{{Code|code=
{{Code|code=

Revision as of 18:02, 27 July 2021

This documentation is a work in progress. Please don't mark it as translatable since it will change in the next hours and days.

Draft AutoGroup

Menu location
Utilities → AutoGroup
Workbenches
Draft, Arch
Default shortcut
None
Introduced in version
0.17
See also
Std Group

Description

The AutoGroup tool sets a selected Std Group, or a related element like an Arch Site, an Arch Building or an Arch BuildingPart, as the active auto-group. When an auto-group is set, new objects will be automatically moved to the indicated group upon being created.

Auto-grouping works with elements created with the Draft and Arch Workbenches.

File:Draft AutoGroup example.png

Draft Tray which sets the active auto-group by clicking on the folder icon and choosing a group

Usage

  1. Select a Std Group, Construction group in the tree view.
  2. Press the None button, or go to the menu Utilities → AutoGroup. If no group is selected, a drop-down menu will display eligible groups to use, or "None".
  3. The button will change with the name of the active auto-group, for example, Group.

Notes:

  • The AutoGroup button is present in the Draft Tray toolbar, which only appears in the Draft and Arch Workbenches.
  • At least one of Std Group or Construction group must exist before using this tool.
  • To change the auto-group, select another group in the tree view and click Group. If no group is selected you have the option of choosing "None" to turn off auto-grouping.
  • When auto-grouping is active, new Draft and Arch objects will be placed in that group except when Construction mode is on, in which case the new geometry will be placed in the Construction group.
  • Auto-grouping only works for objects created from the graphical user interface; objects created programmatically by macros or the Python console aren't automatically placed in groups. The user always has the possibility of programmatically doing the grouping, regardless of the auto-grouping settings.

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

If the Draft Workbench is active the FreeCADGui application object has a draftToolBar property. This draftToolBar object has an autogroup property, which contains the name of the active autogroup, or is None if no autogroup is active. To change the active autogroup use the setAutoGroup method of the draftToolBar object. To put objects in the active autogroup use the autogroup method of the Draft module.

# This code only works if the Draft Workbench is active!

import FreeCAD as App
import FreeCADGui as Gui
import Draft

doc = App.newDocument()

polygon1 = Draft.make_polygon(5, radius=1000)
polygon2 = Draft.make_polygon(3, radius=500)
polygon3 = Draft.make_polygon(6, radius=220)

layer = Draft.make_layer()
# Make the layer the autogroup:
Gui.draftToolBar.setAutoGroup(layer.Name)

Draft.autogroup(polygon1)
Draft.autogroup(polygon2)
Draft.autogroup(polygon3)

doc.recompute()