Object name/bg

Въведение

Всички обекти в програмата имат име на обект, което уникално ги идентифицира в даден документ.

Тази информация се прилага за всички обекти, получени от App DocumentObject (клас App::DocumentObject), който по същество включва всички обекти, които е възможно да се създадат в документ.

Бележки

Има различни свойства на името:

В обобщение, Name по същество действа като уникален идентификатор (UID) за обект. Тъй като уникалното име Name е много ограничително, всички обекти също имат свойство Label, което позволява "преименуване" на обекта на нещо по-описателно. Вътрешното име Name всъщност остава фиксирано, но потребителят може да редактира Label, и може да се го използва в повечето ситуации, в които ще се използва и Name. В обща употреба в програмата и документацията, "преименуване" означава промяна на Label, а не действителното име Name на обекта.

Етикети

Има различни свойства на етикетите:

<<Custom Label With Spaces>>.Height
<<Label may use UTF8 characters>>.Width

Label2

Това е прост низ, който може да съдържа произволен текст и следователно може да се използва за документиране (описване с повече подробности) на създадения обект.

Scripting

See also: FreeCAD Scripting Basics, and scripted objects.

Any object in the software is internally created with the addObject() method of the document. The majority of 2D and 3D objects that the user will see in the 3D View are derived from a Part Feature. In the following example, the object created is a Part Box.

import FreeCAD as App

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

Name

The addObject function has two basic string arguments.

Label

The Label is a property of the created object and can be changed to a more meaningful text.

Getting an object by Name or Label

All objects in a document are data attributes of the corresponding Document object. The attribute's name correspond to the internal Name of the object.

import FreeCAD as App

obj1 = App.ActiveDocument.Box
obj2 = App.ActiveDocument.Box001
obj3 = App.ActiveDocument.Box002

This is equivalent to using the getObject method of the Document.

import FreeCAD as App

obj1 = App.ActiveDocument.getObject('Box')
obj2 = App.ActiveDocument.getObject('Box001')
obj3 = App.ActiveDocument.getObject('Box002')

However, it is also possible to get the object by the more descriptive Label.

import FreeCAD as App

obj1 = App.ActiveDocument.getObjectsByLabel("Concrete wall")[0]
obj2 = App.ActiveDocument.getObjectsByLabel("Custom parallelepiped")[0]
obj3 = App.ActiveDocument.getObjectsByLabel("Some special name for this cube__002")[0]

Given that the Label is in general not unique, the getObjectsByLabel method returns a list with all objects found with that Label. However, if the Label is unique in the document then the first element in that list should be the desired object.