Saturday, 31 May 2014

FreeCAD: Vertex to Vertex Positioning Function

FreeCAD 0.14 is taking too long to be released and, if when you try to compile it, everything is a non-sense and you end up feeling frustrated and stupid (as happens to me every time), you may like this:

Frustration solved: Hamish Assembly2 workbench here

Vector to Vector translation function:

 

Code:

from FreeCAD import Gui

def V2V():
  MouseSel = Gui.Selection.getSelectionEx()
  ObjA_Name = MouseSel[0].ObjectName
  PointA = MouseSel[0].SubObjects[0].Point
  PointB = MouseSel[1].SubObjects[0].Point
  Vector = PointB - PointA
  Pos0 = App.ActiveDocument.getObject(ObjA_Name).Placement.Base
  Rot0 = App.ActiveDocument.getObject(ObjA_Name).Placement.Rotation
  MVector = Pos0 + Vector
  App.ActiveDocument.getObject(ObjA_Name).Placement = App.Placement(MVector, Rot0)

 To Use it:

Copy-Paste at FreeCAD command line the code above and then:

-Select a point of the object you want to move
-Select a point of another object where you want the previous one to be placed
-Call the function (write V2V() at command line and Enter)

And you're done!


With this you can save some time when placing objects without the assembly workbench. 


Bye!