Peepsalot's measurement tools

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!
peepsalot
Posts: 50
Joined: Sun Nov 13, 2011 9:44 pm

Peepsalot's measurement tools

Postby peepsalot » Wed Nov 30, 2011 6:18 am

Hello, I've been experimenting with some FreeCAD Python scripts to help with the task of analyzing 3D models such as imported meshes, and I thought I'd show them off here. I'm pretty new to the CAD world, but been programming for many years. I'm having a blast learning how all this works and everything that is possible with FreeCAD. :)

The following scripts will not work directly on a Mesh object, since individual edges and vertices of a mesh are not selectable.
If you want to measure a mesh (ex. imported STL) then you will need to convert it to a Part first by using the menu: "Part" -> "Create shape from mesh..."

Place any of the downloaded python files into your FreeCAD macros directory and execute it from FreeCAD.

MeasureCircle.py
Determine the radius and center of a circle by selecting any 3 points on the edge of it, with the calculation result displayed in the Report View. A line is also drawn from the first vertex to the center, which can then be used with FreeCAD's builtin "Measure Distance" tool if needed to determine the distance from the center to other features.

After executing this script, the next three vertices you select will be used to calculate dimensions of a corresponding arc or circle. Subsequent uses require executing the script again or instantiating the class in Python Console with "MeasureCircle()"

Image

I just got this working and will probably make some changes to it in the future. I may eventually try to add a real toolbar icon to the gui to make invoking this tool a bit easier, just haven't gotten that far yet.

Protractor.py
For measuring the angle between two edges. Usage is similar to MeasureCircle, just select the edges, and the result is printed in Report View.
Currently does not offer any visual indicator. I'm considering trying to display an arc and text label of the angle degrees(similar to the objects shown by the Measure Distance tool), but haven't figured that out yet.

These scripts are still a work in progress, and I will be adding to and updating these scripts as I go.
Last edited by peepsalot on Thu Dec 01, 2011 4:21 am, edited 3 times in total.
User avatar
yorik
Site Admin
Posts: 11567
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Peepsalot's measurement tools

Postby yorik » Wed Nov 30, 2011 5:56 pm

Congrats peepsalot, that's a very well written script, IMHO (better than the draft module actually ;) )

A couple of tips you might find useful:

- line 17 can also be written like this, since in FreeCAD OCC vertices always have a Point attribute which returns a FreeCAD vector, and they can be compared with ==:

Code: Select all

if p.Point == v.Point:
The toVector() method you can also remove and use the Point attribute above.

- and instead of using Part.show(line), you can also do:

Code: Select all

obj = FreeCAD.ActiveDocument.addObject("Part::Feature","tempLine")
obj.Shape = line
It's a matter of taste, the above code gives you a bit more control (for ex. you can give it a name)
jmaustpc
Posts: 9566
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Peepsalot's measurement tools

Postby jmaustpc » Thu Dec 01, 2011 12:28 am

Peepsalot, Yorik,

I think this looks great.

It would be great if you can make these tools, to be included in 0.13?



Jim
peepsalot
Posts: 50
Joined: Sun Nov 13, 2011 9:44 pm

Re: Peepsalot's measurement tools

Postby peepsalot » Thu Dec 01, 2011 12:49 am

Thanks Yorik. I edited the code to take in your suggestions. I was actually wondering how I would assign a name to those lines anyways.
peepsalot
Posts: 50
Joined: Sun Nov 13, 2011 9:44 pm

Re: Peepsalot's measurement tools

Postby peepsalot » Thu Dec 01, 2011 4:22 am

Added a basic protractor script to the first post.
foff44
Posts: 6
Joined: Fri Nov 18, 2011 8:36 am

Re: Peepsalot's measurement tools

Postby foff44 » Thu Dec 01, 2011 10:03 am

peepsalot wrote:Hello, I've been experimenting with some FreeCAD Python scripts to help with the task of analyzing 3D models such as imported meshes, and I thought I'd show them off here. I'm pretty new to the CAD world, but been programming for many years. I'm having a blast learning how all this works and everything that is possible with FreeCAD. :)

The following scripts will not work directly on a Mesh object, since individual edges and vertices of a mesh are not selectable.
If you want to measure a mesh (ex. imported STL) then you will need to convert it to a Part first by using the menu: "Part" -> "Create shape from mesh..."

Place any of the downloaded python files into your FreeCAD macros directory and execute it from FreeCAD.

MeasureCircle.py
Determine the radius and center of a circle by selecting any 3 points on the edge of it, with the calculation result displayed in the Report View. A line is also drawn from the first vertex to the center, which can then be used with FreeCAD's builtin "Measure Distance" tool if needed to determine the distance from the center to other features.

After executing this script, the next three vertices you select will be used to calculate dimensions of a corresponding arc or circle. Subsequent uses require executing the script again or instantiating the class in Python Console with "MeasureCircle()"

Image

I just got this working and will probably make some changes to it in the future. I may eventually try to add a real toolbar icon to the gui to make invoking this tool a bit easier, just haven't gotten that far yet.

Protractor.py
For measuring the angle between two edges. Usage is similar to MeasureCircle, just select the edges, and the result is printed in Report View.
Currently does not offer any visual indicator. I'm considering trying to display an arc and text label of the angle degrees(similar to the objects shown by the Measure Distance tool), but haven't figured that out yet.

These scripts are still a work in progress, and I will be adding to and updating these scripts as I go.
Hi,
I have a small problem, I have looked everywhere and I don't have a Macros folder in the FreeCAD directory, I have done a system wide search and cannot find it anywhere.
Shouldn't it have been installed when the progamme was installed?
Do I need to install it separately ?

I am running FreeCAD 0.12
Build 5186
Win7 32-Bit
wmayer
Site Admin
Posts: 14899
Joined: Thu Feb 19, 2009 10:32 am

Re: Peepsalot's measurement tools

Postby wmayer » Thu Dec 01, 2011 10:13 am

Hi,
I have a small problem, I have looked everywhere and I don't have a Macros folder in the FreeCAD directory, I have done a system wide search and cannot find it anywhere.
Shouldn't it have been installed when the progamme was installed?
Do I need to install it separately ?

I am running FreeCAD 0.12
Build 5186
Win7 32-Bit
A macro directory is something that doesn't get installed. It's simply a directory By default it points to the directory %APPDATA%\FreeCAD. It's then up to you to put your macros there. The supported file extensions are .FCMacro and .py. Under Tools > Macros you can change your macro directory to something else.
User avatar
yorik
Site Admin
Posts: 11567
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Peepsalot's measurement tools

Postby yorik » Mon Dec 05, 2011 2:21 pm

peepsalot wrote:Added a basic protractor script to the first post.
I actually did something similar in the Draft module... Try drawing 2 lines, then select the dimension tool ,then ALT-select the 2 lines. I didn't use it a lot, though, so it might still be a little buggy, but it might give you some ideas.
galou_breizh
Posts: 259
Joined: Wed Sep 15, 2010 9:38 am

Re: Peepsalot's measurement tools

Postby galou_breizh » Fri Apr 08, 2016 7:48 pm

@peepsalot: I modified your macro in order to be able to select also an circular edge and also to be able to first make the selection and then launch the macro. Please have a look at http://www.freecadweb.org/wiki/index.ph ... sureCircle and tell me what you think.

Gaël