Define Constant

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!
Post Reply
Konni
Posts: 4
Joined: Sat Jun 25, 2016 2:05 pm

Define Constant

Post by Konni »

Hi there,
I am looking for a way to define and use constants for a model.
In a model all the drill hole have a radius of 3mm. And there several of hole.
How to define a constant for the model? And how to use a defined constant in a sketch?
Is there also the possibility to change this radius later on to an other radius?

Has anbody an idea? I'am realy new to FreeCad.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Define Constant

Post by DeepSOIC »

Hi!
Use spreadsheet.
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Define Constant

Post by NormandC »

Hello Konni,

Welcome to FreeCAD and the forum.

If your holes are all in the same sketch, you can apply an Image equality constraint between all circles, and add a Image radius constraint to a single circle.

Another method is the following: let's say you've added a sketch with circles, then created a pocket feature on your part. You now apply a new sketch on the face of your pocket feature, to create a new set of holes. You can use the Image External Geometry tool to link the edge of one of the existing holes, and apply an equality constraint between it and the circles in your sketch.

One more thing: are your holes set in a regular pattern (linear or radial)? Then it will be quicker to sketch and pocket a single one, then create a transformation feature like Image Linear Pattern, Image Polar Pattern or Image MultiTransform.
Konni wrote:Is there also the possibility to change this radius later on to an other radius?
Of course. If it's defined by a radius constraint in a sketch, just edit the sketch then change the value of the radius constraint. If defined in a Spreadsheet as suggested by DeepSOIC, just change the value in the spreadsheet. See Spreadsheet Workbench for more info.

Don't hesitate to ask questions, but please also post your FreeCAD info as detailed in the link from that big red banner at the top, you can't possibly miss it (yet you apparently did). That way we can be sure you have the latest version available.
Konni
Posts: 4
Joined: Sat Jun 25, 2016 2:05 pm

Re: Define Constant

Post by Konni »

Thanks for your answers.
Here is the info of my version:
OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6703 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: 2ce5c8d2e3020d05005ed71f710e09e9aa561f40
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17

Realy interessting is what DeepSOIC said:
Use spreadsheet
But how?
In the tutorial it is only said, how to do calulation and stuff like this.
But there is no hint how to reference cell values in a sketch.
If I make a circle in a sketch and make a radius constraint. Can I write something like:
SpreadscheetName.A2
,like I would do in Excel?
That was my first though. But all your values in a spreadsheet and use them in a sketch. But I do not know how.
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Define Constant

Post by NormandC »

Konni wrote:But there is no hint how to reference cell values in a sketch.
I was sure it was documented in the Spreadsheet Workbench wiki page, or the Expressions page, but it does not look to be the case.

I attached a simple example with a sketch and a spreadsheet. Steps to recreate:
  1. Create sketch, draw a rectangle, you can constrain it now or later
  2. Swith to the Spreadsheet workbench, create a spreadsheet
  3. Double click on the Spreadsheet object in the Model tree to open it
  4. Select a cell, then create an alias for it by clicking on the tool in the toolbar. AFAIK it's the only way to use a cell content with the Expressions engine. Actually this step is unnecessary, using the cell ID like "A4" works. You can also right-click on a cell, select Properties, and go to the "Alias" tab. Once a cell has an alias, its background turns to yellow. Enter a numerical value in the cell.
  5. Repeat with a second cell.
  6. Edit the sketch.
  7. Add a horizontal distance constraint to the rectangle. When the dialog pops up to set the numerical value, click on the blue Expressions icon f(x) at the right of the field.
  8. Type in Spreadsheet.Name, where "Name" is the alias of the cell you want to link. In the attached file, I created two aliases, "Length" and "Width".
  9. Click OK to close the Expressions dialog, then OK again to close the "Insert length" dialog.
  10. Close the sketch and change the cell values in the spreadsheet. The sketch will automatically update.
Edit: as added above, I just tested it, no need to add an alias to use a cell content in Expressions. Typing A4, B12 works. Still, creating an alias makes it easier to manage, if aliases have meaningful names.
Attachments
sketch & spreadsheet example_normandc1.fcstd
(6.52 KiB) Downloaded 75 times
Konni
Posts: 4
Joined: Sat Jun 25, 2016 2:05 pm

Re: Define Constant

Post by Konni »

Thank you very much.
That is what I was looking for.
FreeCad is a very good tool.
Post Reply