Draft Workbench: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
Line 37: Line 37:
* All newly created objects adopt current Draft [[Draft Linestyle|color and width]]
* All newly created objects adopt current Draft [[Draft Linestyle|color and width]]
* The Draft module also has its [[Draft Preferences|preferences]] screen
* The Draft module also has its [[Draft Preferences|preferences]] screen

===API===

{{:Draft API}}


{{docnav|Raytracing Module|Image Module}}
{{docnav|Raytracing Module|Image Module}}

Revision as of 00:06, 12 July 2010

The draft Module is a work-in-progress and quite experimental module made to add basic 2d drawing functionality to FreeCAD. It is written entirely in python, and is also intended to showcase how far you can extend FreeCAD entirely in python, without even touching the source code.

Currently it is not really usable for production work, but already contains a couple of working basic functions. Feel free to test, and give us a feedback on the discussion page.

The draft interface with the buttons toolbar and the function toolbar
The draft interface with the buttons toolbar and the function toolbar

The draft workbench is available in your workbenches list. When you activate it, two toolbars will appear; a classical toolbar containing the standard draft commands listed below and a special command bar that has no tool icon on it, but that is used by the different functions to display their controls. On that command bar, you can also change general things like current line color and width. As a sidenote, the command bar (and, IMHO, the whole QT interface) looks much better if you choose the "cleanlooks" style in FreeCAD general preferences...

Tutorial

For an in-depth explanation, read the Draft tutorial (work in progress), or read the quickstart section below to get you quickly on rails.

Quickstart

Not all Draft commands work well in 3D at the moment. So, the best thing to do is to put yourself in orthographic 2D view before starting to draw. To do that, open or create a new document, then press the O key (or menu view -> orthographic view) to switch to orthographic mode. Then press the 2 key (or menu view -> standard views -> top) to put you in top view. Now, you are ready to draw. You can also configure freecad (menu edit -> preferences) to always start in orthographic mode.

All draft commands follow more or less the same rules: Drawing tools will ask you to pick points on the screen or enter numeric coordinates, while modification tools will ask you to choose an object to work on first, in case no object is selected. In almost all commands, pressing the CTRL key will allow you to snap to existing points, SHIFT will constrain your movement horizontally, verically or in relation to an existing segment, and in some tools ALT will give you extra options such as creating a new object instead of transforming an existing one. The ESC key will always cancel the active command.

Some commands work in non-horizontal planes too, just make sure the Z coordinate is unlocked when drawing, and place yourself in the appropriate view. Below you will find a more complete description of all available tools.

Importing & exporting

These are functions for opening, importing or exporting other file formats. Opening will open a new document with the contents of the file, while importing will append the file content to the current document. Exporting will save the selected objects to a file. If nothing is selected, then all objects will be exported. Be aware that since the purpose of the Draft module is to work with 2d objects, those importers focus only on 2d objects, and, although DXF and OCA formats do support objects definitions in 3D space (objects are not necessarily flat), they won't import volumetric objects like meshes, 3D faces, etc, but rather lines, circles, texts or flat shapes. Currently supported file formats are:

Template:Draft Tools

Common behaviours

  • Snapping: Allows to place new points on special places on existing objects
  • Constraining: Allows to place new points horizontally or vertically in relation to previous points
  • Working with manual coordinates: Allows to enter manual coordinates instead of clicking on screen
  • Copying: All modification tools can either modify the selected objects or create a modified copy of them. Pressing ALT while using the tool will make a copy
  • Construction Mode: Allows you to put geometry apart from the rest, for easy switch on/switch off
  • All newly created objects adopt current Draft color and width
  • The Draft module also has its preferences screen

API

<translate>

(November 2018) This information may be incomplete and outdated. For the latest API, see the autogenerated API documentation.

These functions are part of the Draft Workbench and can be used in macros and from the Python console once the Draft module has been imported.

Example: </translate>

import FreeCAD, Draft

myrect = Draft.makeRectangle(4, 3)
mydistance = FreeCAD.Vector(2, 2, 0)
Draft.move(myrect, mydistance)

<translate>

cut(FreeCAD.Object, FreeCAD.Object)

Description: Returns a cut object made from the difference of the 2 given objects. The original objects get hidden.

Returns: The newly created object

extrude(FreeCAD.Object, Vector)

Description: Extrudes the given object in the direction given by the vector. The original object gets hidden.

Returns: The newly created object

formatObject(FreeCAD.Object, [FreeCAD.Object])

Description: This function applies to the given target object the current properties set on the Draft toolbar (line color and line width), or copies the properties of a second object if provided. It also places the object in construction group if the construction button is pressed.

Returns: Nothing

fuse(FreeCAD.Object, FreeCAD.Object)

Description: Returns an object made from the union of the 2 given objects. If the objects are coplanar, a special Draft Wire is used, otherwise the final object is a standard Part fuse.

Returns: The newly created object

getDraftPath([string])

Description: Returns the user or system path where the Draft module is running from. If a subpath or a filename is supplied, the full path to the subpath inside the Draft module is returned.

Returns: A file path

getGroupContents(list)

Description: Scans recursively the given list for groups. If groups are encountered, their contents are appended to the list.

Returns: A list of FreeCAD Objects

getRealName(string)

Description: Strips the trailing numbers from an object name.

Returns: The stripped object name

getSelection( )

Description: Returns the current FreeCAD selection.

Returns: The current FreeCAD selection.

makeCircle(radius, [placement], [facemode], [startangle], [endangle])

Description: Creates a circle object with given radius. If a placement is given, it is used. If facemode is False, the circle is shown as a wireframe, otherwise as a face. If startangle AND endangle are given (in degrees), they are used and the object appears as an arc.

Returns: The newly created object.

makeDimension(Vector, Vector, [Vector] or FreeCAD.Object, int, int, [Vector])

Description: Creates a Dimension object measuring distance between first and second vectors, with the dimension line passign through the third vector if provided. The current line width and color from the Draft toolbar will be used. Instead of 2 vectors, you can also pass a FreeCAD object, and two integers (and optionally a vector where the dimension line must pass). In that case, the dimension will be associated with the object, and measure two of its vertices, indicated by the two given indice numbers.

Returns: The newly created object.

makeLine(Vector, Vector)

Description: Creates a line between the two given vectors. The current line width and color from the Draft toolbar will be used.

Returns: The newly created object.

makeRectangle(length, width, [placement], [facemode])

Description: Creates a Rectangle object with length in X direction and height in Y direction. If a placement is given, it is used. If facemode is False, the rectangle is shown as a wireframe, otherwise as a face. The current line width and color from the Draft toolbar will be used.

Returns: The newly created object.

makeText(string or list, [Vector], [screenmode])

Description: Creates a Text object, at the given point if a vector is provided, containing the string or the strings given in the list, one string by line. The current color from the Draft toolbar and the text height and font specified in preferences are used. If screenmode is True, the text always faces the view direction, otherwise it lies on the XY plane.

Returns: The newly created object.

makeWire(list or Part.Wire, [closed], [placement], [facemode])

Description: Creates a DWire object from the given list of vectors or from the given Wire. If closed is True or if first and last points are identical, the wire is closed. If facemode is True (and wire is closed), the wire will appear filled. The current line width and color from the Draft toolbar will be used.

Returns: A new Draft DWire (not a Part Wire).

move(FreeCAD.Object or list, Vector, [copymode])

Description: Moves the given object or the objects contained in the given list in the direction and distance indicated by the given vector. If copymode is True, the actual objects are not moved, but copies are created instead.

Returns: The object(s) (or their copies if copymode was True).

precision( )

Description: Returns the precision value from Draft user settings.

Returns: An integer.

rotate(FreeCAD.Object or list, angle, [center], [axis] ,[copymode])

Description: Rotates the given object or the objects contained in the given list with the given angle around the given center if provided, using axis as a rotation axis. If axis is omitted, the rotation will be around the vertical Z axis. If copymode is True, the actual objects are not moved, but copies are created instead.

Returns: The objects (or their copies).

scale(FreeCAD.Object or list, vector, [center], [copymode])

Description: Scales the given object or the objects contained in the given list with a scale factors defined by the given vector (in X, Y and Z directions) around the given center if provided. If copymode is True, the actual objects are not moved, but copies are created instead.

Returns: The objects (or their copies).

select(FreeCAD.Object)

Description: Deselects everything and selects only the passed object

Returns: Nothing.

shapify(FreeCAD.Object)

Description: Transforms a parametric shape object into non-parametric.

Returns: The new object.

draftify(FreeCAD.Object or list)

Description: Turns the given object or each object of the given list into Draft parametric wires.

Returns: Nothing.

getSVG(FreeCAD.Object, [linemodifier], [textmodifier], [(u,v)])

Description: Creates a SVG representation of the given object. The linemodifier attribute is a scale factor (in percents) for line width, and textmodifier for text size. You can also optionally provide a tuple of vectors to define a projection plane, otherwise the geometry will be projected on the XY plane.

Returns: a string containing a SVG representation of the given object.

</translate>

Raytracing Module
Image Module