evereux / pycatia

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

[QUESTION] User ref Properties #232

Closed ptm-tm closed 2 months ago

ptm-tm commented 2 months ago

This is is not valid

product = document.product
user_properties = product.user_ref_properties
for i in range(1, user_properties.count + 1):
    print(user_properties.item(i).name,"=",user_properties.value)

but if we insert additional assignments - this code will be valid.

product = document.product
user_properties = product.user_ref_properties
for i in range(1, user_properties.count + 1):
    a=user_properties.item(i)
    print(a.name,"=",a.value)

its normally?

ptm-tm commented 2 months ago

sry my mistake... need add item(i) to value

ptm-tm commented 2 months ago

closed

evereux commented 2 months ago

You could do it like this:


from pycatia import catia
from pycatia.product_structure_interfaces.product_document import ProductDocument

caa = catia()
product_document: ProductDocument = caa.active_document
product = product_document.product
user_ref_properties = product.user_ref_properties

for i in range(len(user_ref_properties)):
    index = i + 1
    print(f'{user_ref_properties.item(index).name}={user_ref_properties.item(index).value}')

Maybe a little easier to read? I should update the examples to reflect this when using range on a collection.

ptm-tm commented 1 month ago

ye) its more pythonic but im create simple for quick test..

ptm-tm commented 1 month ago

You could do it like this:

from pycatia import catia
from pycatia.product_structure_interfaces.product_document import ProductDocument

caa = catia()
product_document: ProductDocument = caa.active_document
product = product_document.product
user_ref_properties = product.user_ref_properties

for i in range(len(user_ref_properties)):
    index = i + 1
    print(f'{user_ref_properties.item(index).name}={user_ref_properties.item(index).value}')

Maybe a little easier to read? I should update the examples to reflect this when using range on a collection.

for i in user_ref_properties:
    print(i.name,i.value_as_string())

its more readable... but i cant use i.value