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!

Python script for Finding the center of hole

Status
Not open for further replies.

mj345

Mechanical
Jan 9, 2019
72
0
0
US
Hi All,
Thank you everyone for quick responses. I would like to write python script for finding the center point co ordinates of a hole.
Could you please share your ideas.

Thanks,
 
Replies continue below

Recommended for you

Thank you FEA way. My bad.
You are correct.
I want define reference points for multiple circular/cylindrical holes and its 3D model.



 
Yes Mustaine3. Thank you so much. Really appreciated.
I have one more question regarding selecting edges based on their length.
working on big assembly,want to select the edges less than the 0.25" edge length.
I am trying to find them using below python script.

import part
X=mdb.models['Model-1'].parts['Part-1'].edges.getSize()
print X

got an Name error: name 'i' is not defined.

but when I use 'i' equals to some number like 1,2,3. Its printing the length of particular numbered edge.

import part
X=mdb.models['Model-1'].parts['Part-1'].edges[1].getSize()
print X
#####
Length of edge = 18.75
#####
Could you please help me out.

Regards,
 
You would have to loop through all edges in the model and define a condition that if edge is less than 0.25" long then it should be selected.
 
Exactly. Run a for-loop over all edges and use getSize. Then you can check the value and if it fulfills a certain conditions you can do something with it (add the edge id to a list, e.g.)
 
Thank you both for your valuable suggestions.
Started working on it and struck in the middle. Can you look into this when you get chance.

import part
all_edges=mdb.models['Model-1'].parts['Part-1'].edges
nol=len(all_edges)
for i in range(0,nol):
print all_edges[0].getSize()
###its giving all egde lengths like this
Length of edge = 0.973893722612832
0.973893722613########################
I want to include if command to select edges less than 0.55 length
if (Length of edge < 0.55):

Thanks,
 
The additional printout can be suppressed. See documentation. So the only output of getSize() is the value.
Here is an example. In this case the small edges are collected in an additional list.

Code:
edgelist = mdb.models['Model-1'].parts['Part-1'].edges
smalledges = []

for i in edgelist:
	k = i.getSize(printResults=False)
	
	if k < 0.55:
		smalledges.append(i)
 
Status
Not open for further replies.
Back
Top