- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, thank you a lot for the wonderful community here!
I am trying to write a script that would make different configurations of holes in the upper body and then see which one is best after running heat simulations. Hence, I want my program to be able to: (1) give a user a choice to select the faces where holes should be placed (and I achieve this easily with selectEntity); (2) if the user chooses *non* to select any faces, then I want my script to select *all* the top faces for themselves.
Why the *top* faces?: because later on, I want to specify convection coefficient which is usually thermally loaded only on top faces
Language: Python
Ideas I thought of:
(1) iterating over all the faces that the body has does *not* seem to work as I don't know which one of them is the top one?
(2) having a bunch of vectors (or only four if the design is a box) going in many different directions from the center and then check all the faces that intersect the vectors. From there, I could determine which one is 'the top one' looking at x-y-z values? <-- this seems to be very tedious.
(3) at least try selecting the upper body (my script attempts to do that but heavily relies on temporary indexing) and then make holes on all faces. Hence, if I had a case as an upper-body, I would make holes from two sides of the cases and I would *need to hope* that they match and don't create weird holes.
Any ideas on what I could do here?
Attached find the code I have right now.
def run(context):
'''Main program that is executed when the script is run from Fusion360 env.'''
ui = None
try:
### -- SETTING UP:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
# ensuring that there is model built & active:
if not design:
ui.messageBox('No active Fusion design', 'No Design')
return
# Get the root component of the active design:
rootComp = design.rootComponent
holes = rootComp.features.holeFeatures
### --
### --
# [[face_ref, [which_side, length_x, width_y, height_z], [face.centroid x y z]], ...]
# storage for reference to objects
unsafe_faces = []
### --
### -- SELECTION OF THE FACES. TWO WAYS: (1) by user; (2) by our script
user_answer = ui.inputBox("Do you want to specify faces where holes will be placed? Type 'YES', if so \
\n Otherwise, if you want the program to determine faces for you, type 'NO'. ")
if user_answer[1] == False and str(user_answer[0]).strip().upper() == 'YES':
selected_face = ui.selectEntity("Please, choose faces which need better heat dissipation.\
\n If needed, choose all the faces under the upper case.", "Faces")
unsafe_faces.append([selected_face.entity])
while True:
user_answer = ui.inputBox("Great. Do you want to have holes on another face? Type 'YES' or 'NO'.")
if user_answer[1]:
break
if str(user_answer[0]).strip().upper() != 'YES':
break
else:
selected_face = ui.selectEntity("Great. Then, please, choose face № {} \n upon which holes need to be added".format(len(unsafe_faces) + 1), 'Faces')
unsafe_faces.append([selected_face.entity])
else: ###PROBLEM??????
pass
body_with_faces = rootComp.bRepBodies[-1]
for face_idx in range(0, body_with_faces.faces.count):
unsafe_faces.append([body_with_faces.faces.item(face_idx)])
Solved! Go to Solution.