Macro Cut Circle: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
 
(28 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>

<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Text-x-python|Name=Macro Cut Circle|Description=Cut a circle or arc in x arcs.|Author=mario52|Version=00.02|Date=2015-03-09}}
|Name=Macro Cut Circle
|Description=Cuts circles or arcs into multiple arcs. The created arcs can be colored alternately to distinguish them.<br/>{{ColoredText|(Command line, paste the complete macro in the Python console)}}.
|Author=mario52
|Version=00.03
|Date=2019-07-02
|FCVersion=All
|Download=[https://wiki.freecad.org/images/9/93/Macro_Cut_Circle.png ToolBar Icon]
}}


==Description== <!--T:2-->
==Description== <!--T:2-->
This macro cut a circle(s) or arc(s) in multiple arcs, the arcs can be coloured alternately to distinguish.


<!--T:13-->
</translate>
This macro cuts circles or arcs into multiple arcs. The created arcs can be colored alternately to distinguish them.


[[File:Macro CutCircle 00.png|400px|CutCircle]]
{{clear}}
<translate>
==Use== <!--T:3-->
Copy the macro '''cutCirle''' complete in the Python console FreeCAD select the circle(s) and (or) arc(s) type in the console:
</translate>
</translate>
[[File:Macro CutCircle 00.png|400px]]

<translate>
<translate>
<!--T:4-->
<!--T:12-->
{{Caption|CutCircle}}
to see the circles and arcs cut here in the example 5 contiguous arcs.


<!--T:5-->
==Usage== <!--T:15-->

The original object is not deleted.
<!--T:3-->
# Paste the macro '''cutCirle''' in the [[Python_console|Python console]].
# Press {{KEY|Enter}} (the code is now in memory).
# Select one or more circles or arcs.
# Invoke the {{Incode|cutCircle()}} function with 1 or 2 arguments from the Python console:
#* Example with 1 argument: {{Incode|cutCircle(4)}}. This will create 4 new arcs for each selected circle or arc and stop there (no coloring).
#* Example with 2 arguments: {{Incode|cutCircle(6, 1)}}. This will create 6 new arcs for each selected circle or arc, colored alternately in red and white as shown in the image.
# The original object is not deleted.


==Script== <!--T:6-->
==Script== <!--T:6-->

<!--T:16-->
ToolBar Icon [[Image:Macro_Cut_Circle.png]]

</translate>
</translate>
'''Macro_Cut_Circle.FCMacro'''
'''Macro_Cut_Circle.FCMacro'''


{{Code|code=
{{MacroCode|code=

__title__= "cutCircle"
__author__= "Mario52"
__date__= "09/03/2015"
__version__= "00.02"


# selection circle(s) (circles and arcs)
# selection circle(s) (circles and arcs)
Line 39: Line 50:
# if biColor is <> 0 the arcs are colored alternately Red White Red White ....
# if biColor is <> 0 the arcs are colored alternately Red White Red White ....
#
#
__title__ = "cutCircle"
__author__ = "Mario52"
__date__ = "02/07/2019"
__version__ = "00.03"


import Draft
import Draft
Line 86: Line 102:
defbiColor(cercle)
defbiColor(cercle)
pivot1 += pivot0
pivot1 += pivot0
App.ActiveDocument.recompute()


#cutCircle(5, 1) # here with 5 arcs and colored
#cutCircle(4) #


}}
}}
<translate>
<translate>

==Example== <!--T:11-->
==Example== <!--T:11-->
</translate>


</translate>
{{Code|code=
{{Code|code=
cutCircle(5, 1) # here with 5 arcs and coloured
cutCircle(5, 1) # here with 5 arcs and colored
cutCircle(4) #
cutCircle(4) #
}}
}}

<translate>
<translate>

==Project== <!--T:7-->
==Project== <!--T:17-->

<!--T:7-->
Cut circle to cylinder
Cut circle to cylinder


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

<!--T:14-->
ver 00.03 02/07/2019 : add "App.ActiveDocument.recompute()"


<!--T:9-->
<!--T:9-->
ver 00.02 09/03/2015 : adding create arcs coloured altenat alternately Red White Red White .... or not
ver 00.02 09/03/2015 : adding create arcs colored alternately Red White Red White .... or not


