<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: [Ironpython-users] Scripting Ansys with IronPython - Unable to callvalues from dictionary</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

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

</BODY>
</HTML>