# Difference between revisions of "Python Solution to Dimension Tracking"

Russ hensel (talk | contribs) (→Use) |
Russ hensel (talk | contribs) |
||

Line 1: | Line 1: | ||

− | This is about half written, if interested email '''[[User:Russ_hensel]]''' | + | This is about half written, if interested email '''[[User:Russ_hensel]]''' And since written it has been substantially expanded and revised. I will return to this documentation soon, I hope. |

## Latest revision as of 06:52, 17 March 2017

This is about half written, if interested email **User:Russ_hensel** And since written it has been substantially expanded and revised. I will return to this documentation soon, I hope.

# The Problem[edit]

To make FreeCad work you often need to enter values of various dimensions. There does not seem to be a method internal to FreeCad ( and probably there should not be ). These dimensions come from various sources:

- Spec. sheets.
- Measurements
- Calculations
- Design decisions.

You more or less need some notes to keep track of this stuff. Some of this may be paper sketches, paper notes, and digital documents ( many may choose spreadsheets ). I find spreadsheets to be very error prone so I looked for a python solution. The very simple version of this is shown in: FreeCad Gear Box This has now evolved, and this document will describe the solution. For the actual code contact: User:Russ_hensel

# A Python Solution[edit]

My Python solution consists of a set of interacting classes:

## PartDimension[edit]

This class holds a single dimension. Of course you can just go: a_dimention = 22. What is wrong with that? This dimension has a name and a value. What it does not have is units or a type that may help distinguish between pure numbers ( teethe on a gear ), angles, and linear dimensions. Also I have upgraded the class so that it does easy unit conversions and is easy to print.

Here is what you might get when you print a PartDimension:

print a_dimension output: bolt_sep ( mm ) = 25.0

And here is what you get with a fairly fancy getter method:

In: a_dimention = PartDimension( "part name two", dim_type = "linear", radial = False, value = 27.3, units = "in") print( a_dimention ) print( a_dimention.get_value( units = "ft" ) ) Out: part name two ( mm ) = 693.42 2.275

A couple of implementation details.

- Dimensions are always stored in some base units, linear in mm, angles in radians, the getter methods convert to the desired units. There are a couple of helper classes for the conversion:

- LinearConverter
- AngleConverter

## PartInfo[edit]

Of course a part does not have a dimension it has many dimensions. So PartInfo is a collection of Part Dimensions all of which can be manipulated as a unit. There are methods to:

- Support naming of PartInfos ( say "My Gear # 3 " ).
- Add a dimension ( or a set of dimensions ).
- Access dimensions or there values one by one or as a unit.
- Print out all the part dimensions in any particular set of units.

## PartStack[edit]

This is a collection of PartInfo items, the idea is that this represents several parts that are stacked up to be 3D printed as a unit. Perhaps more detail later.

# Use[edit]

I am still working this out but here is an approach:

- In an empty file import the code above ( now cad.py )
- Write a function to generate a PartInfo object. I call my first one something like my_standards_factory:

# --------------------------------------------- def standards_42_factory(): """ this holds standards """ a_part = cad.PartInfo( "Cad Standards #42 " ) a_part.freecad_name = "standards_42" a_part.create_part_dimension( "washer_thick", dim_type = "linear", radial = False, value = .1 ) a_part.create_part_dimension( "gear_clear", dim_type = "linear", radial = False, value = .2 ) a_part.create_part_dimension( "gear_thick", dim_type = "linear", radial = True , value = 4.5 ) a_part.create_part_dimension( "plate_thick", dim_type = "linear", radial = False, value = 2.0 ) ....... more

- and use it:

my_standards = standards_42_factory() my_standards.print_part()

The print is just to verify the factory.

Then ....... more coming .....