Macro Perpendicular To Wire: Difference between revisions

From FreeCAD Documentation
m (m)
(Addon_Manager -> Std_AddonMgr)
 
(18 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Macro Perpendicular To Wire|Name=Macro Perpendicular To Wire|Description=This macro positioned your object perpendicularly to wire selected.|Author=Mario52|Version=00.01|Date=29/01/2017}}
|Name=Macro Perpendicular To Wire
</translate>
|Icon=Macro_Perpendicular_To_Wire.png
<translate>
|Description=This macro positions an object perpendicularly to the selected wire.
|Author=Mario52
|Version=00.03
|Date=2020-03-31
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/0/0c/Macro_Perpendicular_To_Wire.png ToolBar Icon].
}}

==Description== <!--T:2-->
==Description== <!--T:2-->
This macro positioned your object perpendicularly to wire selected.
This macro positions an object perpendicularly to the selected wire.

</translate>
==Usage== <!--T:3-->
<translate>
==Use== <!--T:3-->


<!--T:4-->
<!--T:4-->
# Install the macro via the [[Image:Std_AddonMgr.svg|24px|link=Std_AddonMgr]] [[Std_AddonMgr|Addon Manager]]
# : select the path (May be an element or sub-element)
# Select the path (may be an element or sub-element)
# : select the object to align
# : run the macro
# Select the object to align
# Execute the macro
</translate>

<translate>
==Script== <!--T:5-->
==Script== <!--T:5-->

</translate>
<translate>
<!--T:12-->
<!--T:12-->
The icon toolBar [[File:Macro Perpendicular To Wire.png]]
The macro toolbar icon: [[File:Macro Perpendicular To Wire.png|32px]]
</translate>
</translate>


'''Macro Perpendicular To Wire.FCMacro'''
'''Macro Perpendicular To Wire.FCMacro'''


{{Code|code=
{{MacroCode|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
__title__ = "Macro Perpendicular To Wire"
__title__ = "Macro Perpendicular To Wire"
__author__ = "Mario52"
__author__ = "Mario52"
__url__ = "https://www.freecadweb.org/wiki/index.php?title=Macro_Perpendicular_To_Wire"
__url__ = "https://wiki.freecadweb.org/Macro_Perpendicular_To_Wire"
__version__ = "00.01"
__version__ = "00.03"
__date__ = "29/01/2017"
__date__ = "31/03/2020"


import Draft, Part
import Draft, Part
Line 56: Line 63:
FreeCAD.ActiveDocument.recompute()
FreeCAD.ActiveDocument.recompute()
except Exception:
except Exception:
print "Select twoo objects 1:The path 2:The objet to align"
print( "Select two objects. 1:The path 2:The object to align" )

}}
}}
<translate>
<translate>

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


