Macros recipes

From FreeCAD Documentation
Revision as of 04:39, 4 December 2018 by Vocx (talk | contribs) (Small changes in redaction and links to FreeCAD-macros repository)
Macros

This page contains macros to add functionality to your FreeCAD installation.

Macros

3D View operations

  • Macro Rotate View: This macro rotates the current view by 90° to the left. Only works if you are in Top view.
  • Macro View Rotation: Provides a GUI to permit rotation of view by precise amounts in all three directions.
  • Macro Texture Objects: This macro allows you to temporarily put a texture image on the selected objects.
  • Macro Mouse Cross: This small macro turns the arrow of the mouse in a precision cross.
  • Macro Align View to Face: This macro aligns the current view to a selected face.
  • Macro Align Object to View: This macro align the selected object to the current View and set the coordinates Placement of the camera.
  • Macro Align Camera to Working Plane: This macro aligns the camera to the current Draft Working Plane
  • Macro Align Working Plane to Camera: This macro moves the current Draft Working Plane to the center of the current view
  • Macro Align Face Object to View: This macro align the face of the selected object to the current View (in case face hole the hole is placed to the view).
  • Macro Toggle Panels Visibility: This macro toggles the visibility of various supporting panels in FreeCAD, allowing the main window to be viewed with all available screen space.
  • Macro FCCamera: This macro can rotate the screen in a defined angle and the defined axis and creates a plan to face the screen to create a form in the specified plan positions the selected face facing the screen, to detect the position of the camera.
  • Macro Toggle Visibility: Set of three macro, macro 1: hidden the objects not selected, macro 2: displayed alls objects, macro 3: hidden alls objects.
  • Macro Toggle Visibility2: Set of two macro, macro 1: hidden the objects not selected, macro 2: displayed alls objects, macro with the original visibility.
  • Macro SelectVisible: All visible objects in the tree will be selected.
  • Macro Manage Navigational Style: This pair of macros allow you to alter the Navigation Style while in the Sketcher.
  • Macro Duplicate Selection: This macro testing if one selection are duplicate , select the object IN THE 3D VIEW the "ForbiddenCursor" stay if the or one selection is duplicate, the macro stay resident.
  • Macro Copy3DViewToClipboard: Copy contents of 3DView resized 640, 480 px to clipboard .
  • Macro Perpendicular To Wire: This macro positioned your object perpendicularly to wire selected.
  • Macro Rotate To Point: Macro for rotate on object on itself with the axis of rotation the boundbox center, center of mass or last point clicked
  • Macro FCTreeView: Macro for list all objects in the project in one list without hierarchy, options sort by name, label, visibility, group, by length option search by name, label .... without case sensitive or with case sensitive and select all objects displayed in the macro window.
  • Macro Select Hovering: this macro select a choice Face, Edge, Vertex hovering by the mouse.
  • Macro ExpandTreeItem: this macro expand selected items in the tree view.. If not selection all item are expand/collapse
  • Macro Mouse over cb: this macro display all elements below cursor (elements covered by other elements will also be displayed)
  • Macro FC element selector: this macro display all elements below cursor same "Macro Mouse over cb" with GUI (elements covered by other elements will also be displayed)

Animation

Code and Scripting

  • Macro MessageBox: shows how to give information to the user through the GUI.
  • Qt Example: example of using Qt commands, their connections, extraction and data assignment.
  • Macro Python Assistant Window: This macro provides a cut/copy/paste workspace for Python code, it is segmented so different sections can be selected and it is persistent between FreeCAD sessions.
  • Macro Build Utility: This macro provides a utility to assemble a project from sub-project files using the Merge Project facility.
  • Macro Global Variable Watcher: This macro facilitates the user selecting global variables and monitoring their values.

Conversion

Drawing Workbench

The Drawing Workbench is considered obsolete since FreeCAD 0.17. Consider using the TechDraw Workbench instead.

  • Macro Automatic drawing: allows the user to get the view of his object in a drawing with 4 different position (front,top,iso,right). Needs some modification to be perfectly effective
  • Macro CartoucheFC: This GUI macro to fill simply all fields of the cartridge of the plan implementation worksheet FreeCAD, the format of the date and the symbol of the projection mode adapt to the EU region or US selected.
  • Macro CartoucheFC Full: This GUI macro to fill simply all fields of the cartridge templates_Full of the plan implementation worksheet FreeCAD, the format of the date and the symbol of the projection mode adapt to the EU region or US selected.
  • Macro CartoucheFC 2: This GUI macro to fill simply all fields of the cartridge model 2 of the plan implementation worksheet FreeCAD.
  • Macro Normal Vector: Get the normal vector of a preselected face for creating a drawing view normal to that face

Dxf 2D Draft

Fem

  • Macro GMSH: Create FEM Meshes by GMSH Mesh Generator

Info and measures

  • Macro FCInfo: Gives a series of information about the selected shape and can display a conversion of length, inclination (degrees, radian, grade) shape, surface, volume and the weight of the form in the density selected in various international and Anglo-Saxon units
  • Macro FCInfo Alternate Linux: same as above, but for Linux
  • Macro FCInfoGlass: Gives a series of information about the selected shape and displayed in screen 3D
  • Macro FCInfoToMouse: Provide informations coordinates, length and angles in real time on the mouse in a bubble annotation displayed in the 3D screen
  • Macro Delta xyz: Gives the Delta values and the distance between 2 points
  • Macro ObjectInfo: User-friendly "Info" module created by a FreeCAD user
  • Macro Dump Objects: This macro generates a listing of all objects in the current document - the list can be in a window or on the Report view.
  • Macro MeasureCircle: Compute the radius of a circle by 3 points or a circular edge.
  • Macro CenterOfMass: Gives the total mass and the center of mass of multiple objects selected with the density chosen.

Libraries

Mathematical functions

equations.

Multifunctional

  • Macro WorkFeatures: Tool utility to create plans of the axes, planes from 3 points, axes on a form, information on the coordinates of the shape and many other useful features to facilitate the creation of your project. This utility is up next in the combo view.

Object creation

  • Macro Make Cube: creates a rectangular cuboid from 4 points
  • Macro Solid Sweep: creates a solid by sweeping a 2D profile along a trajectory previously selected in the 3D view. The 2D elements can be created through the regular tools in FreeCAD's GUI.
  • Macro Geodesic Dome: This macro creates a geodesic dome shell
  • Macro Line Length: Create a line giving coordinate XYZ length and angle to plane X Y
  • Macro Cut Line: Cut a line and create x points, giving the number of points, create line or not, create points or not, create bicolor or not on choice.
  • Macro CirclePlus: Create a circle or arc giving radius, diameter, circumference, area, startangle, endangle, arc, anglecenter, cord, arrow, center (point) on choice (same below but with GUI) plus create sector and face.
  • Macro Circle: Create a circle or arc giving radius, diameter, circumference, area, startangle, endangle, arc, anglecenter, cord, arrow, center (point) on choice (same above without GUI).
  • Macro Cut Circle: Cut a circle or arc and create x arcs, giving the number of cut.
  • Macro Triangle AH: This macro create one triangle creates a triangle by giving the head angle and the height of the triangle (the triangle of the head is positioned to the xyz coordinates 0.0)
  • Macro Texture: Create a project from a bmp image to create a texture easily
  • Macro Loft: Create a loft with a list of wire (specially created for Macro Texture see above)
  • Macro Circular Text: This macro create a text around a cylinder
  • Macro WireXYZ: This macro creates a Wire with the coordinates extracted from a file. The coordinates X Y Z are separated by a space.
  • Macro Repro Wire: This macro reproduce all element selected subobject wire or face.
  • Macro Apothem Based Prism GUI: A GUI dialog that creates an Apothem, (inradius) Based Prism from user input.
  • Macro FCSpring Helix Variable: This macro create one spring truncate, the troncature is adjustable on the all coil to choice.
  • Macro Guitar fretboard: Guitar Fretboard Maker
  • Macro FCCamGroover: Creates grooved cylinder for cam.
  • Macro Site From Contours: creates an Arch Site from a series of contour lines

Object transformation

  • Macro ArrayCopy: copies the selected object several times, on an array grid
  • Macro FlattenWire: flattens draft wires that are not planar to their median Z coordinate
  • Macro FlattenWire3Points: flattens draft wires that are not planar to a plane defined by 3 points
  • Macro JointWire: allows to find and joint all non connected edge to the closest non connected one using a line
  • Macro Remove parametric history: removes all parametric associativity from an object, leaving it as a "dumb" shape
  • Macro SuperWire: Forces the creation of a Wire from lines and arcs that don't necessarily touch each other. Use this if normal wire operation fails
  • Macro HealArcs: Sometimes arcs are transformed into BSplines, for example when scale operations have been applied to them. This macro recreates valid arcs from them. Useful before exporting to dxf
  • Macro CloneConvert: Creates a clone of the object and the converted in the chosen position and size (inch, mm, m, µm...). The base object is recognized in mm (FreeCAd base)
  • Macro Image Scaling: Macro for easy scaling drawings, graphics, diagram, blueprint and similar 2D images in Image workbench.
  • Macro MatrixTransform: apply linear space transformations to distort shapes. E.g., non-uniform scaling, shearing, mirroring, axes swapping.
  • Macro Connect And Sweep: This macro easily creates a connection between two objects, an object and a point or between two points (the center of the objects are the starting and ending points of the sweep) can be selected form a configurable ellipse polygon circle
  • Macro Section: (parametric): alternative implementation of Part Section tool, more suitable for making sweep paths.
  • Macro Overlap: (parametric): Boolean operation. Similar to Part Common, but with custom overlap count threshold.

Printer 3D

Raytracing

Spreadsheet Workbench

  • Macro Alias Manager: helps managing aliases inside FreeCAD Spreadsheet workbench. It is able to create, delete, move aliases and create a 'part family' group of files.
  • Macro Spreadsheet Tools: This macro helps managing cells inside FreeCAD Spreadsheet workbench.
  • Macro FCTreeView: Macro for list all objects in the project in one list without hierarchy, options sort by name, label, visibility, group, by length option search by name, label .... without case sensitive or with case sensitive and select all objects displayed in the macro window.
  • Macro FCSpreadSheet Extract: This macro save the data in a csv file with the formula or in a xml file.

Utility

Wizards

  • Macro Sheet Metal Unfolder: Creates an unfolded part from a sheet-metal-part.
  • Macro Unroll Ruled Surface: allows to unroll ruled surfaces and to draw them on a page.
  • Macro Unfold Box: allows to unfold the surfaces of a box of any shape and to draw them on a page.
  • Macro Airfoil Import & Scale: Imports and scales a .dat airfoil to desired chord length.
  • Macro Geneva Wheel: Allows the user to create a Geneva wheel mechanism from scratch. Must edit values within the Macro to alter the size of the object.
  • Macro Geneva Wheel GUI: A GUI front end that allows the user to create a Geneva wheel mechanism from scratch.
  • Macro Cabinets32: creates side and top/bottom walls for a cabinet with drilled holes for connection parts of manufacturer Hettich.
  • Macro Half_turn_stairs: Creates a half turn (left/right) stair from a Data-file.
  • Macro Half-Hull Model: This macro generates both three dimensional half-hull and full-hull models from a series of 2D line drawings.
  • Macro Stairs: Create stair helix, create your stair nosing select and run the macro.
  • Macro FCGear: Additional Workbench to create different types of gears, involute gear, involute rack, cycloide gear, bevel gear.
  • Macro Corner shapes wizard: pops up a dialog asking for the dimensions of your corner piece, then creates the object in the document and creates a page view with top, front and lateral views of the piece
  • Macro PropertyMemo: This little macro create one Property additional (memo or other text) for you object (only Draft)

