Skip to content

Commit 644ad8c

Browse files
vsnodes v0.5.0 update
1 parent 159c33d commit 644ad8c

5 files changed

Lines changed: 280 additions & 0 deletions

File tree

VisualScripts/ALLPLAN FRANCE/AttributesManagement_eng.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,53 @@ AttributeValue=1

5353
<Bitmap></Bitmap>
5454
</Item>
5555
</Node>
56+
<Node Name="NodeChangeObjectAttribute">
57+
<Item>
58+
<TextId>1001</TextId>
59+
<Text>Change the value of an element attribute</Text>
60+
<Description>This node modifies existing elements by setting a new value for one of their attributes or by adding the attribute if it is missing&#xA;
61+
- &#xA;
62+
- **Example:**&#xA;
63+
Objects=BaseElementAdapterList(...)&#xA;
64+
AttributeID=507&#xA;
65+
NewValue='Hello'&#xA;
66+
**Result**:&#xA;
67+
Sets the attribute **Name** to 'Hello'&#xA;
68+
Please note that 'NewValue' can also be a list; in that case, each element receives a new value according to the order of the list.&#xA;
69+
70+
## Links
71+
72+
[Help](https://github.com/cmaignan-source/vsnodes/blob/main/VisualScripts/ALLPLAN%20FRANCE/README-ChangeObjectAttribute.md)</Description>
73+
<Note/>
74+
<Bitmap></Bitmap>
75+
</Item>
76+
<Item>
77+
<TextId>1002</TextId>
78+
<Text>Objects</Text>
79+
<Description/>
80+
<Note/>
81+
<Bitmap></Bitmap>
82+
</Item>
83+
<Item>
84+
<TextId>1003</TextId>
85+
<Text>Attribute ID</Text>
86+
<Description/>
87+
<Note/>
88+
<Bitmap></Bitmap>
89+
</Item>
90+
<Item>
91+
<TextId>1004</TextId>
92+
<Text>New value</Text>
93+
<Description/>
94+
<Note/>
95+
<Bitmap></Bitmap>
96+
</Item>
97+
<Item>
98+
<TextId>1005</TextId>
99+
<Text>Modified objects</Text>
100+
<Description/>
101+
<Note/>
102+
<Bitmap></Bitmap>
103+
</Item>
104+
</Node>
56105
</Element>

VisualScripts/ALLPLAN FRANCE/AttributesManagement_fra.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,53 @@ AttributeValue=1&#xA;
5353
<Bitmap></Bitmap>
5454
</Item>
5555
</Node>
56+
<Node Name="NodeChangeObjectAttribute">
57+
<Item>
58+
<TextId>1001</TextId>
59+
<Text>Change la valeur d’un attribut d’un ou plusieurs éléments</Text>
60+
<Description>Ce nœud modifie des éléments existants en définissant une nouvelle valeur pour l’un de leurs attributs ou en ajoutant l’attribut s’il n’existe pas.&#xA;
61+
- &#xA;
62+
- **Exemple :**&#xA;
63+
Objects=BaseElementAdapterList(...)&#xA;
64+
AttributeID=507&#xA;
65+
NewValue='Bonjour'&#xA;
66+
**Résultat** :&#xA;
67+
Modifie l'attribut **Désignation** par 'Bonjour'&#xA;
68+
A noter : 'NewValue' peut aussi être une liste ; dans ce cas, chaque élément reçoit une nouvelle valeur en fonction de son ordre dans la liste.&#xA;
69+
70+
## Liens
71+
72+
[Aide](https://github.com/cmaignan-source/vsnodes/blob/main/VisualScripts/ALLPLAN%20FRANCE/README-ChangeObjectAttribute.md)</Description>
73+
<Note/>
74+
<Bitmap></Bitmap>
75+
</Item>
76+
<Item>
77+
<TextId>1002</TextId>
78+
<Text>Objets</Text>
79+
<Description/>
80+
<Note/>
81+
<Bitmap></Bitmap>
82+
</Item>
83+
<Item>
84+
<TextId>1003</TextId>
85+
<Text>ID de l'attribut</Text>
86+
<Description/>
87+
<Note/>
88+
<Bitmap></Bitmap>
89+
</Item>
90+
<Item>
91+
<TextId>1004</TextId>
92+
<Text>Nouvelle valeur</Text>
93+
<Description/>
94+
<Note/>
95+
<Bitmap></Bitmap>
96+
</Item>
97+
<Item>
98+
<TextId>1005</TextId>
99+
<Text>Objets modifiés</Text>
100+
<Description/>
101+
<Note/>
102+
<Bitmap></Bitmap>
103+
</Item>
104+
</Node>
56105
</Element>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
""" Script for NodeChangeObjectAttribute
2+
"""
3+
4+
from __future__ import annotations
5+
6+
import NemAll_Python_BaseElements as BaseElements
7+
import NemAll_Python_IFW_ElementAdapter as ElementAdapter
8+
9+
from NodeUtil.NodeBase import NodeBase
10+
from NodeUtil.NodeInitData import NodeInitData
11+
from NodeUtil.NodeObjectUtil import NodeObjectUtil
12+
13+
14+
NodeBase.trace_node_name('ChangeObjectAttribute')
15+
16+
17+
def create_node(init_data: NodeInitData) -> NodeChangeObjectAttribute:
18+
""" Create the node
19+
20+
Args:
21+
init_data: data for the node initialization
22+
23+
Returns:
24+
instance of ChangeObjectAttribute
25+
"""
26+
27+
return NodeChangeObjectAttribute(init_data)
28+
29+
30+
class NodeChangeObjectAttribute(NodeBase):
31+
""" Definition of class ChangeObjectAttribute
32+
"""
33+
34+
def normalize_to_adapter_list(self,
35+
objects: ElementAdapter.BaseElementAdapterList | ElementAdapter.BaseElementAdapter | list
36+
)-> ElementAdapter.BaseElementAdapterList:
37+
""" Will always return BaseElementAdapterList from:
38+
- BaseElementAdapterList
39+
- single BaseElementAdapter
40+
- list/tuple of BaseElementAdapter
41+
42+
Returns:
43+
objects as BaseElementAdapterList
44+
"""
45+
if isinstance(objects, ElementAdapter.BaseElementAdapterList):
46+
return objects
47+
48+
if isinstance(objects, ElementAdapter.BaseElementAdapter):
49+
adapter_list = ElementAdapter.BaseElementAdapterList()
50+
adapter_list.append(objects)
51+
return adapter_list
52+
53+
if isinstance(objects, (list, tuple)):
54+
if not objects:
55+
self.error = "The list of objects cannot be empty."
56+
57+
if not all(isinstance(obj, ElementAdapter.BaseElementAdapter) for obj in objects):
58+
self.error = "All items in the objects list must be BaseElementAdapter instances."
59+
60+
return ElementAdapter.BaseElementAdapterList(objects)
61+
62+
# Unsupported type
63+
self.error = f"Unsupported type for objects: {type(objects).__name__}."
64+
65+
66+
def _create_output(self) -> None:
67+
""" Change or add an attribute
68+
"""
69+
self._set_init_node_output(self.build_ele.ModifiedObjects)
70+
71+
raw_objects = self.build_ele.Objects.value
72+
attr_id = self.build_ele.AttributeID.value
73+
values = self.build_ele.NewValue.value
74+
75+
objects = self.normalize_to_adapter_list(raw_objects)
76+
77+
if not attr_id or (attr_name := BaseElements.AttributeService.GetAttributeName(self.document, attr_id)) == '???':
78+
self.error = f"Attribute ID {attr_id} does not exist in this project"
79+
80+
if not values or values == []:
81+
self.error = "NewValue cannot be empty"
82+
83+
if isinstance(values, str):
84+
values = [values]
85+
86+
for idx, obj in enumerate(objects):
87+
element_adapters = ElementAdapter.BaseElementAdapterList()
88+
element_adapters.append(obj)
89+
new_value = values[idx] if idx < len(values) else values[-1]
90+
BaseElements.ElementsAttributeService.ChangeAttribute(attr_id, new_value, element_adapters)
91+
92+
self.build_ele.ModifiedObjects.value = NodeObjectUtil.create_base_element_adpter_list(objects)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Element>
3+
<LanguageFile>.\AttributesManagement</LanguageFile>
4+
<Script>
5+
<Name>.\NodeChangeObjectAttribute.py</Name>
6+
<Uuid>3F7B9D20-6A84-4B71-B6AC-3B0A-1C9F812E0001</Uuid>
7+
<Title>Change the value of an element attribute</Title>
8+
<TextId>1001</TextId>
9+
<Version>0.1.0</Version>
10+
</Script>
11+
<Page>
12+
<Name>__IN_MANDATORY__</Name>
13+
<Parameter>
14+
<Name>Objects</Name>
15+
<Text>Objects</Text>
16+
<TextId>1002</TextId>
17+
<Value></Value>
18+
<ValueType>list{$Object}</ValueType>
19+
</Parameter>
20+
</Page>
21+
<Page>
22+
<Name>__IN_OPTIONAL__</Name>
23+
<Parameter>
24+
<Name>AttributeID</Name>
25+
<Text>Attribute ID</Text>
26+
<TextId>1003</TextId>
27+
<Value/>
28+
<ValueType>object{Integer}</ValueType>
29+
</Parameter>
30+
<Parameter>
31+
<Name>NewValue</Name>
32+
<Text>New value</Text>
33+
<TextId>1004</TextId>
34+
<Value/>
35+
<ValueType>list{String}</ValueType>
36+
</Parameter>
37+
</Page>
38+
<Page>
39+
<Name>__OUT__</Name>
40+
<Parameter>
41+
<Name>ModifiedObjects</Name>
42+
<Text>Modified objects</Text>
43+
<TextId>1005</TextId>
44+
<Value></Value>
45+
<ValueType>list{$Object}</ValueType>
46+
</Parameter>
47+
</Page>
48+
<Page>
49+
<Name>__HiddenPage__</Name>
50+
<Parameter>
51+
<Name>Executed</Name>
52+
<Value>False</Value>
53+
<ValueType>CheckBox</ValueType>
54+
</Parameter>
55+
</Page>
56+
</Element>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# CHANGEOBJECTATTRIBUTE - VS NODE FOR ALLPLAN
2+
3+
## Overview
4+
This node enables you to **set** or **add** an attribute on a existing object in your ALLPLAN project.
5+
6+
---
7+
8+
## 1. Inputs / Outputs
9+
10+
**Inputs:**
11+
- `Objects` → list of the objects to be modify (BaseElementAdapter or BaseElementAdapterList)
12+
- `AttributeID` → ID of the attribute (as an integer)
13+
- `NewValue` → new value for the attribute (single string or list of strings)
14+
15+
**Outputs:**
16+
- `ModifiedObjects` → modified objects as a BaseElementAdapterList
17+
18+
---
19+
20+
## 2. How it works
21+
- The node checks if the attribute already exists on the ALLPLAN elements.
22+
- If it does, the attribute value is updated.
23+
- If not: adds the attribute with the specified value.
24+
- If `NewValue` is a list, each element receives a value according to the order of the list; if there are more objects than values, the last value is reused for the remaining objects.
25+
26+
---
27+
28+
## 3. Example
29+
30+
- `Objects`=BaseElementAdapterList(...)
31+
- `AttributeID`=507
32+
- `NewValue`='Hello'
33+
- `Result`:
34+
- Sets the attribute **Name** to 'Hello'

0 commit comments

Comments
 (0)