Macro Line Length: Difference between revisions

From FreeCAD Documentation
mNo edit summary
(Use {{MacroCode}})
 
(21 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Text-x-python|Name=Macro Line Length|Description=Creates a line giving as an argument the XYZ coordinates, length, and angle.|Author=mario52}}
|Name=Macro Line Length
|Icon=Macro_Line_Length.png
|Description=Create a line giving as an argument the XYZ coordinates, length, and angle. The new line is created in the real coordinate of object, not in the coordinate of the Body.<br/>{{ColoredText|(Command line, paste this complete macro in the Python console)}}.
|Author=mario52
|Version=02.00
|Date=2014-08-08
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/b/bd/Macro_Line_Length.png ToolBar Icon]
}}


<!--T:2-->
==Description== <!--T:2-->
This small macro create a line giving as an argument the XYZ coordinates, length, and angle
This small macro create a line giving as an argument the XYZ coordinates, length, and angle


===Use=== <!--T:3-->
==Usage== <!--T:3-->
Can be used from the Freecad macro editor.
Can be used from the Freecad macro editor.


<!--T:4-->
<!--T:4-->
the default values are : x1 = 0, y1 = 0, z1 = 0, length = 10, angle = 0
If the macro is copied in the Python console, you can you can use it by:
</translate>


==Script== <!--T:7-->
<syntaxhighlight>
>>> line_length(x1 = 0, y1 = 0, z1 = 0, length = 10, angle = 45)
</syntaxhighlight>
<translate>

<!--T:5-->
or choice
</translate>
</translate>


ToolBar Icon [[Image:Macro_Line_Length.png]]
<syntaxhighlight>
>>> line_length(x1 = 10, y1 = 10, z1 = 0, length = 50)


'''Macro Line_Length.py'''
>>> line_length(length = 50, angle = 45)
</syntaxhighlight>
<translate>


{{MacroCode|code=
<!--T:6-->
the default values are : x1 = 0, y1 = 0, z1 = 0, length = 10, angle = 0

===Script=== <!--T:7-->
Macro Line_Length.py
</translate>

<syntaxhighlight>
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# créer une ligne avec une coordonnée une longueur et un angle sur le plan X Y
# créer une ligne avec une coordonnée une longueur et un angle sur le plan X Y
Line 43: Line 36:
from math import cos, sin, radians
from math import cos, sin, radians
#from FreeCAD import Base
#from FreeCAD import Base

def line_length(x1 = 0, y1 = 0, z1 = 0, length = 10, angle = 0):
def line_length(x1 = 0.0, y1 = 0.0, z1 = 0.0, length = 10.0, angle = 0.0):
x2 = x1 + (length * cos(radians(angle)))
x2 = x1 + (length * cos(radians(angle)))
y2 = y1 + (length * sin(radians(angle)))
y2 = y1 + (length * sin(radians(angle)))
Line 50: Line 43:
Draft.makeWire([FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x2,y2,z2)])
Draft.makeWire([FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x2,y2,z2)])


#Example:
x1 = 0.0 # Edit coordinate x1 origin
y1 = 0.0 # Edit coordinate y1 origin
#x1 = 0.0 # Edit coordinate x1 origin
z1 = 0.0 # Edit coordinate z1 origin
#y1 = 0.0 # Edit coordinate y1 origin
length = 50 # Edit length
#z1 = 0.0 # Edit coordinate z1 origin
angle = 45 # Edit angle plane XY
#length = 50.0 # Edit length
#angle = 45.0 # Edit angle plane XY
#line_length(x1, y1, z1, length, angle)


}}
line_length(x1, y1, z1, length, angle)

</syntaxhighlight>
{{clear}}
{{clear}}

<languages/>
<translate>

==Example== <!--T:8-->

<!--T:9-->
If the macro is copied in the Python console, you can use it by:
</translate>

{{Code|code=
>>> line_length(x1 = 0, y1 = 0, z1 = 0, length = 10, angle = 45)
}}
<translate>

<!--T:10-->
or choice
</translate>

{{Code|code=
>>> line_length(x1 = 10, y1 = 10, z1 = 0, length = 50)

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

Latest revision as of 00:42, 8 May 2020

Other languages:

Macro Line Length

Description
Create a line giving as an argument the XYZ coordinates, length, and angle. The new line is created in the real coordinate of object, not in the coordinate of the Body.
(Command line, paste this complete macro in the Python console).

Macro version: 02.00
Last modified: 2014-08-08
FreeCAD version: All
Download: ToolBar Icon
Author: mario52
Author
mario52
Download
ToolBar Icon
Links
Macro Version
02.00
Date last modified
2014-08-08
FreeCAD Version(s)
All
Default shortcut
None
See also
None

Description

This small macro create a line giving as an argument the XYZ coordinates, length, and angle

Usage

Can be used from the Freecad macro editor.

the default values are : x1 = 0, y1 = 0, z1 = 0, length = 10, angle = 0

Script

ToolBar Icon

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

#Example:
#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)


Example

If the macro is copied in the Python console, you can use it by:

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

or choice

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

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