How to update a model's dictionary IDs using the update_card() method

28 views
Skip to first unread message

stepha...@gmail.com

unread,
Jan 28, 2019, 12:05:05 PM1/28/19
to pyNastran Discuss
Hi,
First off, pyNastran is a fantastic tool and I am super impressed with its quality and usefulness - thank you for all the development efforts!


I am trying to export/write some cards after having modified them in pyNastran. I would like to export them sorted by their new Element ID. 
However, when using either update_card() or directly editing the field of the card (eg. cbush.eid = 1234), the original dictionary IDs of the read BDF remain the same. Since the order of model.elements.items() is determined by the original ID, the cards are written following the order of their old IDs.

Is there a way to update these dictionary IDs? Or is there a way to write out sorting on the card ID, not the BDF dictionary ID.

Thank you very much!
Stephan



Example:

Modified CBUSH cards using:

model.update_card('CBUSH', 6010001, 1, 329001)
model.elements.items()

Output is:

dict_items([(6010001, CBUSH 329001 319010 141240 320291 319001
), (6010002, CBUSH     329003  319010  141239  320284                          319001
), (6010003, CBUSH     329315  319010  320280  122291                          319022
), (6010004, CBUSH     329313  319010  320294  122293                          319022

To export, I am using "Method 1" described in the documentation:
http://pynastran.m4-engineering.com/1.1.0/quick_start/bdf_overview.html#id1

Steven Doyle

unread,
Jan 28, 2019, 12:20:33 PM1/28/19
to pyNastran Discuss
Stephen,

That's not a use case that's handled by the code.  You can just do:
    model.elements = {element.eid : element for element in model.element.values()}

Even for a large number of elements, it should be fast.  Alternatively, store the elements that you modified, remove those ids, and add the new elements to the dictionary.

Steve

--
You received this message because you are subscribed to the Google Groups "pyNastran Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pynastran-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

stepha...@gmail.com

unread,
Jan 29, 2019, 5:09:25 AM1/29/19
to pyNastran Discuss
Thanks for the quick reply Steve!

I hadn't thought of simply re-defining the model.elements dictionary. This approach works well.

Just for future readers, the code to update the elements dictionary is:

model.elements = {element.eid : element for element in model.elements.values()}

(you had forgotten an "s").


Stephan
Reply all
Reply to author
Forward
0 new messages