Git Product home page Git Product logo

Comments (22)

evereux avatar evereux commented on August 23, 2024

from pycatia.

mrjapon avatar mrjapon commented on August 23, 2024

from pycatia.

evereux avatar evereux commented on August 23, 2024

Aah ok got you. I've never used the feature like that. Let me have a look at the automation API and see if I can come up with something. Might be a few days but I'll definitely respond.

from pycatia.

mrjapon avatar mrjapon commented on August 23, 2024

This macro (in VB) can help for sure. I'm studying and translating it to Python. Let's see....
https://www.eng-tips.com/viewthread.cfm?qid=436208

from pycatia.

evereux avatar evereux commented on August 23, 2024

Sorry I've not responded sooner.

I've looked at the VB script and whilst it's certainly doable in python it's not something I currently have time to look at in detail sorry. Maybe in the near future.

from pycatia.

tcrakshi avatar tcrakshi commented on August 23, 2024

How to get the user defined properties in part or product?

i am trying with "user_ref_properties", its throwing me a com error like below.

com_error: (-2147352567, 'Exception occurred.', (0, 'CATIAProduct', 'The method UserRefProperties failed', None, 0, -2147467259), None)

Can any one help me in that?

from pycatia.

evereux avatar evereux commented on August 23, 2024

@tcrakshi This is unrelated to the original post. A new issue has been raised. I will reply to the issue there.

from pycatia.

manjitkumar avatar manjitkumar commented on August 23, 2024

@mrjapon I see you faced this issue some time back. Were you able to make any progress on this?

from pycatia.

mrjapon avatar mrjapon commented on August 23, 2024

from pycatia.

Tian-Jionglu avatar Tian-Jionglu commented on August 23, 2024

Hi,
I think the key of this issue is getting a correct Inertia Object.
With pycatia 0.4.1, it can basically work.

# test Inertia

from pycatia import catia
from pycatia.space_analyses_interfaces.inertia import Inertia

caa = catia()

document = caa.active_document
product = document.product()

inertia_com = product.get_technological_object('Inertia')
my_inertia = Inertia(inertia_com)
print(my_ineria.density)
print(my_inertia.mass)

The density and mass properties can be obtained correctly. Methods like get_cog_position or get_principal_axes yet doesn't work.
I'm trying to solve this puzzle...

from pycatia.

evereux avatar evereux commented on August 23, 2024

Try this:

from pycatia import catia

caa = catia()

document = caa.active_document
product = document.product()

spa_workbench = document.spa_workbench()
inertias = spa_workbench.inertias

# clear existing inertias.
# this is required since the CAA object seems to keep the inertia collection in
# memory on each iteration of the script. Not sure if this is by design or 
# something pycatia should be doing.
for i in range(inertias.count):
    inertias.remove(1)

# add product to inertia collection.
inertias.add(product)

