App DocumentObjectGroup

From FreeCAD Documentation
Revision as of 07:28, 13 January 2020 by Vocx (talk | contribs) (→‎Properties: See the properties in the Std Group page.)
Other languages:
Do no translate, this information will be moved to Std_Group


Introduction

An App DocumentObjectGroup object, or formally an App::DocumentObjectGroup, is a simple element that allows grouping any type of App DocumentObject in the tree view no matter its type of data.

It was developed to organize the objects in the tree view in a way that is logical for the user.

Simplified diagram of the relationships between the core objects in the program. The App::DocumentObjectGroup class has an extension that allows it to group any type of object; the Group itself doesn't have many properties.

How to use

  1. Press the Group button in the structure toolbar. An empty Group is created.
  2. To add objects to a Group, select them in tree view, and then drag and drop them over the Group.
  3. To remove objects from a Group, drag them out of the Group, and onto the document label at the top of the tree view.

See the Std Group page for the complete information, including its use in Scripting.

Properties

An App DocumentObjectGroup (App::DocumentObjectGroup class) is derived from the basic App DocumentObject (App::DocumentObject class), therefore it shares all the latter's properties.

See the properties in the Std Group page.

Scripting

See also: FreeCAD Scripting Basics, and scripted objects.

An App DocumentObjectGroup is created with the addObject() method of the document. Once a Group exists, other objects can be added to it with the addObject() or addObjects() methods of this Group.

import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("App::DocumentObjectGroup", "Group")

bod1 = App.ActiveDocument.addObject("PartDesign::Body", "Body")
bod2 = App.ActiveDocument.addObject("Part::Box", "Box")

obj.addObjects([bod1, bod2])
App.ActiveDocument.recompute()

This basic App::DocumentObjectGroup doesn't have a Proxy object so it can't be fully used for sub-classing.

Therefore, for Python scripting, the recommendation is to create the App::DocumentObjectGroupPython object.

import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("App::DocumentObjectGroupPython", "Name")
obj.Label = "Custom label"

For example, a FEM Analysis is an App::DocumentObjectGroupPython object with a custom icon and additional properties.