Macro documentation: Difference between revisions

From FreeCAD Documentation
(→‎New macro page: Template:Macro will put the information on using and installing the macros in every page.)
(→‎Adding the new macro to the list: "Adding the new macro to the wiki repository" level 2 heading)
Line 138: Line 138:
This template must be placed at the beginning of the macro page, in the {{Emphasis|Description}} section. It must be the first block of code in the page so that the [[Addon Manager]] can automatically detect it and import it. See [[Macro CirclePlus]] for an example of the usage.
This template must be placed at the beginning of the macro page, in the {{Emphasis|Description}} section. It must be the first block of code in the page so that the [[Addon Manager]] can automatically detect it and import it. See [[Macro CirclePlus]] for an example of the usage.


=== Adding the new macro to the list ===
== Adding the new macro to the wiki repository ==


Use [[Template:MacroLink]] to include a line in the appropriate category in [[Macros recipes]]; create a new category if needed.
Use [[Template:MacroLink]] to include a line in the appropriate category in [[Macros recipes]]; create a new category if needed.

Revision as of 07:22, 4 December 2018

Description

All macros should be properly documented in the same way Gui Commands are documented. They should have an individual wiki page, and should be listed in one of the categories in Macros recipes.

The Macros recipes page has a good selection of macros created by experienced users, and many of them can be directly installed from the Addon Manager.

See GuiCommand model and macro pages like Macro Loft and Macro Site From Contours to see how macros should be documented. At least two sections should be included, a Description section with general usage information, and a Script section to hold the actual macro code. Other sections may be included as needed to explain with more detail the usage of the macro.

If a macro provides a well defined functionality, and is well documented, it could be included eventually as part of an existing workbench or a new one.

New macro page

Create a new page for the macro starting with the word Macro_, for example, Macro_Excellent_Modification. The link can be used without underscores as [[Macro Excellent Modification]], which results in Macro Excellent Modification; the spaces are automatically converted to underscores.

In the new page 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 fields of 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 indicate the icon explicitly.

{{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 .

Template:Macro will put the information on using and installing the macros in every page.

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


Adding the macro documentation

  • Just like a Gui Command, explain what the macro does, its inputs, outputs, options, and limitations, if any.
  • Add one or more images to clarify its usage.
  • If the macro performs a complex task, 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 related macros and workbenches that complement the function of this macro.
  • Mention the version of FreeCAD used to create the macro. 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)

Consider adding this information in a comment block inside the code of the macro.

Adding the macro code

Inside the Script section, use Template:Code to place the code of the macro in the page. This will create a block of text that uses monospace font, which will preserve the whitespace that is essential for Python.

{{Code|code=

«Your code should be here»

}}

Add header information before your actual code.

{{Code|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" 

«Your code should be here»
}}

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, this information is also used by the Addon Manager, which downloads the macro from the FreeCAD-macros repository.

Adding macro code outside of the wiki

If your macro is too big that it exceeds 64 KB, it won't be able to be hosted on the wiki. In this case, use Template:Codeextralink with a link to the raw web address of the code.

For example:

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

It will be displayed as:

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")


This template must be placed at the beginning of the macro page, in the Description section. It must be the first block of code in the page so that the Addon Manager can automatically detect it and import it. See Macro CirclePlus for an example of the usage.

Adding the new macro to the wiki repository

Use Template:MacroLink to include a line in the appropriate category in Macros recipes; 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 the 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 icon should be an SVG or a PNG file, 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, .