Good Morning. I’m working Perspective on the 8.0.16 Gateway. I have a script that is copying the props.elements of an SVG to use elsewhere in the project. When I update my copy of the data, it is also changing the original object’s data, since I’m actually given a reference to the original object, not a copy of the object. How can I go about copying the data without simply receiving a reference to the original object?
#Get the element data from the original object
element_adjusted = self.getSibling('test_2').props.elements[0]
#Update the information for the new object (also updates the original object)
element_adjusted.transform = 'translate(50,0) scale (1.0)'
#Write the adjusted data to the new object
elements_list.append(element_adjusted)
self.getSibling('aggregate_layout').props.elements = elements_list
Error running action 'component.onActionPerformed' on
pages/system/overview@C$0:1:0:2/root/coord_overview/Button:
Traceback (most recent call last): File "<function:runAction>", line 7, in
runAction AttributeError: 'com.inductiveautomation.perspective.gateway.script'
object has no attribute 'copy'
Error running action 'component.onActionPerformed' on
pages/system/overview@C$0:1:0:2/root/coord_overview/Button:
Traceback (most recent call last): File "<function:runAction>", line 10,
in runAction AttributeError: 'builtin_function_or_method' object has no attribute 'props'
It’s interesting this one seemed to work (didn’t error out), but returned a ‘builtin_function_or_method’ object.
copy.copy(self.getSibling('test_2')) returns this error:
copy.deep_copy(self.getSibling('test_2')) returns this error:
Ever used monkey patching as recommended in the error message? Don’t want to take the time to learn how to use it to find out that it’s not what I need.
Worst case, I’m looking at simply reading through the elements’ JSON and recreating a copy line-by-line. Definitely not the quickest way.
What if you put the property you were trying to copy, instead of the entire component? element_adjusted = copy(self.getSibling('test_2').props.elements[0])
I’m using the Drawing component, created by dragging an SVG image into the Designer and selecting to Embed it. Screenshot of the object properties and the JSON of the elements are attached.