Macros recipes
Tutorial |
Topic |
---|
Macros |
Level |
Beginner |
Time to complete |
Authors |
FreeCAD version |
Example files |
See also |
None |
This page contains macros to add functionality to your freecad installation
Macros
3D View operations
- Template:MacroLink/sv Detta makro roterar den nuvarande vyn med 90° åt vänster. Fungerar endast om du är i toppvyn.
Animation
- Macro crank simul: Rotation rod and piston
- Macro Spring: Simulation of one spring
- Macro hinge: Open and close hinge
- Macro Assembly: Assembly animate
- Macro Animated Constrain: Animate angle constrain in sketcher
- Macro Assemblage Imprimante 3D: Simulation of movements of a 3D printer
- Macro Constraint Draft: Simple example animation Draft wires by use the Expressions for associate many wires and simulate or verify the movement. Here the circle rotation create the movement for all objects connected
- Macro Rubik Cube: Display a Rubik Cube and interactively do slice rotations.
Code and Scripting
- Macro MessageBox: shows how to give information to the user through the GUI.
- 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
- Konvertera Nät till Delar: Detta makro konverterar valda nät till delar. Det har en bred tolerans, så använd det bara med objekt som inte har några kurvor, annars kommer du att få konstiga resultat.
Drawing Workbench
- 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
- Macro Rectellipse: creates a parametric rectellipse
- Macro Make Circle 3 Points: creates a circle on 3 selected points, the points can be objects (this example brings together the two examples below, all parameters simply settle on a graphic window).
- Macro Draft Circle 3 Points: creates a circle from 3 selected points 2D orthogonal
- Macro Draft Circle 3 Points 3D: creates a circle from 3 selected points in the space 3D
- Macro Make Arc 3 Points: creates a arc from 3 selected points
- Macro Ellipse-Center+2Points Makes an ellipse by selecting three points (in this order): centre, major radius and minor radius
- Macro FCConvertLines: this macro convert the object line, wire in line Dash, DashDot, DashDotDot,ZigZag and Hand with the dimensions given.
- Macro EdgesToArc: Converts the selected Edges to a circular Arc if possible. Useful for restoring discretized arcs.
- Macro Creating faces from a DXF file: This macro create face from a DXF file, the "Layer" are recognized separate and trained in groups.
- Macro DXF to Face and Sketch: This macro converts selected elements of imported dxf to face and sketch.
- Macro_Compound_Plus: Draf command set in a small macro for the 2D sketch example: work with the DXF files.
- Macro Dxf To Shape: Macro utility for create unique wire with many wires, the type wire created is selected to MakeWire, Bspline, BsplineCurve, BsplineCurve + Arc, Polygon, Bezier curve
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
- Macro screw maker1_2: This macro creates a screw with or without thread, according to ISO standards (screw_maker1_6.py.zip with Pyside support). (Screw Maker 2.0 - new version!)
- Macro BOLTS: The aim of BOLTS is to build a free and open-source standard parts library for CAD applications.
- Macro PartsLibrary: Starts the Parts library browser
Mathematical functions
- Macro 3D Parametric Curve: Draw a function described by parametric equations x(t), y(t) and z(t).
- Macro Draw 2D Function: draws a function described by an equation z=F(x)
- Macro Draw Parametric 2D Function: Based on the above macro, but for parametric and optionally polar
- Macro WorkFeatures: Tool utility : Tab > Wire > Curves And Surfaces Launch Curves and Surfaces Menu ...
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 cutLine: 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 cutCircle: Cut a circle or arc and create x arcs, giving the number of cut.
- Macro triangleAH: 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 FCTexture: Create a project from a bmp image to create a texture easily
- Macro FCCreaLoft: Create a loft with a list of wire (specially created for Macro Texture see above)
- Macro FCCircularText: 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 ReproWire: 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
- Template:MacroLink/sv: Detta makro kopierar det valda objektet flera gånger på ett rutnät. Du kan definiera antalet rader, kolumner och avståndet mellan dem. Du behöver ha pyqt installerat.
- Template:MacroLink/sv: Detta makro plattar ut ritlinjer som inte är parallella (i Z-axeln) till deras median Z koordinat.
- Template:MacroLink/sv: Detta makro hittar alla oanslutna kanter och kopplar ihop dem med den närmaste oanslutna genom att använda en linje.
Det har en matrisform i inmatningen ( [shape1,shape2,...]).
Printer 3D
- Macro 3d Printer Slicer: Exports current design to slicer software or CAM software.
Raytracing
- Macro FreeCAD to Kerkythea: Export from FreeCAD to Kerkythea
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 SpreadsheetTools: 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
- Macro CenterFace: This macro red trace (editable) the center face (mass) with 1 point and print the coordinates
- Macro Center Align Objects with Faces or Edges: This macro covers the following constraints: - Concentric constraint among non cylindrical parts; - Constraint on center Faces and/or Edges. It works also with the new Body and App::Part containers, as well as with STEP hierarchy.
- Macro Easy cutouts for Enclosure Design: This macro makes Cutouts for Enclosures in a very handy way
- Macro MacroMenu: Add the macros found in the macros folder to the Macros menu of FreeCAD
- Macro ForceRecompute: Forces manual recompute of model
- Macro Recompute Profiler: measures time it takes to recompute each object in a project
- Macro Shake Sketch: Shake a sketch in order to discover its unconstrained parts.
- Macro Replace Part in Assembly: Replaces a part (simple copy) in an "Assembly" with another Part (simple copy).
- Macro Toggle Drawstyle: This macro toggles the Drawstyle of the selected object
- Macro HighlightCommon: Highlight common parts.
- Macro HighlightDifference: Compute the difference between two shapes.
- Macro cross section: displays an interactively slidable cross-section.
- Macro Print_SceneGraph: prints the SceneGraph.
- Macro BoundingBox Tracing: This macro red trace (editable) around the BoundingBox with 6 rectangles
- Macro Arch Axis System Repartition: This macro help you to create an Arch Axis System along a line with a
- Macro Perpendicular To Wire: This macro positioned your object perpendicularly to wire selected.
- Macro merge duplicate materials: Merges materials that have the same base name (with different numeral endings like 001, 002,...) into one.
- Macro Unbind Numpad Shortcuts: rebinds standard view commands from digit keys to Ctrl+digit, so that they don't spin the view by accident when entering numbers.
- Macro findConfigFiles: finds user config files system.cfg and user.cfg, copies folder location to system clipboard, instructs user on renaming these files in order to reset FreeCAD settings, and opens folder with default file browser.
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, ..... other
- By hamish2014: FreeCAD_assembly2, FreeCAD_drawing_dimensioning, ...
- By triplus: IconThemes, ShortCuts, NavigationIndicator, TabBar, Launcher, PersistentToolbars, PieMenu, ....
- By rockn: FreeCAD-Timber, FreeCAD-addons, FreeCAD-library, FreeCAD-StructuresBois, .... other
- 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 ...
- By realthunder: workbench FreeCAD_assembly3 ... other
How to use?
The above macros can easily be plugged on any FreeCAD installation
- Starting from FreeCAD v 0.17, a new Tools → Addons Manager allows you to easily install any macro from this page. The instructions below must still be followed if your version of FreeCAD doesn't have the Addons Manager yet.
- Copy the macro python code from the corresponding macro page
- In FreeCAD, Macro → Macros → Create new, and give it a name
- Paste the python code you copied
- Hit the Save button, and restart FreeCAD
- Open the Macro manager, select your new macro and click "execute"
- Tutorial How to install macros
Additionally, you can also add your new macro to a custom toolbar
- In FreeCAD, go to Tools → Customize
- In the Macros tab, add a new macro, and, if you like, 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.
- Tutorial Customize Toolbars
Adding new macros to this repository
- Create a new page, beginning its name with "Macro", for example "Macro_My_Excellent_Macro", this can be done simply by editing this page, and adding a new link to your macro, like this:
- example :
* {{MacroLink|Text-x-python|Macro My Excellent Macro|Macro My Excellent Macro title}} : My excellent macro description.
- Text-x-python : icon by default (replace with your name icon with the exact same name as your macro page if there is. The format always .png only)
- Macro My Excellent Macro : macro name
- Macro My Excellent Macro title : macro name or title
A new page (red link) will be created.
- In that page, paste the following text:
(With the default icon)
{{Macro|Icon=Text-x-python|Name=Macro_My_Excellent_Macro|Description=What my excellent macro does|Author=your username|Version=1.0|Date=YYYY-MM-DD}
(With the icon custom)
{{Macro|Icon=Macro_My_Excellent_Macro|Name=Macro_My_Excellent_Macro|Description=What my excellent macro does|Author=your username|Version=1.0|Date=YYYY-MM-DD}}
(Another language with the default icon (example "/fr" "/de" "/it"....))
{{Macro/fr|Icon=Text-x-python|Name=Macro_My_Excellent_Macro|Name/fr=Macro_My_Excellent_Macro|Description= What my excellent macro does|Author=your username|Version=1.0|Date=YYYY-MM-DD}
(Another language with the icon custom (example "/fr" "/de" "/it"....))
{{Macro/fr|Icon=Macro_My_Excellent_Macro|Name=Macro_My_Excellent_Macro|Name/fr=Macro_My_Excellent_Macro|Description= What my excellent macro does|Author=your username|Version=1.0|Date=YYYY-MM-DD}}
- You can also Upload a custom format icon.png
Note that the name of the icon must have the same name as the name of the macro.
- Paste your macro, and use the Code template to avoid adding spaces into your script. This will display the macro in a monospace font inside a light grey box like the example above.
- If you like, upload a .png icon with the exact same name as your macro page (ex. Macro_My_Excellent_Macro.png)
- Add an image: an image is useful to show what the macro does. Optionally you can create an animated gif that represents the object in context. The gif image should have a maximum size of 500x500px as the wiki does not resize animated gifs; if the gif is any bigger the animation won't work.
- Optionally you can add some more info on how to use your macro, tips, limitations and workaround.
- It is also interesting to include version information in your macro. This macro allows you to locate in time compared to the evolution of FreeCAD, do "Menu → Help → About FreeCAD and click to Copy to clipboard" and paste it your macro
Ex:
#OS: Windows Vista
#Platform: 32-bit
#Version: 0.14.3389
#Python version: 2.6.2
#Qt version: 4.5.2
#Coin version: 3.1.0
#SoQt version: 1.4.1
#OCC version: 6.5.1
It is also advisable to create a macro in your header, this header can be used by the Plugin Loader program to install the macro and check versions. Also available addons_installer.FCMacro
Ex:
__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"
- Add it to the above categories, create a new category if needed.
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")