Macro Make Arc 3 Points: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
(Use {{MacroCode}})
 
(10 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}}
|Name=Macro Make Arc 3 Points
</translate>
|Icon=Macro_Make_Arc_3_Points.png
<translate>
==Description== <!--T:2-->
|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-->
This macro creates a arc on 3 selected points.
This macro creates a arc on 3 selected points.

</translate>
==Usage== <!--T:3-->
<translate>
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.
==Use== <!--T:3-->

Select 3 points, or 3 points subObject and run the macro.
<!--T:5-->
</translate>
(PS: It is not required to hold down the Ctrl key)
<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'''


{{MacroCode|code=
<syntaxhighlight>
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from FreeCAD import Base
from FreeCAD import Base
Line 25: Line 35:
__author__ = "Mario52"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.00"
__version__ = "00.02"
__date__ = "28/06/2019"
__date__ = "29/07/2019"


global selected; selected = []
App = FreeCAD


class SelObserver:
selectedObject = FreeCADGui.Selection.getSelection() # select one element
print( "Create Arc to 3 points ...")
selectedEdge = FreeCADGui.Selection.getSelectionEx() # select one subElement
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()
try:
FreeCADGui.Selection.addObserver(s)
try:
point0 = selectedObject[0].Shape.Point # element
point1 = selectedObject[1].Shape.Point
point2 = selectedObject[2].Shape.Point
except:
point0 = selectedEdge[0].SubObjects[0].Point # subElement
point1 = selectedEdge[0].SubObjects[1].Point
point2 = selectedEdge[0].SubObjects[2].Point


FreeCAD.Console.PrintMessage(str(point0)+" "+str(point1)+" "+str(point2))


}}
C1 = Part.Arc(point0,point1,point2)
S1 = Part.Shape([C1])
W = Part.Wire(S1.Edges)
Part.show(W)
except:
FreeCAD.Console.PrintError("Select tree points or tree subObjects points"+"\n")

</syntaxhighlight>
<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)