[Ironpython-users] Scripting Ansys with IronPython - Unable to call values from dictionary
Ossi Heinonen
ossi.heinonen at tut.fi
Thu Nov 24 13:21:51 CET 2011
Hi Liu
Thanks for the reply!
I did as you suggested. Here's what I got with type()
type(verifiedValues)
<type 'dict'>
So it is a dictionary, right? Then I tried dir(verifiedValues)
dir(verifiedValues)
['Add', 'Clear', 'Contains', 'ContainsKey', 'CopyTo', 'Count',
'Equals', 'GetEnumerator', 'GetHashCode', 'GetType',
'Item', 'Keys', 'MemberwiseClone', 'ReferenceEquals', 'Remove',
'ToString', 'TryGetValue', 'Values', '__add__',
'__class__', '__cmp__', '__contains__', '__delattr__',
'__delitem__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__getitem__', '__gt__', '__hash__',
'__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__setitem__', '__sizeof__', '__str__',
'__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key',
'items', 'iteritems', 'iterkeys', 'itervalues', 'keys',
'pop', 'popitem', 'setdefault', 'update', 'values']
This doesn't really say much to me, is it any help to you? Or should I
use dir() in some other way?
I tried some of those, for example
dict.Contains(verifiedValues,'/Optimization/InputParameter:P1')
False
So I think this tells me - once again - that there is no such key in
verifiedValues.
I also triednew_verifiedValues=dict(verifiedValues) but got the same result
new_verifiedValues=dict(verifiedValues)
new_verifiedValues['/Optimization/InputParameter:P1']
KeyNotFoundException: /Optimization/InputParameter:P1
Would you have any thoughts about what I could try next?
Best regards
Ossi Heinonen
On 24.11.2011 13:05, 刘振海 wrote:
> Hi,
> I think you should check the type of verifiedValues like
> "type(verifiedValues)"
> then use the dir function to check the content of verifiedValues.
> maybe try to use new_verifiedValues=dict(verifiedValues)
> Hope it will help!
>
> Regards,
> Liu Zhenhai
>
> 2011/11/24 Ossi Heinonen <ossi.heinonen at tut.fi
> <mailto:ossi.heinonen at tut.fi>>
>
> 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 <mailto: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/20111124/73734d7f/attachment.html>
More information about the Ironpython-users
mailing list