Other interesting macros created by FreeCAD users

  • By microelly2 : freeCAD_macro, geodata, Animation, freecad-nurbs, PieMenu, and more.
  • By hamish2014: FreeCAD_assembly2, FreeCAD_drawing_dimensioning, and more.
  • By triplus: IconThemes, ShortCuts, NavigationIndicator, TabBar, Launcher, PersistentToolbars, PieMenu, and more.
  • By rockn: FreeCAD-Timber, FreeCAD-addons, FreeCAD-library, FreeCAD-StructuresBois, and more.
  • By oddtopus: flamingo (workbench for metal structures).
  • By dprojects: getDimensions FreeCAD macro to get chipboards dimensions to cut (woodworking).
  • By Siardeni: workbench for create metal profiles, square tubing, z profile, palette, rotation, drawing, and more.
  • By realthunder: Assembly3 workbench, and more.


How to use

You can add macros to an existing FreeCAD installation. See How to install macros for a full description, and Customize toolbars for adding the macro to a toolbar for easy access.

Automatic installation

Starting with FreeCAD 0.17, use the Addon Manager (Tools → Addon manager) to install a macro that has been included in the FreeCAD-macros repository.

Manual installation

If the Addon Manager is not used, the macro can be installed manually.

  • Copy the Python code from the corresponding macro page.
  • Open the macros menu Macro → Macros, press Create, and give it a name.
  • Paste the Python code that you copied.
  • Press the Save button, and restart FreeCAD.
  • To use it, open again the macros menu, select your new macro, and press Execute.

Add a macro to a custom toolbar

You can add a button that launches a particular macro to a custom toolbar.

  • Go to Tools → Customize.
  • In the Macros tab, add a new macro name, and optionally define an icon and a keyboard shortcut.
  • In the Toolbars tab, create a new toolbar, and add your macro, taking it from the Macros category.

How to install macros and customize toolbars links in the infobox in each macro page

New macro page

Create a new page for the macro, starting with the word Macro_, for example, Macro Excellent Modification. The spaces are automatically converted to underscores.

In the new page, for example, Macro Excellent Modification, you should use Template:Macro at the top, with a minimum of information:

{{Macro
|Name=Macro_Excellent_Modification
|Description=This macro does excellent things on existing shapes
|Author=your username
|Date=2018-11-30
}}

You can add a custom icon if it doesn't have the same name as the macro; you can also add other information.

{{Macro
|Name=Macro_Excellent_Modification
|Icon=Macro_custom_icon.svg
|Description=This macro does excellent things on existing shapes
|Author=your username
|Date=2018-11-30
|Version=3.14516
|SeeAlso=[[Macro Regular Modification]]
}}

When translating the page, use a localized template. You need to specify the name with the two letter language code (/fr, /it, /de), and you need to add the icon specifically.

{{Macro/fr
|Name=Macro_Excellent_Modification
|Name/fr=Macro_Excellent_Modification
|Icon=Macro_Excellent_Modification.svg
|Description=(Translated description)
|Author=your username
|Date=2018-11-30
}}
  • Use Special:Upload to upload the custom icon in SVG or PNG formats. It should have the same name as the macro.
  • Otherwise it will default to Icon=Text-x-python.png, .

Code

Use Template:Code to place the code of the macro. It will use a monospace font and will preserve the white spaces that are essential for Python.

