Hi,
Due to my lack of Python-knowledge I’m struggling with moving a finalized Python script into Dynamo.
In the original script the variables are defined inside the __init__
method, but after putting it into Dynamo, I these variables will come form Dynamo, so these will be input parameters. So I have to modify this __init__
method but I can’t know how I should do it.
This is the original script part (self.x_all and self.y_all originally come from external CSV files):
class Opticlass:
def __init__(self) -> None:
file_path = os.path.dirname(os.path.abspath(__file__))
self.x_all = np.genfromtxt(file_path+'/s.csv')
self.y_all = np.genfromtxt(file_path+'/e.csv')
rs = 10
re = 10
self.l_min = 10
self.angle_change_max_deg = 0.15
This is how I tried to modify it in Dynamo:
x = IN[0]
y = IN[1]
rs = IN[2]
re = IN[3]
l_min = IN[4]
angle_change_max_deg = IN[5]
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
import numpy as np
class Opticlass:
def __init__(self) -> None:
self.x_all = np.asarray(x)
self.y_all = np.asarray(y)
self.l_min = l_min
self.angle_change_max_deg = angle_change_max_deg
t.Commit()
pass