|
| 1 | +#! /usr/bin/python3.6 |
| 2 | + |
| 3 | +""" |
| 4 | +
|
| 5 | + Example 26: |
| 6 | +
|
| 7 | + Prompt the user to select a product and get it's bounding box parameters |
| 8 | +
|
| 9 | + .. warning: |
| 10 | + Currently there must be NO other existing Measure Inertias saved |
| 11 | + ANYWHERE in your product tree as these may be returned and not |
| 12 | + product you have selected. |
| 13 | +
|
| 14 | +""" |
| 15 | + |
| 16 | +import win32con |
| 17 | +import win32gui |
| 18 | +from pycatia import catia |
| 19 | + |
| 20 | + |
| 21 | +def close_inertia_window(): |
| 22 | + # for future debugging from https://stackoverflow.com/questions/55547940/how-to-get-a-list-of-the-name-of-every-open-window |
| 23 | + # def winEnumHandler(hwnd, ctx): |
| 24 | + # if win32gui.IsWindowVisible(hwnd): |
| 25 | + # print(hex(hwnd), win32gui.GetWindowText(hwnd)) |
| 26 | + # |
| 27 | + # win32gui.EnumWindows(winEnumHandler, None) |
| 28 | + |
| 29 | + handle = win32gui.FindWindow(None, "Measure Inertia") |
| 30 | + win32gui.PostMessage(handle, win32con.WM_CLOSE, 0, 0) |
| 31 | + |
| 32 | + |
| 33 | +caa = catia() |
| 34 | +document = caa.active_document |
| 35 | +product = document.product() |
| 36 | +selection = document.selection |
| 37 | +selection.clear() |
| 38 | + |
| 39 | +c = True |
| 40 | +while c is True: |
| 41 | + input("Selection product to measure.\nPress <ENTER> when selection made.") |
| 42 | + selection = document.selection |
| 43 | + |
| 44 | + caa.start_command("Measure Inertia") |
| 45 | + parameters = product.parameters |
| 46 | + print(f"BBOx = {parameters.item('BBOx').value_as_string()}.") |
| 47 | + print(f"BBOy = {parameters.item('BBOy').value_as_string()}.") |
| 48 | + print(f"BBOz = {parameters.item('BBOz').value_as_string()}.") |
| 49 | + print(f"BBLx = {parameters.item('BBLx').value_as_string()}.") |
| 50 | + print(f"BBLy = {parameters.item('BBLy').value_as_string()}.") |
| 51 | + print(f"BBLz = {parameters.item('BBLz').value_as_string()}.") |
| 52 | + selection.clear() |
| 53 | + close_inertia_window() |
| 54 | + |
| 55 | + prompt = input("Continue? (Y/N):") |
| 56 | + |
| 57 | + if prompt.lower()[0] == 'n': |
| 58 | + c = False |
| 59 | + else: |
| 60 | + c = True |
0 commit comments