{{Code|code=

Your code should be here

}}

  • Document the way of using your macro in the same way the Gui Commands are documented.
  • Add one or more images to clarify what the macro does.
  • If the macro is complex, consider adding an animated GIF that shows its capabilities. The GIF image should have a maximum size of 500 x 500 pixels; if the GIF is bigger, the animation may not work. Do not resize the GIF as the wiki will not play resized GIFs.
  • Mention any tips and limitations of your macro, and the version of FreeCAD used to create it. This information can be gathered from Help → About FreeCAD → Copy to clipboard.
When this information is pasted, it looks like this
# OS: Ubuntu 18.04.1 LTS
# Word size of OS: 64-bit
# Word size of FreeCAD: 64-bit
# Version: 0.18.15302 (Git)
# Build type: Release
# Branch: master
# Hash: 2e03d2f298677b8212c22cbbc3cb20b7c80eabb5
# Python version: 2.7.15rc1
# Qt version: 4.8.7
# Coin version: 4.0.0a
# OCC version: 7.3.0
# Locale: English/UnitedStates (en_US)
  • Add header information to your code.
__Title__="Title_Of_macro"
__Author__ = "User_Name"
__Version__ = "00.11"
__Date__    = "2015-07-25"

__Comment__ = "This is the comment of the macro"
__Web__ = "http://forum.freecadweb.org/viewtopic.php?f=3&t=7384"
__Wiki__ = "http://www.freecadweb.org/wiki/index.php?title=Macro_Title_Of_macro"
__Icon__  = "/usr/lib/freecad/Mod/plugins/icons/Title_Of_macro"
__IconW__  = "C:/Documents and Settings/YourUserName/Application Data/FreeCAD"
__Help__ = "start the macro and follow the instructions"
__Status__ = "stable"
__Requires__ = "freecad 0.14.3706"
__Communication__ = "http://www.freecadweb.org/wiki/index.php?title=User:User_Name"

This information can be used by the addons_installer.FCMacro macro, or by the Plugin Loader program, to install the macro and check for new versions. Starting with FreeCAD 0.17, you don't have to use these programs any more, as the macros can be installed directly from the Addon Manager.

Adding the new macro to the list

Use Template:MacroLink to include a line in the appropriate category in this page, or create a new category if needed.

* {{MacroLink|Macro_Excellent_Modification|Macro Excellent Modification}}: the macro described in a short sentence.
  • The first argument is the name of the macro page in this wiki.
  • The second argument is the displayed text, which may be different from the page name.
  • What follows is a short description of the macro.
* {{MacroLink|Icon=Macro_Excellent_Modification.svg|Macro_Excellent_Modification|Macro Excellent Modification}}: the macro described in a short sentence.
  • The optional parameter Icon= may be given to specify the image file that will be used at the start of the line. The icons should be SVG or PNG files, and should have the same name as your macro. If this parameter is not given it will use the default icon for a Python script, .

Adding new macro page with macro code extra wiki

If your macro is too big (+64Ko) and does not fit in the wiki page, use the {{Codeextralink| xxx}} template by giving the address of the RAW page of the macro

The template must always be placed at the beginning of the page below the Description (must be the first code detected by the addonManager macro, in case there are code examples in the page, if a sample code is detected is this code that will be installed and not the code of the macro)

Example given:

{{Codeextralink|https://gist.githubusercontent.com/mario52a/8d40ab6c018c2bde678f/raw/e16ad9ea7b38c0c47e42aa3019be01dd1267a620/FCInfo_en_Ver_1-20_Docked.FCMacro}}

Example displayed in the macro page:

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://gist.githubusercontent.com/mario52a/8d40ab6c018c2bde678f/raw/e16ad9ea7b38c0c47e42aa3019be01dd1267a620/FCInfo_en_Ver_1-20_Docked.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://gist.githubusercontent.com/mario52a/8d40ab6c018c2bde678f/raw/e16ad9ea7b38c0c47e42aa3019be01dd1267a620/FCInfo_en_Ver_1-20_Docked.FCMacro")

Tutorials