Draft AutoGroup: Difference between revisions

From FreeCAD Documentation
(More concise information, and links)
(Code more complete)
Line 32: Line 32:


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

{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].


<!--T:7-->
<!--T:7-->
Adding objects to the active auto-group can be done in [[macros]] and from the [[Python]] console by using the following function:
In python scripts, using Draft autogrouping is simply done with the command below:
</translate>
{{Code|code=
autogroup(obj)
}}
<translate>
* 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.


Example:
</translate>
</translate>
{{Code|code=
{{Code|code=
import Draft
import FreeCAD, Draft

Draft.autogroup(object)
Polygon1 = Draft.makePolygon(3, 500)
Polygon2 = Draft.makePolygon(3, 1000)
Polygon3 = Draft.makePolygon(5, 1500)

FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "Group")

# Use the graphical interface to set "Group" for auto-grouping

Draft.autogroup(Polygon1)
Draft.autogroup(Polygon2)
Draft.autogroup(Polygon3)
}}
}}

Revision as of 22:15, 20 November 2018

Draft AutoGroup

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

Description

The AutoGroup tool sets a selected Std Group, or a related element like a Draft VisGroup, Arch Site, Arch Building or 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

How to use

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

At least one Std Group should exist before calling this tool.

Notes:

  • 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: Draft API and FreeCAD Scripting Basics.

Adding objects to the active auto-group can be done in macros and from the Python console by using the following function:

autogroup(obj)
  • Puts the obj element in the current auto-group.
  • If auto-grouping is disabled (the group is None), or if Construction mode is active, or if obj is already in the auto-group, the function doesn't do anything.
  • The function will fail if 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.

Example:

import FreeCAD, Draft

Polygon1 = Draft.makePolygon(3, 500)
Polygon2 = Draft.makePolygon(3, 1000)
Polygon3 = Draft.makePolygon(5, 1500)

FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "Group") 

# Use the graphical interface to set "Group" for auto-grouping

Draft.autogroup(Polygon1)
Draft.autogroup(Polygon2)
Draft.autogroup(Polygon3)