Hello all,
I have been trying to create attributes and wanted to attach them to some library elements. To do that, I created following method:
def loadLibaryElementFromEtcLibrary(path: str): path = os.path.join(AllplanSettings.AllplanPaths.GetEtcPath() + "Library\\", path) print(path) if not os.path.exists(path): print(f"The path '{path}' is not valid or does not exist.") return library_element_properties = \ AllplanBasisElements.LibraryElementProperties(fullPathName= path, elementType= getElementType(path), placementMatrix= AllplanGeo.Matrix3D())
This returns me a library element, which works just fine. Also, I am creating an attribute like this:
def createAttribute(cls, doc: AllplanEleAdapter.DocumentAdapter, attribute_name: str, default_value: str, dimension: str, attr_type: AllplanBaseElements.AttributeService.AttributeType, attr_control_type: AllplanBaseElements.AttributeService.AttributeControlType, min_value: float = 0.0, max_value: float = 0.0, list_values=AllplanUtil.VecStringList()): """ returns true, if the attribute is new, false if there is an attribute with the same name already additionally returns the id of the attribute """ existing_id = AttributeHandler.getAttributeId(doc, attribute_name) if(existing_id != -1): LogHandler.log(Severity.INFORMATION, "Attribute already exists") return False, existing_id id = AllplanBaseElements.AttributeService.AddUserAttribute( doc, attr_type, attribute_name, default_value, min_value, max_value, dimension, attr_control_type, list_values ) if(id == -1): LogHandler.log(Severity.ERROR, "The attribute could not be created!") else: LogHandler.log(Severity.INFORMATION, "Attribute creation was successful") return True, id
Now I have my attribute id and an element. I wanted to add the attribute to the library element using the AllplanBaseElements.ElementsAttributeService.ChangeAttribute(...) method, but it does not take a library element object as parameter, so of course this does not work. Then I tried setting an existing attribute, but this also does not work:
libarary_element = LibraryElements.loadLibaryElementFromEtcLibrary(path) description_attr = BaseElements.AttributeString(507, "Neue Bezeichnung") attr_set = BaseElements.AttributeSet([description_attr]) attributes = BaseElements.Attributes([attr_set]) libarary_element.SetAttributes(attributes) attributes = libarary_element.GetAttributes()
... but nothing happens, the attribute is not set or anything. The attributes list from the library is also always empty at the beginning (after adding the attribute it does have the entry) and no error is thrown. The log file from allplan also does not show anything...
Help is very much appreciated!