Skip to content

Instantly share code, notes, and snippets.

@mario52a
Last active August 12, 2021 23:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mario52a/60d240ed6845f97f67a1423603a774f0 to your computer and use it in GitHub Desktop.
Save mario52a/60d240ed6845f97f67a1423603a774f0 to your computer and use it in GitHub Desktop.
This macro positioned your object perpendicularly to wire selected.
# -*- coding: utf-8 -*-
__title__ = "Macro Perpendicular To Wire"
__author__ = "Mario52"
__url__ = "https://www.freecadweb.org/wiki/index.php?title=Macro_Perpendicular_To_Wire"
__version__ = "00.02"
__date__ = "06/04/2019"
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 twoo objects 1:The path 2:The objet to align" )
@mario52a
Copy link
Author

This macro utility is intended for the use of the program FreeCAD http://www.freecadweb.org/
The icon for your toolbar, it is to place in your macros directory (in the same location of the macro)

macro_perpendicular_to_wire Rename in Macro_Perpendicular_To_Wire.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment