-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature proposal: user defined (Python?) functions for Expressions and Spreadsheets #14042
Comments
It only works in realthunder's Link branch for now unfortunately. I've taken notice of your forum threads while on my own FreeCAD learning journey. We seem to have similar frustrations regarding limitations of expressions and general disconnect between the GUI and the object-oriented base it rests on. IMHO FreeCAD really needs a safe scripting system (like Lua?) that allows us to do some level of programming that gets saved in the FCStd file. That or a way to put Python macros in it and ask the user if its okay to run them. Anyway, you are not alone. |
Embedding Python code into a FCStd file has been discussed many times and is refused for security reasons : to separate data and code. If you want to ship your own code there are already many available methods (macro, FC object ...) |
Having two occasions where something different would help you is quite a long way from justifying opening up Expressions to full-on Python. To me, the proposed solution is overkill for the problems. Also, the two issues you identify are quite different in scope. Cosine rule can already be done with Expressions, it just needs a little more typing. The global placement issue is different and might be fixed locally by opening up just that part which is currently closed to Expressions. What I am saying is that until the RT changes reach the top of the in tray, small wins in focussed or targeted places might be easier to achieve. On cosine rule, please see https://github.com/sbyrnes321/trianglesolver A similar solve() function might be easier to add to the list of permitted Expressions (cube root was added recently as a standalone function, even though exponentiation to 1/3 has long been possible). |
It's not about begging for a fish (or two), but about empowering users to do fishing on their own, in general. Regarding choice of language, I think, any Turing complete language might do. May be even some superset of the current expression language, complemented by some control structure and skd of "define function"? My favour for Python was due to the native access to object properties - which leads to the question of security. I understand that the development carawane has priority towards TNP. But coming new from outside, I see the FreeCAD communty falling into two parties regarding TNP:
Why do associations of primordial reptile instincts come to my mind? Humans have learned to overcome such instincts with rational decisions. But they are still humans, prone to be caught by emotional patterns, I know.... E.g. there is a sketching wiki (I consider flipping sketches the little sister of TNP, OK?), suggesting to avoid datum constraints as fas as possible. And there is a TNP wiki, suggesting the opposite: relying on datum constraints as far as possible, to keep control on the model. From a sportive or hunting spirit, I'm with the TNP attackers: Failure is not an option. We'll do it, because we can do it. And FreeCAD is going to be THE one FOSS CAD, so there is no room for compromise. OK. I also see that toddler like attachment aka "wanna this, there, that way..." appears fast, efficient and attractive, in the first moment. But many time I have allowed myself to be lured down that way, I had to pay long hours of repairing my designs, as soon as I wantet to apply some minor modifications. There are people who just want to do some mediocre designs. Like me, but not only. Have their sportive goals in other areas. Instead of elaborate ways to cope with inevitable ambiguities resulting from the behaviour of sophisticated solvers, they tend to avoid those solvers all togehter, as long as they don't se a real advantage for their specific design. People like me, who start to keep track of all placement of assembled subelements in a spreadsheet now, since, as soon as I loose control, I have hard times to gain it back. Cumbersome, but safe. And in the end much faster than reparing a complex model that has fallen apart due to uncomprehensible opaque automagics. I understand that at the moment, there is no way to implement my idea. Can live with that. So, I'd suggest that some authorized developer might rate this issue as "delayed but not forgotten forever"? |
python in expressions would be a security nightmare so I don't think we'll do that. User defined functions could be a desirable feature |
Is there an existing issue for this?
Problem description
From elaborated office spreadsheets (and other applications), we know that we can supply user defined functions to expand the functionality of the formula language in customized manner.
In the FreeCAD envrionment, I'd assume that Python were the language of choice for such an endeavour.
In @realthunder 's Wiki
https://github.com/realthunder/FreeCAD_assembly3/wiki/Expression-and-Spreadsheet
there even is described an elaborated ability to acces python in Expressions (and thus in spreadsheets, too).
However, I failed to reproduce this on current stable 0.21.2.
On my journey from bloody novice to still-bloody silly-user in FreeCAD, there were two occasions where I really missed user defined functions:
https://forum.freecad.org/viewtopic.php?t=86102
https://forum.freecad.org/viewtopic.php?p=759225#p759225
Of course, this are mere examples, other people may have other needs in mind.
From my experience, user defined functions (e.g. in Excel) reduce the amount of programming and object integration required to a considerable extent, compared to implement a far wider superset of the functionality in high level language, as it seems the way to go with FreeCAD at the moment - see e.g.
https://wiki.freecad.org/Python_scripting_tutorial
Full version info
Subproject(s) affected?
Expressions
Anything else?
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: