setPropertyByName

Need help, or want to share a macro? Post here!
Chri1
Posts: 68
Joined: Wed Oct 17, 2018 9:00 am

setPropertyByName

Postby Chri1 » Tue Nov 05, 2019 1:17 pm

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
Posts: 2959
Joined: Wed Oct 05, 2011 7:36 am

Re: setPropertyByName

Postby ickby » Tue Nov 05, 2019 1:23 pm

You can use pythons intrinsic setattr and getattr methods:

Code: Select all

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

Re: setPropertyByName

Postby Chri1 » Tue Nov 05, 2019 2:20 pm

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

Re: setPropertyByName

Postby Kunda1 » Tue Nov 05, 2019 5:20 pm

#documentation
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features