[Ironpython-users] Scripting Ansys with IronPython - Unable to callvalues from dictionary

Ossi Heinonen ossi.heinonen at tut.fi
Fri Nov 25 10:49:14 CET 2011


Hi Eyvind

That gives me

     print verifiedValues[dict.keys(verifiedValues)[0]]
     5.5 [mm]

Which is pretty damn exactly what I need! Thank you very much! The only 
problem now is that the order of the keys seems a bit random but maybe I 
can find some pattern for that.

Thanks again!

- Ossi


On 25.11.2011 11:24, Eyvind Axelsen wrote:
>
> Hi Ossi,
>
> I had some problems posting to the list, so I send to you directly:
>
>
> What happens if you try the following?
>
>  print verifiedValues[dict.keys(verifiedValues)[0]]
>
>
>  Eyvind.
>
>
>
>
> -----Original Message-----
> From: ironpython-users-bounces+eyvind.axelsen=profdoc.no at python.org on 
> behalf of Ossi Heinonen
> Sent: Thu 24.11.2011 09:54
> To: Ironpython-users at python.org
> Subject: [Ironpython-users] Scripting Ansys with IronPython - Unable 
> to callvalues from dictionary
>
> Hi all!
>
> I have a problem with scripting the FEA software Ansys Workbench with
> IronPython. I need to come up with a script that gets the variable
> values in an optimum point that I have found using the optimization tools.
>
> I found some help for this with "VerifyCandidate" in the scripting guide
> in the Ansys manual and did this in the Ansys Workbench command window:
>
>    IronPython 2.6.10920.0 on .NET 2.0.50727.3625
>    system1 = GetSystem(Name="GDO")
>    optimization1 = system1.GetContainer(ComponentName="Optimization")
>    optimizationModel1 = optimization1.GetModel()
>    verifiedValues = optimizationModel1.VerifyCandidate(Index=0)
>    print verifiedValues
>    {'/Optimization/OutputParameter:P3': '-0.035979796200990677 [mm]',
>    '/Optimization/InputParameter:P1': '5.5 [mm]',
>    '/Optimization/OutputParameter:P2': '0.07417053282883164 [kg]'}
>
> Now I have a dictionary with my one design variable P1 and two responses
> P2 and P3 with their values at the optimum. Looking good so far. So now
> I only need to get my hands on the values and I'm home free.
>
> I think this should give me the value of the design variable P1:
>
>    verifiedValues['/Optimization/InputParameter:P1']
>    KeyNotFoundException: /Optimization/InputParameter:P1
>
> But no, I get an error saying that there is no such key. But when I list
> the keys, it's right there:
>
>    dict.keys(verifiedValues)
>    ['/Optimization/OutputParameter:P3',
>    '/Optimization/OutputParameter:P2', '/Optimization/InputParameter:P1']
>
> So this is my problem. I've tried calling it without the quotes or with
> double quotes and any other variation that I've come up with. If I make
> a new dictionary manually with the exact same keys and values copied
> from the screen it works just fine. But I can't get anything out of the
> original dictionary.
>
> Any ideas on how to get it working or what could be done to debug this?
> The only idea I've had is that for some reason the keys are printed
> incorrectly and some characters are actually missing from their names,
> but I might be totally off with this.
>
> Needless to say that I'm a total newbie with Python. Probably the right
> people to ask are other Ansys users, but I've had no luck finding one
> that could help me. Maybe my luck will chance with you Python gurus :)
>
> All help is greatly appreciated!
>
> Best regards
>
> Ossi Heinonen
> Researcher
> Tampere University of Technology
> Finland
>
> _______________________________________________
> Ironpython-users mailing list
> Ironpython-users at python.org
> http://mail.python.org/mailman/listinfo/ironpython-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20111125/3e3e7e05/attachment.html>


More information about the Ironpython-users mailing list