How to modify property documentation

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
msauv
Posts: 2
Joined: Sat Oct 23, 2021 10:04 pm

How to modify property documentation

Post by msauv »

Hello
I try to change de "documentation of properties" in spreadsheet. used for tooltip in property editor.
I did not found a way in the GUI
In Python I found a getDocumentationOfProperty but no corresponding set, and getProperty return a string ,not an object.
getDocumentationOfProperty is not even in FreeCad documentation.
Is thre a way to change the documentation instead of suppressig and adding the property?
If the property is suppressed and recreated what about th formulas using the property ?
Best regards
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: How to modify property documentation

Post by TheMarkster »

I know of no way to change the documentation/tooltip of a property except to remove it and add a new one, which will disrupt any expressions bound to the property.

It should be possible to make a copy of all the expressions the object is using:

Code: Select all

old_expressions = obj.ExpressionEngine
and then restore them after removing and adding back the property

Code: Select all

for o in old:
    obj.setExpression(o[0],o[1])
But there can also be objects with expressions bound to the property which also must be preserved.

Code: Select all

propmap = {}
others = obj.InList
for other in others:
    propmap[other] = other.ExpressionEngine
Then after removing/adding the property with its new tooltip/documentation string:

Code: Select all

for k,v in propmap.items():
    for expression in v:
       k.setExpression(expression[0],expression[1])
All of this is untested and likely has errors. It would be better to check if the property is part of the expression before restoring it, but I don't think there is any harm in restoring all of them.
msauv
Posts: 2
Joined: Sat Oct 23, 2021 10:04 pm

Re: How to modify property documentation

Post by msauv »

Thanks for answering
I did not found anay way except suppress/add, even in C++ sources
But, at least in version 0.19, my tests indicate that suppress/add do not disrupt expressions using the property.
I checked in containts for distances in sketcher and position in pad
Best regards
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: How to modify property documentation

Post by TheMarkster »

Perhaps you are removing the old property and adding the new one before the system can react if expressions are not broken by doing this.
Post Reply