Skip to content

Commit d15224b

Browse files
committed
copied the create_id helper from compas_fab
1 parent fe7f353 commit d15224b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added `create_id` to `compas_ghpython.utilities`. (moved from `compas_fab`)
13+
1214
### Changed
1315

1416
* Fixed bug that caused a new-line at the end of the `compas.HERE` constant in IronPython for Mac.

src/compas_ghpython/utilities/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
:toctree: generated/
5353
5454
unload_modules
55+
create_id
5556
5657
"""
5758
from __future__ import absolute_import
@@ -93,4 +94,27 @@
9394
"list_to_ghtree",
9495
"ghtree_to_list",
9596
"update_component",
97+
"create_id",
9698
]
99+
100+
101+
def create_id(component, name):
102+
"""Creates an identifier string using `name` and the ID of the component passed to it.
103+
104+
The resulting string can be used to store data elements in the global sticky dictionary.
105+
This can be useful when setting variable in a condition activated by a button.
106+
107+
Paramaters
108+
----------
109+
components : `ghpythonlib.componentbase.executingcomponent`
110+
The components instance. Use `self` in advanced (SDK) mode and `ghenv.Components` otherwise.
111+
name : str
112+
A user chosen prefix for the identifier.
113+
114+
Returns
115+
-------
116+
str
117+
For example: `somename55dd-c7cc-43c8-9d6a-65e4c8503abd`
118+
119+
"""
120+
return "{}_{}".format(name, component.InstanceGuid)

0 commit comments

Comments
 (0)