evereux / pycatia

python module for CATIA V5 automation
MIT License
196 stars 53 forks source link

[BUG] Instance renaming not working #188

Open gggstamm opened 9 months ago

gggstamm commented 9 months ago

Describe the bug when trying to change the "name" it is not taken into account if the Part is in a Component

To Reproduce Sample of code with snapshot

def bug_pycatia():
    catia_com = catia()
    documents = catia_com.documents

    product_document = documents.add('Product')
    root = Product(product_document.document.Product)
    root.part_number = 'OK1'

    sub_product = root.products.add_new_product('OK2')
    sub_product.part_number = 'OK3'
    sub_product.name = 'OK4'

    sub_product.products.add_components_from_files(i_files_list=((r"E:\CAD_INT\working\exchange_old\Cube.CATPart"),), i_method="All")

    cube = sub_product.products.items()[0]
    cube.part_number = 'OK6'
    cube.name = 'KO_KO_KO'     # this is KO

Expected behavior the cube instance name should be changed

Screenshots screenshot of the bad result given image Cube.zip

Desktop (please complete the following information):

Additional context no

evereux commented 9 months ago

I can reproduce this with my own quick and dirty script.

Have you tested this in VB? pycatia doesn't do anything fancy here so I suspect the fault lies with CATIA V5?

evereux commented 9 months ago

So, I recorded a macro to see how CATIA does it in VB and converted that to pycatia. Interestingly this works:

caa = catia()
application = caa.application
document = application.active_document
product_document = document
component_node = Product(product_document.get_item('Product2').com_object)
products = Products(component_node.products.com_object)
sub_part = products.item('LL300010P-101.2')
sub_part.name = 'purple_monkey'
evereux commented 9 months ago

Been playing some more. The key here seems to be to use get_item on the ProductDocument to get the component node and not by getting the Products collection from the top Product.

I don't think this is a pycatia bug.

gggstamm commented 9 months ago

You are right : " The key here seems to be to use get_item" Then the difficulty is to know what is the name of the item we are looking for (when we come from add_components_from_files) It is really weird. In any case, look like it is not a bug on pycatia side, and your comments helped me to get around the issue. Thanks a lot for your reactivity

evereux commented 9 months ago

It's maybe bit hacky but I'm thinking you could maybe use your method to get the name of the instance and use that name with get_item().

It's definitely a bit weird. I'm hoping to have a look at this a bit more soon.

siddhu2310 commented 1 month ago

@gggstamm , Have you resolved your issue ?

gggstamm commented 1 month ago

@gggstamm , Have you resolved your issue ? @siddhu2310 I do not get your question; evereux gave a working python code with get_item. It is a bad workaround, but a working one!