Macro Make Arc 3 Points: Difference between revisions

From FreeCAD Documentation
m (date)
(Use {{MacroCode}})
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Macro_Make_Arc_3_Points|Name=Macro Make Arc 3 Points|Description=Creates a arc from 3 selected points.|Author=Mario52|Version=01.00|Date=14/07/2016}}
|Name=Macro Make Arc 3 Points
</translate>
|Icon=Macro_Make_Arc_3_Points.png
<translate>
|Description=Creates a arc from 3 selected points.
|Author=Mario52
|Version=02.00
|Date=2019-07-29
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/9/92/Macro_Make_Arc_3_Points.png ToolBar Icon]
}}

==Description== <!--T:2-->
==Description== <!--T:2-->
This macro creates a arc on 3 selected points.
This macro creates a arc on 3 selected points.

</translate>
==Usage== <!--T:3-->
<translate>
==Use== <!--T:3-->
Launch the macro, select 3 points, the arc is created and the coordinates and the length of the arc are displayed in the report view.
Launch the macro, select 3 points, the arc is created and the coordinates and the length of the arc are displayed in the report view.


Line 14: Line 22:
(PS: It is not required to hold down the Ctrl key)
(PS: It is not required to hold down the Ctrl key)


</translate>
<translate>
==Script== <!--T:4-->
==Script== <!--T:4-->
The icon for the toolBar [[File:Macro Make Arc 3 Points.png|36px]]
The icon for the toolBar [[File:Macro Make Arc 3 Points.png|36px]]


</translate>
</translate>
Macro_Make_Arc_3_Points.FCMacro
'''Macro_Make_Arc_3_Points.FCMacro'''


{{Code|code=
{{MacroCode|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from FreeCAD import Base
from FreeCAD import Base
Line 29: Line 35:
__author__ = "Mario52"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.01"
__version__ = "00.02"
__date__ = "14/07/2016"
__date__ = "29/07/2019"


global selected; selected = []
global selected; selected = []
Line 36: Line 42:


class SelObserver:
class SelObserver:
print "Create Arc to 3 points ..."
print( "Create Arc to 3 points ...")
def addSelection(self,doc,obj,sub,pnt): # Selection
def addSelection(self,doc,obj,sub,pnt): # Selection
global selected
global selected
selected.append(pnt)
selected.append(pnt)
if len(selected) == 1:
if len(selected) == 1:
print "Point 1 : ",FreeCAD.Vector(selected[0])
print( "Point 1 : ",FreeCAD.Vector(selected[0]))
elif len(selected) == 2:
elif len(selected) == 2:
print "Point 2 : ",FreeCAD.Vector(selected[1])
print( "Point 2 : ",FreeCAD.Vector(selected[1]))
elif len(selected) == 3:
elif len(selected) == 3:
print "Point 3 : ",FreeCAD.Vector(selected[2])
print( "Point 3 : ",FreeCAD.Vector(selected[2]))
try:
try:
C1 = Part.Arc(FreeCAD.Vector(selected[0]),FreeCAD.Vector(selected[1]),FreeCAD.Vector(selected[2]))
C1 = Part.Arc(FreeCAD.Vector(selected[0]),FreeCAD.Vector(selected[1]),FreeCAD.Vector(selected[2]))
Line 52: Line 58:
Part.show(W)
Part.show(W)
App.ActiveDocument.ActiveObject.Label = "Arc_3_Points"
App.ActiveDocument.ActiveObject.Label = "Arc_3_Points"
print "Length : ",W.Length
print( "Length : ",W.Length)
except Exception:
except Exception:
print "Three points are collinear or bad selection"
print( "Three points are collinear or bad selection")
del selected[:]
del selected[:]
FreeCADGui.Selection.removeObserver(s)
FreeCADGui.Selection.removeObserver(s)
print "End Make_Arc_3_Points"
print( "End Make_Arc_3_Points")
print "_____________________"
print( "_____________________")


s=SelObserver()
s=SelObserver()
FreeCADGui.Selection.addObserver(s)
FreeCADGui.Selection.addObserver(s)



}}
}}
<languages/>

Latest revision as of 23:46, 7 May 2020

Other languages:

Macro Make Arc 3 Points

Description
Creates a arc from 3 selected points.

Macro version: 02.00
Last modified: 2019-07-29
FreeCAD version: All
Download: ToolBar Icon
Author: Mario52
Author
Mario52
Download
ToolBar Icon
Links
Macro Version
02.00
Date last modified
2019-07-29
FreeCAD Version(s)
All
Default shortcut
None
See also
None

Description

This macro creates a arc on 3 selected points.

Usage

Launch the macro, select 3 points, the arc is created and the coordinates and the length of the arc are displayed in the report view.

(PS: It is not required to hold down the Ctrl key)

Script

The icon for the toolBar

Macro_Make_Arc_3_Points.FCMacro

# -*- coding: utf-8 -*-
from FreeCAD import Base

__title__   = "Macro_Make_Arc_3_points"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.02"
__date__    = "29/07/2019"

global selected; selected = []
App = FreeCAD

class SelObserver:
    print( "Create Arc to 3 points ...")
    def addSelection(self,doc,obj,sub,pnt):  # Selection 
        global selected
        selected.append(pnt)
        if len(selected) == 1:
            print( "Point 1 : ",FreeCAD.Vector(selected[0]))
        elif len(selected) == 2:
            print( "Point 2 : ",FreeCAD.Vector(selected[1]))
        elif len(selected) == 3:
            print( "Point 3 : ",FreeCAD.Vector(selected[2]))
            try:
                C1 = Part.Arc(FreeCAD.Vector(selected[0]),FreeCAD.Vector(selected[1]),FreeCAD.Vector(selected[2]))
                S1 = Part.Shape([C1])
                W = Part.Wire(S1.Edges)
                Part.show(W)
                App.ActiveDocument.ActiveObject.Label   = "Arc_3_Points"
                print( "Length  : ",W.Length)
            except Exception:
                print( "Three points are collinear or bad selection")
            del selected[:]
            FreeCADGui.Selection.removeObserver(s)
            print( "End Make_Arc_3_Points")
            print( "_____________________")

s=SelObserver()
FreeCADGui.Selection.addObserver(s)