-2

I use Python to pilot a software named Orcaflex. Orcaflex has its own python library with functions.

Here is just an example to load a model and modify the position of the vessel

import OrcFxAPI as OF
model = OF.model()
model.LoadData(OrcaflexFile)
Vessel = model[VesselName]
Vessel.InitialX = 0

If I need to define the X, Y, Z position, I will write:

Vessel.InitialX = 0
Vessel.InitialY = 10
Vessel.InitialZ = 5

But I would like to make a loop, I know the below is an horror, but it is just to show what I would like to do:

pos = [0,10,5]
dof = ['X','Y','Z']
for i in range(3):
  Vessel.Initial + dof[i] = pos[i]

So how should I do that properly ?

  • 3
    You _can_ do this, but it is virtually never useful. – khelwood Oct 30 '18 at 10:31
  • 1
    I would suggest you to use dictionaries instead :) . – NoorJafri Oct 30 '18 at 10:33
  • 1
    `but for some reasons this is not what I want to do here.` You need to [**explain clearly in your question**](https://stackoverflow.com/posts/53062276/edit) why this is the case. – jpp Oct 30 '18 at 10:33
  • This question is completely different from the original. ANyway, unless the number of dimensions is not fixed, the proper way to do this is without a loop. – Stop harming Monica Oct 30 '18 at 13:46
  • Specific for this case, but the Orcaflex API objects have methods called `SetData`, where you can use the properties names as the first argument: `vessel.SetData('InitialX', 0, 0)`. From there it is straightforward to do what you want. – Raf Jan 13 '21 at 13:25

1 Answers1

1

Try this:

dict_i = {}
for i in range(1,3,1):
    print('Variable{0} = {0}'.format(str(i)))
    dict_i['Variable{}'.format(i)] = i

Necessary data print and parallel write in dict_i