Undocumented string processing in expressions : shall we document ?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
chrisb
Veteran
Posts: 53939
Joined: Tue Mar 17, 2015 9:14 am

Re: Undocumented string processing in expressions : shall we document ?

Post by chrisb »

I just used the wiki for this 5 minutes ago to remove the (preferences dependent) decimals from a string :D .
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Undocumented string processing in expressions : shall we document ?

Post by adrianinsaval »

openBrain wrote: Sat May 15, 2021 9:23 am Only one specifier is possible inside delimiters, but string concatenating is also possible using '+', and all Python specifiers are available.
So with a default cube and 3 decimals as a precision

Code: Select all

<<Box (%s) : >> % Box.Label + <<L = %g mm : >> % Box.Length + <<W = %.2f mm>> % Box.Width
would expand in

Code: Select all

Box (Cube) : L = 10 mm : W = 10.00 mm
JFYI it is possible to use more than one % specifier like this:

Code: Select all

<<Cube length is %s and width is %s>> % tuple(Box.Length; Box.Width)
I just corrected the wiki. Source: realthunder mentioned it here: https://forum.freecadweb.org/viewtopic. ... 74#p330713 and it works in 0.20
User avatar
ProjectBP
Posts: 402
Joined: Tue Jun 06, 2023 2:33 pm
Contact:

Re: Undocumented string processing in expressions : shall we document ?

Post by ProjectBP »

Hello.

Is there any way to get one specific value from an array of data? The picture shows the distances between the centerlines. And I would like to get the second value. And then the second + third.

And in the tooltips when hovering over a particular axis, I see the data. But I can not output them through expressions in any way.

So that this data can be used in other elements of construction in expressions.

Perhaps this array can somehow be broken down into smaller parts using formatting. But I have not found an example in the documentation.

Such data is used in the axis lines, roof settings. And it would be very useful in building parametric models.

And if it were possible to modify these arrays through expressions, that would be really great. Now the axes and roofs settings do not accept expressions and are filled manually.

UPD. The solution seems to be simple (prompted)
Axis.Distances[1] , Axis.Distances[1]+Axis.Distances[2] and so on

I apologize for distracting you.)
Attachments
Scr_20230705_111452.jpg
Scr_20230705_111452.jpg (13.29 KiB) Viewed 527 times
Scr_20230705_104813.jpg
Scr_20230705_104813.jpg (22.78 KiB) Viewed 539 times
There may be a misunderstanding :!: . I communicate with the help of a translator :P
User avatar
onekk
Veteran
Posts: 6147
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Undocumented string processing in expressions : shall we document ?

Post by onekk »

ProjectBP wrote: Wed Jul 05, 2023 7:51 am ...
Probably wrong place to ask, and necrobumbing such an old post is not the best way.

However Expressions:

https://wiki.freecad.org/Expressions

it is not clear from what you intend for array.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
ProjectBP
Posts: 402
Joined: Tue Jun 06, 2023 2:33 pm
Contact:

Re: Undocumented string processing in expressions : shall we document ?

Post by ProjectBP »

onekk wrote: Wed Jul 05, 2023 9:36 am
Probably wrong place to ask, and necrobumbing such an old post is not the best way.
I saw a link to this post in the manual. in the formatting section. thought it might answer the question. That's why I wrote it here. I will be more careful next time. I haven't got the hang of the forum yet.

There are a lot of questions accumulated on the way to modeling a parametric house. I will probably have to create a separate topic for discussion

In "However Expressions" there is no example of work for such a problem. I'm not a programmer and don't know what square brackets do.
UPD.
I realized my mistake. I was looking for the solution in the manual in the wrong place (flipping down hard). I don't understand what [list_index] means in the manual.
I apologize for taking up your time.
I can delete my posts if they disturb someone

UPD2.
"it is not clear from what you intend for array."

I needed to get one of its values.
I figured it out.

What remains to be understood is whether it is possible to insert an expression from a table into one of the places of such an array, for example. That would expand the possibilities of parametric model building.
There may be a misunderstanding :!: . I communicate with the help of a translator :P
User avatar
onekk
Veteran
Posts: 6147
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Undocumented string processing in expressions : shall we document ?

Post by onekk »

ProjectBP wrote: Wed Jul 05, 2023 10:13 am ...
I apologize for taking up your time.
I can delete my posts if they disturb someone
No problem, is only a matter of "appropriate way" to obtain answers.

It is a more general approach, as usually the "Open Discussion" is not for asking help, is about "discussing things", usually here there are proposal, or more general discussion about "how to do things" maybe with "future tools" or about "how about making FreeCAD better in this area".

About your problem lists in Python (you could search it in a Python tutorial) could be used to make arrays (list of lists) and index is as example list[0] is first element (and in Python list[-1] the last element).

Some Python construct could be used in Expressions some other not, so your mileage may vary.

Good move is to make a proper post in a relevant forum section and asking for help there, probably Arch section as you are speaking of house will be a good place.

About parametric, FreeCAD is parametric, expressions and spreadsheet could improve the model if correctly done, usually most of the "input fields" in an object could support an expression and an expression could be a "reference" to a spreadsheet cell too.

Code: Select all

<<SpreadSheet1>>.wall_hei
could be a way to specify a wall_hei, if you assign an alias to the cell where wall_hei value is placed, you could even modify the spreadsheet moving cells around and have a robust model.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply