Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-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
Joined
Jan 9, 2019
Messages
82
Location
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,
 
Isn’t the plug-in attached here sufficient for your purpose ?

What exactly would you like to do - define reference points for multiple circular/cylindrical holes distributed unevenly in the imported geometry ? Is that a 2D or 3D model ?
 
Thank you FEA way. My bad.
You are correct.
I want define reference points for multiple circular/cylindrical holes and its 3D model.



 
My plugin in the link of FEA way does this for face regions. Is that what you are looking for?
 
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)
 
Thank you so much.Its working well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top