for inertia in inertias:
    print(inertia.mass)
    print(inertia.get_cog_position())```

from pycatia.

evereux avatar evereux commented on August 23, 2024

The density and mass properties can be obtained correctly. Methods like get_cog_position or get_principal_axes yet doesn't work.
I'm trying to solve this puzzle...

Good luck! I've been trying to solve this and can't figure out the problem.

from pycatia.

Tian-Jionglu avatar Tian-Jionglu commented on August 23, 2024

Aha, that's the correct solution to get a exact Inertia instance. But it's pity I didn't find the bound box parameters directly.

I tried another solution, simply and directly translated from

This macro (in VB) can help for sure. I'm studying and translating it to Python. Let's see....
https://www.eng-tips.com/viewthread.cfm?qid=436208

from pycatia import catia

caa = catia()

document = caa.active_document
product = document.product()

sel= document.selection

sel.clear
sel.add(product)
caa.start_command("Measure Inertia")

print(f'BBLx: {product.parameters.item("BBLx").value_as_string()}',
     f'BBLy: {product.parameters.item("BBLy").value_as_string()}',
     f'BBLz: {product.parameters.item("BBLz").value_as_string()}',
     sep='\n')

Here is one more issue should we pay attention, as CAA Document describe StartCommand:

Role:This method starts a command and executes it untill its first interaction. Please notice interactions such as selections you could add after in your macro will not work. StartCommand is useful to execute one-shot (not interactive) commands, it is not safe for interactive commands.

I think "Measure Inertia" is not one-shot command. To solve this, it would be anther issue #39.

@mrjapon, please check whether it is you mean.

from pycatia.

evereux avatar evereux commented on August 23, 2024

If I understand correct and you want the script to stop and wait for input from a user could you use a messagebox to prompt the user?

Hopefully I'll provide an example script tomorrow. 🤷‍♂️

from pycatia.

evereux avatar evereux commented on August 23, 2024

This is actually more complex than I thought to make it interactive, for a number of reasons:

  • You can't make a selection whilst the message box is open. So my suggestion above isn't valid.
  • You can use pythons inbuilt input() to halt the process, select the product, press enter to continue in the cmd window.
    • Having to switch between windows isn't user friendly.
    • You still need to close / cancel the inertia tool once the data is read. This isn't insurmountable as pywinauto could do this I think (see example 18, not directly related but uses pywinauto). However, there is a bigger problem to solve ... see next.
  • In a large product product.parameters returns ALL parameters for ALL loaded documents. parameters.item('BBLx') will only return the first occurrence.
    • Well, we could loop through the parameter names and get those that include the product name and the last BBLx no? Not really, as this is way too impractical for large products as it's too slow from my tests.

This is going to need some more thought.

from pycatia.

Tian-Jionglu avatar Tian-Jionglu commented on August 23, 2024

I've tried win32gui.FindWindow, win32gui.CloseWind, win32gui.DestroyWindow.
"Measure Inertia" Window can be find and close, but meet error when try to destroy. More work need to be done.

from pycatia.

evereux avatar evereux commented on August 23, 2024

This seems to work but comes with a warning. Please test thoroughly.

"""

    Example 26:

    Prompt the user to select a product and get it's bounding box parameters
    
    .. warning:
        Currently there must be NO other existing Measure Inertias saved 
        ANYWHERE in your product tree as these may be returned and not 
        product you have selected.

"""

import win32con
import win32gui
from pycatia import catia


def close_inertia_window():
    # for future debugging from https://stackoverflow.com/questions/55547940/how-to-get-a-list-of-the-name-of-every-open-window
    # def winEnumHandler(hwnd, ctx):
    #     if win32gui.IsWindowVisible(hwnd):
    #         print(hex(hwnd), win32gui.GetWindowText(hwnd))
    #
    # win32gui.EnumWindows(winEnumHandler, None)

    handle = win32gui.FindWindow(None, "Measure Inertia")
    win32gui.PostMessage(handle, win32con.WM_CLOSE, 0, 0)


caa = catia()
document = caa.active_document
product = document.product()
selection = document.selection
selection.clear()

c = True
while c is True:
    input("Selection product to measure.\nPress <ENTER> when selection made.")
    selection = document.selection

    caa.start_command("Measure Inertia")
    parameters = product.parameters
    print(f"BBOx = {parameters.item('BBOx').value_as_string()}.")
    print(f"BBOy = {parameters.item('BBOy').value_as_string()}.")
    print(f"BBOz = {parameters.item('BBOz').value_as_string()}.")
    print(f"BBLx = {parameters.item('BBLx').value_as_string()}.")
    print(f"BBLy = {parameters.item('BBLy').value_as_string()}.")
    print(f"BBLz = {parameters.item('BBLz').value_as_string()}.")
    selection.clear()
    close_inertia_window()

    prompt = input("Continue? (Y/N):")

    if prompt.lower()[0] == 'n':
        c = False
    else:
        c = True

from pycatia.

Tian-Jionglu avatar Tian-Jionglu commented on August 23, 2024

👍 Brilliant!

from pycatia.

tcrakshi avatar tcrakshi commented on August 23, 2024

It's really good example everex,
I think it will ans for #39 issue.

def close_inertia_window(), this function is closing command dialog box,
so now I want understand is it similarly give input like yes/no/enter options, or recognise which all are button available in command dialog box and click on those button?

If it possible , thee we can address most of the issue, like generate catpart,. , Etc

from pycatia.

Tian-Jionglu avatar Tian-Jionglu commented on August 23, 2024

so now I want understand is it similarly give input like yes/no/enter options, or recognise which all are button available in command dialog box and click on those button?

If it possible , thee we can address most of the issue, like generate catpart,. , Etc

It's possible.
However, it is done by pywin32, not pycatia. In this example, you can find it is win32gui play the role to close the window.
You can find more information by searching win32gui on Internet.

from pycatia.

evereux avatar evereux commented on August 23, 2024

It's really good example everex,
I think it will ans for #39 issue.

def close_inertia_window(), this function is closing command dialog box,
so now I want understand is it similarly give input like yes/no/enter options, or recognise which all are button available in command dialog box and click on those button?

If it possible , thee we can address most of the issue, like generate catpart,. , Etc

See example 20. message_box does what I think you're asking.

from pycatia.

evereux avatar evereux commented on August 23, 2024

Closing this as issue as I think it's resolved to a degree although the solution isn't perfect yet.

from pycatia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.