Use length of a sketch line in an expression

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
teejay03830
Posts: 21
Joined: Mon Oct 12, 2020 4:08 pm

Use length of a sketch line in an expression

Post by teejay03830 »

I would like to use the length of a line in a sketch in an expression.

I have had success using expressions to reference aliases in spreadsheets.

but i dont know how to reference a specific lines length from a sketch

<<Sketch>>.Constraints seems to show up in the formula builder but i cant access the sketch elements

also is it possible to create an alias for a sketch element such as a line?

looking for an alternative method i also cannot find a suitable tool to create a measurement between 2 end points of a line in a sketch, std measure is greyed out.

thanks
Grub
Posts: 303
Joined: Sun Nov 15, 2020 7:28 pm

Re: Use length of a sketch line in an expression

Post by Grub »

Like this ?
Attachments
Reference.gif
Reference.gif (652.53 KiB) Viewed 2738 times
teejay03830
Posts: 21
Joined: Mon Oct 12, 2020 4:08 pm

Re: Use length of a sketch line in an expression

Post by teejay03830 »

wow thank you for your time creating this giff. Yes this is the method i have discovered, aditionally selecting the reference checkbox when creating the sketch constraint makes it a dynamic constraint (measurement) that gets overridden by other constraints.
Last edited by teejay03830 on Sat Nov 28, 2020 5:45 pm, edited 2 times in total.
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: Use length of a sketch line in an expression

Post by chrisb »

It's a pleasure to see a newbie helping with such high quality!

A note for slightly speeding up such sketching: You don't need to select the endpoints in this case, you can simply select the line.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
teejay03830
Posts: 21
Joined: Mon Oct 12, 2020 4:08 pm

Re: Use length of a sketch line in an expression

Post by teejay03830 »

Still curious though about referencing a lines length directly without the creation of a constraint.
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: Use length of a sketch line in an expression

Post by chrisb »

teejay03830 wrote: Sat Nov 28, 2020 5:44 pm Still curious though about referencing a lines length directly without the creation of a constraint.
You need at least what is called a "driven constraint". In 0.19 you can check the box "Reference" when creating the constraint or toggle it later. Such constraints are shown in blue.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
asker
Posts: 33
Joined: Thu Sep 06, 2018 7:10 am

Re: Use length of a sketch line in an expression

Post by asker »

teejay03830 wrote: Sat Nov 28, 2020 5:44 pm Still curious though about referencing a lines length directly without the creation of a constraint.
You can do that

<<mySketch>>.Shape.Edge1.Length

Will give you the length of a line in your sketch. Just try Edge2, Edge3 and so on to find out which one is the one you are looking for.

Another method

If the line you are looking for is used to draw a shape then you can select the edge drawn using your line and refer to it, which will give the same value as your line. You can select the edge and use a ready made macro like the FCInfo to see the name of the edge you have selected, or try out different name numbers like in the previous method.

<<myShape>>.Shape.Edge9.Length

Note that the edge names turn out to be different for each method.
Also note that you need to start the address parts with capital letters.
greetings
Asker
User avatar
mfro
Posts: 663
Joined: Sat Sep 23, 2017 8:15 am

Re: Use length of a sketch line in an expression

Post by mfro »

asker wrote: Sat Aug 13, 2022 7:55 am <<myShape>>.Shape.Edge9.Length
You should avoid that if possible as it breaks very easily on sketch changes. References are much more robust.
Cheers,
Markus
asker
Posts: 33
Joined: Thu Sep 06, 2018 7:10 am

Re: Use length of a sketch line in an expression

Post by asker »

mfro wrote: Sat Aug 13, 2022 9:27 am
asker wrote: Sat Aug 13, 2022 7:55 am <<myShape>>.Shape.Edge9.Length
You should avoid that if possible as it breaks very easily on sketch changes. References are much more robust.
Sure, but the forum member asked specifically for that where you access data without having to name elements or creating constraints first.
I am using the method to pull out measurements into tables but not to drive sketches from tables.
Last edited by asker on Sat Aug 13, 2022 2:03 pm, edited 2 times in total.
greetings
Asker
bleber
Posts: 259
Joined: Thu Jun 30, 2016 5:12 pm

Re: Use length of a sketch line in an expression

Post by bleber »

There are a selection window that shows wat you are selected in case you need a line name in sketch and on 3d object
Post Reply