FreeCAD Logo FreeCAD 1.0
  • English Afrikaans Arabic Belarusian Catalan Czech German Greek Spanish Spanish Basque Finnish Filipino French Galician Croatian Hungarian Indonesian Italian Japanese Kabyle Korean Lithuanian Dutch Norwegian Bokmal Polish Portuguese Portuguese Romanian Russian Slovak Slovenian Serbian Swedish Turkish Ukrainian Valencian Vietnamese Chinese Chinese
  • Features
  • Download
  • Blog
  • Documentation
    Documentation index Getting started Users documentation The FreeCAD manual Workbenches documentation Python coding documentation C++ coding documentation Tutorials Frequently asked questions Privacy policy About FreeCAD
  • Contribute
    How to help Sponsor Report a bug Make a pull request Jobs and funding Contribution guidelines Developers handbook Translations
  • Community
    Code of conduct Forum The FPA GitHub GitLab Codeberg Mastodon Matrix IRC IRC via Webchat Gitter Discord Reddit Twitter Facebook LinkedIn Calendar
  • ♥ Donate

Donate

$
SEPA Information
Please set up your SEPA bank transfer to:
Beneficiary: The FreeCAD project association
IBAN: BE04 0019 2896 4531
BIC/SWIFT: GEBABEBBXXX
Bank agency: BNP Paribas Fortis
Address: Rue de la Station 64, 1360 Perwez, Belgium

While Stripe doesn't support monthly donations, you can still become a sponsor! Simply make a one-time donation equivalent to 12 months of support, and you'll gain access to the corresponding sponsoring tier. It's an easy and flexible way to contribute.

If you are not sure or not able to commit to a regular donation, but still want to help the project, you can do a one-time donation, of any amount.

Choose freely the amount you wish to donate one time only.

You can support FreeCAD by sponsoring it as an individual or organization through various platforms. Sponsorship provides a steady income for developers, allowing the FPA to plan ahead and enabling greater investment in FreeCAD. To encourage sponsorship, we offer different tiers, and unless you choose to remain anonymous, your name or company logo will be featured on our website accordingly.

from 1 USD / 1 EUR per month. You will not have your name displayed here, but you will have helped the project a lot anyway. Together, normal sponsors maintain the project on its feet as much as the bigger sponsors.

from 25 USD / 25 EUR per month. Your name or company name is displayed on this page.

from 100 USD / 100 EUR per month. Your name or company name is displayed on this page, with a link to your website, and a one-line description text.

from 200 USD / 200 EUR per month. Your name or company name and logo displayed on this page, with a link to your website and a custom description text. Companies that have helped FreeCAD early on also appear under Gold sponsors.

Instead of donating each month, you might find it more comfortable to make a one-time donation that, when divided by twelve, would give you right to enter a sponsoring tier. Don't hesitate to do so!

Choose freely the amount you wish to donate each month.

Please inform your forum name or twitter handle as a notein your transfer, or reach to us, so we can give you proper credits!

Macro Sketch Constraint From Spreadsheet

Description
Macro which, with a simple click on a spreadsheet cell, adds a length constraint to a line, a circle, or between 2 points using a spreadsheet cell alias or address (ex. C2). Future changes to the spreadsheet will update the constraint. The macro can create alias for you.
Just select 1 line, 2 points or a constraint, click on a spreadsheet cell and run the macro. You can select lines, points at the ends of a line, points, circles or arcs of circles.


Macro version: 02.03
Last modified: 2025/10/27
FreeCAD version: All
Download: ToolBar icon
Author: 2cv001
Author
2cv001
Download
ToolBar icon
Links
Macros recipes
How to install macros
How to customize toolbars
Macro Version
02.03
Date last modified
2025/10/27
FreeCAD Version(s)
All
Default shortcut
None
See also
None

Description

Contact me on the FreeCAD forum in case of any problems.

Macro which, with a simple click on a spreadsheet cell, adds a length constraint to a line or between 2 points using a spreadsheet cell alias or address (ex. C2). Future changes to the spreadsheet will update the constraint. The macro can create alias for you.

Just select 1 line, 2 points or a constraint, click on a spreadsheet cell and run the macro. You can select lines, points at the ends of a line, points, circles or arcs of circles.

Temporary code for external macro link. Do not use this code. This code is used exclusively by Addon Manager. Link for optional manual installation: Macro


# This code is copied instead of the original macro code
# to guide the user to the online download page.
# Use it if the code of the macro is larger than 64 KB and cannot be included in the wiki
# or if the RAW code URL is somewhere else in the wiki.

from PySide import QtGui, QtCore

diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,
    "Information",
    "This macro must be downloaded from this link\n"
    "\n"
    "https://raw.githubusercontent.com/2cv001/FreeCAD-macros/master/Spreadsheet/Sketch_Constraint_From_Spreadsheet.FCMacro" + "\n"
    "\n"
    "Quit this window to access the download page")

diag.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()

import webbrowser 
webbrowser.open("https://raw.githubusercontent.com/2cv001/FreeCAD-macros/master/Spreadsheet/Sketch_Constraint_From_Spreadsheet.FCMacro")
<class="rawcodeurl"><a href="https://raw.githubusercontent.com/2cv001/FreeCAD-macros/master/Spreadsheet/Sketch_Constraint_From_Spreadsheet.FCMacro">raw code</a>


Usage

Automatic object creation

If you run the macro and have not yet created a spreadsheet, a body or a sketch, the macro suggests to create one and then opens the sketch in edition mode and the spreadsheet so that you can start filling it.

Automatic alias creation

It is not mandatory, but it is better to use aliases in your spreadsheet. The macro can create aliases from texts in cells.
Two modes:

  • a manual mode where you select yourself the cells with text for alias and an automatic mode.
  • and an automatic mode:

Automatic mode

An automatic mode where alias are automatically created using a text zone defined by a cell. The zone includes the cell and those below. These texts correspond to the alias name. The alias is created to the right of its text. The designated cell (here A3) is editable in these dialog boxes:

Alias automatic creation

Alias automatic creation Alias automatic creation

Manual mode

To use manual mode don't check the "Automatic alias" option.

Alias creation

Alias creation

Constraints creation

1) Select:

  • a line,
  • two points (end of a line, center of a circle, etc.)
  • or a length constraint.

2) Click on a spreadsheet cell, with or without an alias, that has a numerical value:

3) Run the macro.

4) Select the desired type of constraint:

If the cell has an alias, the length property of the constraint will be something like 'Spreadsheet.alias'. Otherwise, something like 'Spreadsheet.D4'.

5) If the constraint causes a conflict in the sketch and the "conflict detection" box is checked, the macro will offer to delete the new constraint:

If you select an existing constraint, you can change its value for a value from a spreadsheet:

The macro can also handle external geometry from another sketch:

To make things even more refined, if, for example, a line is horizontal rather than vertical, when the dialogue box opens, the focus will be on the button for apply a horizontal constraint. If the line is vertical rather than horizontal, the focus will be on the button to apply a vertical constraint. In both cases, simply press the enter key if you are happy with this choice.

The macro also works for Objects properties. If you click, for example, on the Length property of a Pad, and then on a cell with the desired value, the Length property of the pad is automatically modified.

You can use formulas

Principle: The macro transforms the alias before inserting it into the parameter or dimension expression. It replaces keywords with operations for everything following the character string f (f for function).

Example of usage:

If your alias is: radius_f__mul_2_plu_1
The expression will be:
<<datas>>.radius_f__mul_2_plu_1 * 2 + 1
Thus, if you have, for instance, the value 5 in the cell, the parameter or dimension will take the value 5 * 2 + 1, which equals 11.

A snippet of the code showing possible operations and formulas to use:

formulaSeparator = '_f_'
dicoFormula = {
    '_div_':'/',
    '_mul_':'*',
    '_plu_':'+',
    '_mor_':'+',
    '_les_':'-',
    '_moi_':'-',
    '_pg_':'(',
    '_lp_':'(',
    '_pd_': ')',
    '_rp_': ')',
}

Radius → diameter

A checkbox lets you divide the value by 2 directly in the formula. This is very handy, for example, when you want to enter a diameter that will be converted into a radius. A typical case is a line in a sketch used as the profile for a revolution.

Links

  • Forum discussion (French)
  • Forum discussion (English)
  • Macros recipes
  • How to install macros
  • How to customize toolbars

Credits

Thanks to openBrain, mario52 and onekk for their help on the code!
Thanks to Syres for tests, reviews and help in the code.
Thanks to Roy043 and David69 for the various reviews and improvements to the wiki.
Thanks to L'ami René for tests and ideas.

Script

ToolBar Icon

Code

ver 02.03 2025/10/27 by 2cv001 Macro_Sketch_Constraint_From_Spreadsheet.FCMacro

Download

Download latest version of the macro

This page is retrieved from https://wiki.freecad.org/Macro_Sketch_Constraint_From_Spreadsheet

Get in touch!
Forum GitHub Mastodon Matrix IRC Gitter.im Discord Reddit Twitter Facebook LinkedIn

© The FreeCAD Team. Homepage image credits (top to bottom): ppemawm, r-frank, epileftric, regis, rider_mortagnais, bejant.

This project is supported by: , KiCad Services Corp. and other sponsors

GitHubImprove this page on GitHub