Author Topic: The mutable problem in Function  (Read 378 times)

eason1021

  • Newbie
  • *
  • Posts: 24
The mutable problem in Function
« on: January 30, 2019, 11:46:01 AM »
Hello everyone, when I write a script to calculate the property. Sometimes I need to set the pbc.
In the latest version, I set the pbc condition like this:
Code: [Select]
cell_ref = node_ref.compute().cell_
with cell_ref:
    cell_ref.pbc=(True,True,False)
This method is a success, however, when I use the same method in def, it has an error message.
Code: [Select]
def compute_myproperty(frame, input, output):
    data = input
    data.cell_.pbc = (True, True, False)
the message said that I need to add '_' notation.
But I have been added it... how to solve this problem?

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 233
Re: The mutable problem in Function
« Reply #1 on: January 30, 2019, 02:05:23 PM »
Hello,

in the latest version you don't need to use two separate "input" and "output" data objects. Now the DataCollection data initially holds the input data objects of the modifier, which were produced by the upstream part of the data pipeline. Your user-defined modifier function is then free to modify the data collection and the data objects stored in it, so simply do it like this:

Code: [Select]
def modify(frame, data):
    data.cell_.pbc = (True, True, False)

-Constanze

eason1021

  • Newbie
  • *
  • Posts: 24
Re: The mutable problem in Function
« Reply #2 on: January 30, 2019, 03:00:58 PM »
Thanks to your reply, the problem has been solved!