Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ANSYS WB: Element Centroid

Status
Not open for further replies.

Francesco La

Mechanical
Jul 4, 2019
5
0
0
FR
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.
 
Replies continue below

Recommended for you

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]

 
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.


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)
 
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!
 
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?



 
Status
Not open for further replies.
Back
Top