setPropertyByName

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Chri1
Posts: 86
Joined: Wed Oct 17, 2018 9:00 am

setPropertyByName

Post by Chri1 »

Hi

I created a python-object and added propérties (w1,w2,w3, w4)
I managed to get the value of a property:

Code: Select all

…
wi=["w1","w2","w3","w4"]
# i     generated by Code before
val =bk.Object.getPropertyByName(winkel[i].Value)
is there something equivalent to set the value of an property?
Something like:

Code: Select all

val=50
bk.Object.setPropertyByName(winkel[i], val)

greetings
Chri1
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: setPropertyByName

Post by ickby »

You can use pythons intrinsic setattr and getattr methods:

Code: Select all

setattr(bk.Object, winke[i], val)
Chri1
Posts: 86
Joined: Wed Oct 17, 2018 9:00 am

Re: setPropertyByName

Post by Chri1 »

Thanks, this works
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: setPropertyByName

Post by Kunda1 »

#documentation
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply