Macro Line Length

From FreeCAD Documentation
Revision as of 19:48, 8 August 2014 by FuzzyBot (talk | contribs) (Updating to match new version of source page)

File:Text-x-python Macro Line Length

Description
Creates a line giving as an argument the XYZ coordinates, length, and angle.

Author: mario52
Author
mario52
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Cette petite macro crée une ligne en donnant comme argument, ces coordonnées de départ XYZ, sa longueur et un angle

Utilisation

Peut être utilisée dans l'éditeur de macro de FreeCAD.

Si la macro est copiée dans la console Python intégrée de FreeCAD la commande reste accessible tant que FreeCAD est ouvert et peut être utilisée en faisant :

>>> line_length(x1 = 0, y1 = 0, z1 = 0, length = 10, angle = 45)

ou au choix

>>> line_length(x1 = 10, y1 = 10, z1 = 0, length = 50)

>>> line_length(length = 50, angle = 45)

Les valeurs par défaut sont : x1 = 0, y1 = 0, z1 = 0, length = 10, angle = 0

Script

Macro Line_Length.py

# -*- coding: utf-8 -*-
# créer une ligne avec une coordonnée une longueur et un angle sur le plan X Y
# create line with coordinate length and angle to plane X Y
import FreeCAD, FreeCADGui, Draft
from math import cos, sin, radians
#from FreeCAD import Base
 
def line_length(x1 = 0.0, y1 = 0.0, z1 = 0.0, length = 10.0, angle = 0.0):
    x2 = x1 + (length * cos(radians(angle)))
    y2 = y1 + (length * sin(radians(angle)))
    z2 = z1 #+ ()
    Draft.makeWire([FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x2,y2,z2)])
 
x1 = 0.0          # Edit coordinate x1 origin
y1 = 0.0          # Edit coordinate y1 origin
z1 = 0.0          # Edit coordinate z1 origin
length = 50.0       # Edit length
angle  = 45.0       # Edit angle plane XY
 
line_length(x1, y1, z1, length, angle)
Other languages: