hexagon logo

ADAMS Python, more in-depth examples?

​I am very excited about opening up the python interface for ADAMS 2017, but as I dig into the language, I'm finding lots of ways to crash view, and not much documentation.
 
The 2017 documentation is good at giving a very short introduction, showing how to create and modify objects, but these are frankly trivial examples and don't actually use much of the python language.
 
For example, if I want to iterate through all the parts in my model, I imagine I would do something like
 
prtNames=list()
for prt in Adams.getCurrentModel().Parts.iteritems():
  prtNames.append(prt.name)
 
I have tried several iterations of this, and most of them either throw an error or crash Aview (this one then crashes). Can anyone point me to some more complex examples, which take advantage of python coding patterns?
 
Crashing suggests the code is fragile, so I need more guidance than the help() command in how to do things as help() reveals things that are broken, like the iteritems function.
Parents
  • Hi Chris,
     
    I've spent some time with the new API and it sounds like I've had a bit more luck than you - I have seen a few crashes, but not many. In fact I spent 3 days demoing aspects of this to customers and didn't have a single crash! Some thoughts:
     
    1. iteritems() returns a tuple of (key, value), so try correcting to:
     
    mod = Adams.defaults.model
    for pName, pObj in mod.Parts.iteritems():
    prtNames.append(pName)
     
     
    2. I've attached an example of auto-renaming joints in your model, for interest's sake.
     
    3. I've attached an 'Adams Python cheatsheet' for common issues.
     
    4. We have a training class that will be available in a month or so; that has a fair bit of basic Python to get one going, but there are vast resources out there. I stumbled upon this cheatsheet and it's more of a 'cheat book' that looks quite good:
     
     
    If you post ideas for examples/questions then we'll add articles to our SimCompanion on this..
     
    Thanks,
    Kent
     
     
     
     

    Attached Files (1)
Reply
  • Hi Chris,
     
    I've spent some time with the new API and it sounds like I've had a bit more luck than you - I have seen a few crashes, but not many. In fact I spent 3 days demoing aspects of this to customers and didn't have a single crash! Some thoughts:
     
    1. iteritems() returns a tuple of (key, value), so try correcting to:
     
    mod = Adams.defaults.model
    for pName, pObj in mod.Parts.iteritems():
    prtNames.append(pName)
     
     
    2. I've attached an example of auto-renaming joints in your model, for interest's sake.
     
    3. I've attached an 'Adams Python cheatsheet' for common issues.
     
    4. We have a training class that will be available in a month or so; that has a fair bit of basic Python to get one going, but there are vast resources out there. I stumbled upon this cheatsheet and it's more of a 'cheat book' that looks quite good:
     
     
    If you post ideas for examples/questions then we'll add articles to our SimCompanion on this..
     
    Thanks,
    Kent
     
     
     
     

    Attached Files (1)
Children
No Data