<!--T:10-->
<!--T:10-->
ver 00.01 24/02/2015 :
ver 00.01 24/02/2015 :



</translate>
</translate>

Latest revision as of 17:04, 30 December 2023

Other languages:

Macro Cut Circle

Description
Cuts circles or arcs into multiple arcs. The created arcs can be colored alternately to distinguish them.
(Command line, paste the complete macro in the Python console).

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

Description

This macro cuts circles or arcs into multiple arcs. The created arcs can be colored alternately to distinguish them.

CutCircle

Usage

  1. Paste the macro cutCirle in the Python console.
  2. Press Enter (the code is now in memory).
  3. Select one or more circles or arcs.
  4. Invoke the cutCircle() function with 1 or 2 arguments from the Python console:
    • Example with 1 argument: cutCircle(4). This will create 4 new arcs for each selected circle or arc and stop there (no coloring).
    • Example with 2 arguments: cutCircle(6, 1). This will create 6 new arcs for each selected circle or arc, colored alternately in red and white as shown in the image.
  5. The original object is not deleted.

Script

ToolBar Icon

Macro_Cut_Circle.FCMacro

# selection circle(s) (circles and arcs)
# give number of cut, biColor 0/1
# cut the circle to x arcs
# if biColor is <> 0 the arcs are colored alternately Red White Red White ....
# 
 
__title__   = "cutCircle"
__author__  = "Mario52"
__date__    = "02/07/2019"
__version__ = "00.03"

import Draft
global biscolor ; biscolor = 0
def cutCircle(number = 2, biColor = 0):
    global biscolor
    def defbiColor(objet):
        global biscolor
        if biscolor == 0:
            FreeCADGui.ActiveDocument.getObject(objet.Name).LineColor = (1.0,0.0,0.0) # 255 = 1 (10 = (1/255 * 10 ))
            biscolor = 1
        else:
            FreeCADGui.ActiveDocument.getObject(objet.Name).LineColor = (1.0,1.0,1.0) # 255 = 1 (10 = (1/255 * 10 ))
            biscolor = 0
    selection = FreeCADGui.Selection.getSelection()
    for piece in selection:
        nom = piece.Name
        if (nom[:6] == "Circle") or (nom[:8] == "Cylinder"):
            circonference = piece.Shape.Length
            rayon = piece.Radius
            placem = piece.Placement
 
            if (nom[:8] == "Cylinder"):
                pivot0 = float(piece.Angle/number)
                FreeCAD.Console.PrintMessage("Cylinder"+"\n")
            else:
                pivot0 = float(360/number)
                FreeCAD.Console.PrintMessage("Circle"+"\n")
            pivot1 = 0.0
            for i in range(number):
                cercle = Draft.makeCircle(radius=rayon,placement=placem,face=False,startangle=(pivot1),endangle=(pivot0+pivot1),support=None)
                if biColor != 0:
                    defbiColor(cercle)
                pivot1 += pivot0
        elif nom[:3] == "Arc":
            FreeCAD.Console.PrintMessage("Arc"+"\n")
            circonference = piece.Shape.Length
            rayon = piece.Radius
            placem = piece.Placement
            First = float(piece.FirstAngle)
            Last  = float(piece.LastAngle)
            pivot0 = abs((First - Last) / number)
            pivot1 = 0.0
            for i in range(number):
                cercle = Draft.makeCircle(radius=rayon,placement=placem,face=False,startangle=(pivot1+First),endangle=(pivot0+pivot1+First),support=None)
                if biColor != 0:
                    defbiColor(cercle)
                pivot1 += pivot0
    App.ActiveDocument.recompute()

#cutCircle(5, 1)  # here with 5 arcs and colored
#cutCircle(4)     #

Example

cutCircle(5, 1)  # here with 5 arcs and colored
cutCircle(4)     #

Project

Cut circle to cylinder

Version

ver 00.03 02/07/2019 : add "App.ActiveDocument.recompute()"

ver 00.02 09/03/2015 : adding create arcs colored alternately Red White Red White .... or not

ver 00.01 24/02/2015 :