How to create a new TechDraw template

Contents

  • 00:21 Introduction
  • 00:52 Creating the sample part
  • 01:43 Introduction to InkScape
  • 02:13 Setting the template page size
  • 02:37 Creating a basic template
  • 04:44 Testing the template without editable text
  • 04:59 Making the text editable (almost)
  • 06:36 Testing the updated template in FreeCAD
  • 07:04 Adding the last ingredient for editable text
  • 07:20 More testing in FreeCAD
  • 07:32 What happens if the text is rotated?
  • 08:45 Using line styles, etc

Glasson Design Studio2022. All rights reserved.

FreeCAD's TechDraw workbench comes with a number of predefined templates that you can use, but what do you do if you want a custom template? You can modify an existing template, or you can create your own. I'm going to show you how you can create your own from scratch.

It's a fairly straightforward process that requires the use of another program that allows you to create and modify drawings stored in SVG files. We use InkScape to do this. You could use something else if you prefer. InkScape is available on Windows, Mac, and Linux.

InkScape website

https://inkscape.org

InkScape allows you to create sophisticated drawings and edit the XML1 which forms the basis of the SVG structure. This means that applications such as InkScape can attach additional information to the graphical elements in the file which FreeCAD can use when displaying the file.

You can create a static template that does not allow the user to modify the text in the template or you can create a template that allows the user to insert their own descriptive text into the text fields that you have defined as being editable.

Important

You can tell the difference between a static template and one that allows you to edit the text items by looking for a small green square next to the text item. You can click on the green square to open a dialogue box that allows you to change the text. A text item without a green square CANNOT be edited.

Creating a new template

The process of creating a new template is straightforward, but you need to give some thought to how it is going to look before you start. These are the steps that you'll need to follow to create the template.

  1. Create the blank template
  2. Set the page size
  3. Place each of the graphical items in the template
  4. Set the colours, line styles, fonts, etc.

Warning

There is a limitation in FreeCAD version 0.19's TechDraw Workbench that prevents it correctly displaying editable which have an attribute called <transform>. The TechDraw Workbench does not seem to handle the transformation properly and strange results can occur. 2

In the case of editable text items, the limitation reveals itself by drawing the green square some distance away from the text item itself, and may not be visible when you have zoomed in.

It may be best to limit your editable text elements to a horizontal orientation.

The template you've just created can now be used but it WILL NOT allow you to edit any of the text in it. We find it useful to create a new drawing using the new templatein a FreeCAD model so that we can confirm that it looks the way we expect it to and make any changes prior to making the text editable. You don't have to do this.

Making FreeCAD aware of the customisable text fields

The template that you've just created is a static template because the user cannot edit the text items in it. The TechDraw Workbench does not know how to display them so that they can be edited. You'll need to use InkScape's XML Editor to add the XML attributes that the TechDraw Workbench is looking for.

 

Important

Insert unadorned text item image representing the whole SVG file here. FLOAT IT RIGHT

 

The XML structure of the SVG file is shown in the image on the right. An XML file is made up of tags that describe the settings or graphical items in the drawing. The TechDraw Workbench requires that a special attribute be added to the editable text items, as well as another special attribute attached to the top level <svg> tag.

A text item is made editable in the TechDraw Workbench by adding an attribute called <freecad-editable> to the <text> tag. The first image above shows the text item without the attribute added, and the second image shows the text item with the attribute added. You can set the title of the attribute to be whatever you want, but we choose to make it something meaningful such as the name of the field, the required format of a date field, etc.

Important

Insert unadorned text item image here

Important

Insert adorned text item image here

 

You need to add a <freecad-editable> attribute to every text item that you want to be able to edit.

Adding the <freecad-editable> attribute to each text element is not the only thing that needs to be done to complete the template. The TechDraw Workbench won't understand the <freecad-editable> attributes until you add the FreeCAD namespace to the XML file element - in this case, the <svg> tag.

This is done by adding the <xmlns:freecad> attribute to the <svg> tag, and setting its value to be http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace. The first image above shows the <svg> tag without the attribute and the second image shows it with <svg> tag with it. The TechDraw Workbench will now recognise the editable text items and draw a green box next to them, allowing you to edit the text item.

Important

Insert unadorned SVG tag here

Important

Insert the adorned SVG tag image here

 

Other embellishments

The SVG file allows you a high level of control over the look of the template which means that you can include logos, other images, special fonts, line styles, line weights, etc. You can create simple templates like we do, or you could get a graphic artist to help you design a template that is consistent with your organisations branding.

Links

  • 1Checkout the link at the bottom of the article for more informationabout XML
  • 2It could actually be FreeCAD that has this limitation instead of the TechDraw Workbench but it manifests itself in the TechDraw Workbench which is why we mention it here.