×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ANSYS WB: Element Centroid

ANSYS WB: Element Centroid

ANSYS WB: Element Centroid

(OP)
Hi guys,
i have i problem and i cannot find a solution, i hope you can help me.
I have a named selection of solid elements and i would like to export the element id and the location of the centroid. Is it possile?
For named selections of nodes it is sufficient to set Include Node Location in options, but for elements is not possible.
Thank you a lot.

RE: ANSYS WB: Element Centroid

One possible solution is to select the named selection in the tree and
paste this code to the console. You can then write the data to a text file.

model = ExtAPI.DataModel.Project.Model
analysis = model.Analyses[0]
meshdata = analysis.MeshData

ns = ExtAPI.DataModel.Tree.FirstActiveObject
element_ids = ns.Location
elements = [meshdata.ElementById(element_id) for element_id in element_ids]
centroids = [element.Centroid for element in elements]

RE: ANSYS WB: Element Centroid

(OP)
Thank you. I think It is a good idea. May i ask you how to export centroids into a txt file? Thank you very Much

RE: ANSYS WB: Element Centroid

I encourage you to learn the basics of python programming language if you need use the console in the future. Here is a quick example
of how to write the ids and centroids to a text file.


CODE --> python

import csv, os
model = ExtAPI.DataModel.Project.Model
analysis = model.Analyses[0]
meshdata = analysis.MeshData
workingDir = analysis.WorkingDir

ns = ExtAPI.DataModel.Tree.FirstActiveObject
element_ids = ns.Location
elements = [meshdata.ElementById(element_id) for element_id in element_ids]
centroids = [element.Centroid for element in elements]

os.chdir(workingDir)
with open(ns.Name + '.txt', 'w') as f:
    writer = csv.writer(f, delimiter = '\t')
    writer.writerow(['ElementId', 'x', 'y', 'z'])
    for element_id, centroid in zip(element_ids, centroids):
        row = [element_id] + list(centroid)
        writer.writerow(row) 

RE: ANSYS WB: Element Centroid

(OP)
Hi L_K Thank you very much, your code worked very Well for my project. I Am doing the thesis work, i know i should learn python but i don t have enough time. May i ask you the last thing (i hope)? I have a txt file with the IDs of element faces, is there the possibility to import It As a named selection? I know how TO import nodes and 3d elements through .cdb, but i cannot do It with element faces. Do you know how TO do It with act for example? Thank you a lot!

RE: ANSYS WB: Element Centroid

If you export a named selection which consists of element faces to a cdb file and then import that cdb file back to Mechanical,
the resulting named selection is nodal.

If you create a new named selection and go to the worksheet you can find that EntityType column has an option "Element Face".
In the criterion column the options are named selection, normal and xyz locations. Unfortunately ID is not an option.
So at least I don't know how to automate this. Can you share a sample of the file?



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close