Is it possible to read rule-defined attributes with Python?

4895
8
Jump to solution
01-04-2015 01:24 PM
floraroumpani
New Contributor

I am writting a script in which i would like for python to read rule defined attributes such as area from CGA geometry.area.

I know is possible to read user-defined attributes, but when its rule defined, it doesnt seem to work.. Alternativly, is there an option to provide areas in the Object attributes of the shape, which dynamically changes as the object changes?

Many thanks in Advance,

F.

0 Kudos
1 Solution

Accepted Solutions
MatthiasBuehler
Occasional Contributor III

Hey Flora !

Both things are not possible:

1]

the CGA rule values that you see in the Inspector when the rule is evaluated can not be queried. You need to report it and fetch the value with Python.

2]

there's no dynamic way of defining object attributes. You also need Python to update those values.

Can you handle this ?

Matthias Buehler

Head of 3D Technologies

twitter: @MattB3D

---------------------------------------------------------------------------

Garsdale Design Limited

matthias.buehler@garsdaledesign.co.uk

www.garsdaledesign.co.uk

View solution in original post

8 Replies
MatthiasBuehler
Occasional Contributor III

Hey Flora !

Both things are not possible:

1]

the CGA rule values that you see in the Inspector when the rule is evaluated can not be queried. You need to report it and fetch the value with Python.

2]

there's no dynamic way of defining object attributes. You also need Python to update those values.

Can you handle this ?

Matthias Buehler

Head of 3D Technologies

twitter: @MattB3D

---------------------------------------------------------------------------

Garsdale Design Limited

matthias.buehler@garsdaledesign.co.uk

www.garsdaledesign.co.uk

floraroumpani
New Contributor

Hi Matt!

I was afraid of that.. 😕  I ll try the first option and see what i can do.

Thank you!

F.

0 Kudos
by Anonymous User
Not applicable

Flora, can you explain your goal? (just to see if another route might exist).

0 Kudos
floraroumpani
New Contributor

Hello Chris,

Thank you for your reply. What I practically need to do is to include area calculation in my python script which includes loops. Any ideas?

Thanks ,

F.

0 Kudos
by Anonymous User
Not applicable

You said "python script which includes loops". There is not a "loop" in CGA, but you can do recursion for most things that a loop would be needed for. I can show you how recursion works. Can you tell more about the calculation involving area?

Chris

0 Kudos
floraroumpani
New Contributor

Hi Chris Wilkins​,

Sorry for the delayed reply.  I am not sure how to do certain recursive functions within CGA. For example is it possible to find the minimum-maximum of an attribute for a list of shapes?

flora

0 Kudos
by Anonymous User
Not applicable

For lists of shapes you must use Python, since CGA only handles one shape at a time, and they can't talk to each other. Rather than learning Python, there is a quick and easy, yet manual way to do this:

In your rule, print the value of your attribute to the console, like this:

print(someAttributeValueYouMustPutHere)

# Put this somewhere like the beginning so it only prints once per shape.

Save the rule, show the console window and then clear its contents, then select all shapes at once, and run that rule. All of the attribute values will be in the console. In the console, select all (control-A), copy(control-C), open an Excel spreadsheet, and paste the values in. You can see the max and min values at the bottom of the screen when the values are all selected. Then plug those values back into whereever you needed it. I'm assuming some sort of colorRamp or something that needs min and max for normalization?

floraroumpani
New Contributor

Thank you Chris Wilkins,

I was looking for something dynamic, but i guess its not possible. Can i suggest this for future CE versions?? A min max function built in CGA would be very useful i think.:)

Best wishes, 

Flora

0 Kudos