<!--T:7-->
<!--T:7-->
Essentially the line is cut in x points with {{incode|discretize()}} (for our purposes we default to {{incode|Number&#61;500}} but cuts may be modfied between 0 to 499)
Principle :

<!--T:8-->
the line is cut in x points with "discretize()" (here Number=500 cuts begin 0 to 499 you can modify)
</translate>
</translate>


Line 73: Line 79:
<translate>
<translate>
<!--T:9-->
<!--T:9-->
the perpendicularity is calculate between 2 points modify :
1. The perpendicularity is calculated between 2 points:
</translate>
</translate>

1:

{{Code|code=
{{Code|code=
v=pointsDirection[0].sub(pointsDirection[1]) # perpendicular of first > second point
v=pointsDirection[0].sub(pointsDirection[1]) # perpendicular of first > second point
}}
}}


[[File:Macro Perpendicular To Wire 01.png ]]
:[[File:Macro Perpendicular To Wire 01.png]]
{{clear}}
{{clear}}
2:
2:
Line 90: Line 93:
pl.Base = pointsDirection[-1] # position base last point}}
pl.Base = pointsDirection[-1] # position base last point}}


[[File:Macro Perpendicular To Wire 02.png ]]
:[[File:Macro Perpendicular To Wire 02.png]]
{{clear}}
{{clear}}
3:
3:
Line 98: Line 101:
pl.Base = pointsDirection[100] # position base point 100}}
pl.Base = pointsDirection[100] # position base point 100}}


[[File:Macro Perpendicular To Wire 03.png ]]
:[[File:Macro Perpendicular To Wire 03.png]]
{{clear}}
{{clear}}
4:
4:
Line 106: Line 109:
pl.Base = pointsDirection[0] # position base first point}}
pl.Base = pointsDirection[0] # position base first point}}


[[File:Macro Perpendicular To Wire 04.png ]]
:[[File:Macro Perpendicular To Wire 04.png]]
{{clear}}
{{clear}}
<translate>
<translate>

<!--T:10-->
<!--T:10-->
for discretize other parameters
Other parameters to {{incode|discretize()}} are as follows:

</translate>
</translate>
{{Code|code=
{{Code|code=
# Discretizes the edge and returns a list of points.
#http://forum.freecadweb.org/viewtopic.php?f=12&t=16336#p129468
# Forum thread: http://forum.freecadweb.org/viewtopic.php?f=12&t=16336#p129468
#Discretizes the edge and returns a list of points.
#The function accepts keywords as argument:
# The function accepts keywords as argument:
#discretize(Number=n) => gives a list of 'n' equidistant points
# discretize(Number=n) => gives a list of 'n' equidistant points
#discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above)
# discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above)
#discretize(Distance=d) => gives a list of equidistant points with distance 'd'
# discretize(Distance=d) => gives a list of equidistant points with distance 'd'
#discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge
# discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge
#discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster)
# discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster)
#discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
# discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
#and a curvature deflection of 'c'. Optionally a minimum number of points
# and a curvature deflection of 'c'. Optionally a minimum number of points
#can be set which by default is set to 2.
# can be set which by default is set to 2.
}}
}}
<translate>

==Example== <!--T:13-->
</translate>
<br /><br />
[[File:Macro Perpendicular To Wire 05.gif]]
{{clear}}

[[File:Macro Perpendicular To Wire.gif]]


<translate>
<translate>
==Discussions== <!--T:15-->

<!--T:11-->
<!--T:11-->
The discussion on the forum [[https://forum.freecadweb.org/viewtopic.php?f=13&t=19899&start=20 Spiralbohrer]]
* [[https://forum.freecadweb.org/viewtopic.php?f=13&t=19899&start=20 Spiralbohrer]] discussion on the FC forum.
* http://forum.freecadweb.org/viewtopic.php?f=12&t=16336#p129468

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

<!--T:16-->
Ver 00.03 2020-03-21: Source and comment typo fixes
Ver 00.02 2019-04-06: Python 3


</translate>
</translate>
<languages/>

Latest revision as of 19:17, 3 November 2021

Other languages:

Macro Perpendicular To Wire

Description
This macro positions an object perpendicularly to the selected wire.

Macro version: 00.03
Last modified: 2020-03-31
FreeCAD version: All
Download: ToolBar Icon.
Author: Mario52
Author
Mario52
Download
ToolBar Icon.
Links
Macro Version
00.03
Date last modified
2020-03-31
FreeCAD Version(s)
All
Default shortcut
None
See also
None

Description

This macro positions an object perpendicularly to the selected wire.

Usage

  1. Install the macro via the Addon Manager
  2. Select the path (may be an element or sub-element)
  3. Select the object to align
  4. Execute the macro

Script

The macro toolbar icon:

Macro Perpendicular To Wire.FCMacro

# -*- coding: utf-8 -*-
__title__   = "Macro Perpendicular To Wire"
__author__  = "Mario52"
__url__     = "https://wiki.freecadweb.org/Macro_Perpendicular_To_Wire"
__version__ = "00.03"
__date__    = "31/03/2020"

import Draft, Part

try:
    sel = FreeCADGui.Selection.getSelection()                               # Select an object
    
    lineSelected = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]   # first object the Path object or SubObjects
    myCircle     = sel[1]                                                   # second object
    
    pointsDirection  = []
    
    pointsDirection = lineSelected.discretize(Number=500)                   # discretize the path line first selection
    
    v=pointsDirection[0].sub(pointsDirection[1])                            # avec vecteurs 1 et 2 (direction debut ligne)
    r=App.Rotation(App.Vector(0,0,1),v)
    
    pl=FreeCAD.Placement()                                                  # placement object
    pl.Rotation.Q = r.Q
    pl.Base = pointsDirection[0]
    myCircle.Placement = pl
    
    del pointsDirection[:]
    FreeCAD.ActiveDocument.recompute()
except Exception:
    print( "Select two objects. 1:The path 2:The object to align" )

Options

Essentially the line is cut in x points with discretize() (for our purposes we default to Number=500 but cuts may be modfied between 0 to 499)

pointsDirection = lineSelected.Shape.discretize(Number=500)             # discretize the path line first selection

1. The perpendicularity is calculated between 2 points:

v=pointsDirection[0].sub(pointsDirection[1])          # perpendicular of first > second point

2:

v=pointsDirection[-1].sub(pointsDirection[-2])       # perpendicular of last > before last point
pl.Base = pointsDirection[-1]                        # position base last point

3:

v=pointsDirection[100].sub(pointsDirection[101])   # perpendicular of point 100 > point 101
pl.Base = pointsDirection[100]                     # position base point 100

4:

v=pointsDirection[0].sub(pointsDirection[-1])         # perpendicular of first point > last point
pl.Base = pointsDirection[0]                          # position base first point

Other parameters to discretize() are as follows:

# Discretizes the edge and returns a list of points.
# Forum thread: http://forum.freecadweb.org/viewtopic.php?f=12&t=16336#p129468
# The function accepts keywords as argument:
# discretize(Number=n) => gives a list of 'n' equidistant points
# discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above)
# discretize(Distance=d) => gives a list of equidistant points with distance 'd'
# discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge
# discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster)
# discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
# and a curvature deflection of 'c'. Optionally a minimum number of points
# can be set which by default is set to 2.

Example



Discussions

Version

Ver 00.03 2020-03-21: Source and comment typo fixes Ver 00.02 2019-04-06: Python 3