[Solved] Is there an easy way to get the length of a b-spline

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

[Solved] Is there an easy way to get the length of a b-spline

Post by jfc4120 »

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.2.29177 +426 (Git)
Build type: Release
Branch: (HEAD detached from 0.20.2)
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * Help 1.0.3
I am looking for a way (simply way) to get the length of a b-spline but not using the curves workbench. Any suggestions?

Only post I have seen is viewtopic.php?t=55155

But it just gives 0.00. Okay I tried Macro FCInfo https://wiki.freecad.org/Macro_FCInfo got the length.
Last edited by jfc4120 on Thu Mar 23, 2023 12:33 am, edited 1 time in total.
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Is there an easy way to get the length of a b-spline

Post by edwilliams16 »

Any edge, b-spline or anything:

Select in the 3D view.
Edit|Send to python console (or ctl-shift-P)
sub.Length in the console.

EDIT
or install @dan-miel 's QuickMeasure tool. It is really handy.
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: [Solved] Is there an easy way to get the length of a b-spline

Post by jfc4120 »

Got it, select first, rt click, send to python console:

Code: Select all

doc.getObject("BSpline002")
>>> shp = obj.Shape
>>> sub = obj.getSubObject("Edge1")
>>> ### End command Std_SendToPythonConsole
>>> sub.Length
396.5090127490411
>>> 
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: [Solved] Is there an easy way to get the length of a b-spline

Post by chrisb »

jfc4120 wrote: Wed Mar 22, 2023 11:35 pm Only post I have seen is viewtopic.php?t=55155
The macro doesn't work reliably while you are in Sketcher's edit mode.
You have to select the spline in 3D view, and not the sketch in the tree.

So yes, there are some restrictions :cry: .
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: [Solved] Is there an easy way to get the length of a b-spline

Post by mario52 »

Hi

example of macro to use in sketcher open : How to select edges inside of Sketcher?

Code: Select all

if Gui.ActiveDocument.getInEdit().Object.TypeId == 'Sketcher::SketchObject':
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: [Solved] Is there an easy way to get the length of a b-spline

Post by chrisb »

mario52 wrote: Thu Mar 23, 2023 10:28 am

Code: Select all

if Gui.ActiveDocument.getInEdit().Object.TypeId == 'Sketcher::SketchObject':
Thanks for this! I have bookmarked your post for reuse when I rework the small macro. I had already tried once to make it skethcer aware and finally decided to go for the non sketcher version.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: [Solved] Is there an easy way to get the length of a b-spline

Post by mario52 »

Hi

i have include the code in my macro FCInfo (line 2957) and adapted for it

Code: Select all

            if (Gui.ActiveDocument.getInEdit() and (sketch.TypeId == "Sketcher::SketchObject")) and ("Constraint" not in subElemName): # sketcher open
the codes worked by chrisb, openBrain, edi, drmacro, abdullah, paullee ... allowed me to give info in a sketcher open and add it to my macro

thanks all

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply