Draft Point: Difference between revisions

From FreeCAD Documentation
(Improved the code)
(Remove external API link as this information is already in Draft API)
Line 40: Line 40:


==Scripting== <!--T:11-->
==Scripting== <!--T:11-->
{{emphasis|See also:}} [[FreeCAD Scripting Basics]], [[Draft API]], and the [https://www.freecadweb.org/api autogenerated API documentation].
{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].


<!--T:12-->
<!--T:12-->

Revision as of 21:40, 12 November 2018

Draft Point

Menu location
Draft → Point
Workbenches
Draft, Arch
Default shortcut
P T
Introduced in version
0.7
See also
Draft Line, Draft Wire

Description

The Point tool creates a simple point in the current work plane, handy to serve as reference for placing lines, wires, or other objects later. It uses the Draft Linestyle (only the color) set on the Draft Tray.

How to use

  1. Press the Draft Point button, or press P then T keys.
  2. Click a point on the 3D view, or type a coordinate and press the add point button.

Options

  • To enter coordinates manually, simply enter the numbers, then press Enter between each X, Y and Z component. You can press the add point button when you have the desired values to insert the point.
  • Press T or click the checkbox to toggle continue mode. If continue mode is on, the point tool will restart after you place a point, allowing you to place another one without pressing the tool button again.
  • Press Esc or the Close button to abort the current command.

Properties

  • DataX: the X coordinate of the point.
  • DataY: the Y coordinate of the point.
  • DataZ: the Z coordinate of the point.

Scripting

See also: Draft API and FreeCAD Scripting Basics.

The Point tool can be used in macros and from the Python console by using the following function:

Point = makePoint(X=0, Y=0, Z=0, color=None, name="Point", point_size=5)
Point = makePoint(point, Y=0, Z=0, color=None, name="Point", point_size=5)
  • Creates a Point object in the specified X, Y and Z coordinates, with units in millimeters. If no coordinates are given the point is created at the origin (0,0,0).
    • If X is a point defined by a FreeCAD.Vector, it is used.
  • color is a tuple (R, G, B) that indicates the color of the point in the RGB scale; each value in the tuple should be in the range from 0 to 1.
  • name is the name of the object.
  • point_size is the size of the object in pixels, if the graphical user interface is loaded.

Example:

import random, FreeCAD, Draft

Point1 = Draft.makePoint(1600, 1400, 0)

p2 = FreeCAD.Vector(-3200, 1800, 0)
Point2 = Draft.makePoint(p2, color=(0.5, 0.3, 0.6), point_size=10)

# Make a loop and create ten points with random coordinates that extend
# from -L to L on both X and Y. Also choose a random color and size.

# Change value to define the area covered by the points
L = 1000
centered = FreeCAD.Placement(FreeCAD.Vector(-L,-L,0), FreeCAD.Rotation())
Rectangle = Draft.makeRectangle(2*L, 2*L, placement=centered)

for i in range(10):
    x = 2*L*random.random() - L
    y = 2*L*random.random() - L
    z = 0
    r = random.random()
    g = random.random()
    b = random.random()
    size = 15*random.random() + 5
    Draft.makePoint(x, y, z, color=(r, g, b), point_size=size)