get FreeCAD.Placement out of two FreeCAD.Vector
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
get FreeCAD.Placement out of two FreeCAD.Vector
Assumed I have two FreeCAD.Vector one is the position and the other the direction seen from the position.
How do I get the FreeCAD.Placement out of this. I have been reading Placement twice but still have no glue how to get my Placement in Python.
bernd
How do I get the FreeCAD.Placement out of this. I have been reading Placement twice but still have no glue how to get my Placement in Python.
bernd
Re: get FreeCAD.Placement out of two FreeCAD.Vector
eventually I need a linear lattice2 placement:
the above one generates a linear lattice2 placement in direction of x starting from 0,0,0 because the obj has standard global placement
As an example I have the following list ... (assumed a check if they are all on a line and have the same step has been done.)
this I need to set the global placement of the lattice2 linear placement with. But how do I get the rotation from the direction
Code: Select all
# generate placements with lattice2
# linear
import lattice2LinearArray, lattice2Executer
la = lattice2LinearArray.makeLinearArray(name='LinearArray')
la.GeneratorMode = 'StepN'
la.Alignment = 'Justify' # https://forum.freecadweb.org/viewtopic.php?f=22&t=37657#p320586
la.SpanEnd = 1500
la.Step = 200
la.MarkerSize = 100
lattice2Executer.executeFeature(la)
As an example I have the following list ... (assumed a check if they are all on a line and have the same step has been done.)
Code: Select all
[Vector (0.0, 0.0, 0.0), Vector (-100.0, 0.0, 0.0), Vector (-200.0, 0.0, 0.0), Vector (-300.0, 0.0, 0.0), Vector (-400.0, 0.0, 0.0), Vector (-500.0, 0.0, 0.0)]
Code: Select all
origin = FreeCAD.Vector(0, 0, 0)
direction = FreeCAD.Vector(-500.0, 0.0, 0.0)
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: get FreeCAD.Placement out of two FreeCAD.Vector
There is a Rotation constructor which uses 3 directions
in your case X is your direction
Z may be 0,0,1( keep Head on top)
''' three vectors that define rotated axes directions + an optional 3-characher string of capital letters 'X', 'Y', 'Z' that sets the order of importance of the axes (e.g., 'ZXY' means z direction is followed strictly, x is used but corrected if necessary, y is ignored) '''
return Rotation(X,Y,Z,mode)
in your case X is your direction
Z may be 0,0,1( keep Head on top)
''' three vectors that define rotated axes directions + an optional 3-characher string of capital letters 'X', 'Y', 'Z' that sets the order of importance of the axes (e.g., 'ZXY' means z direction is followed strictly, x is used but corrected if necessary, y is ignored) '''
return Rotation(X,Y,Z,mode)
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: get FreeCAD.Placement out of two FreeCAD.Vector
Yes.
Specifically
Code: Select all
dir = App.Vector(1,2,3)
App.ActiveDocument.LinearArray.Placement = App.Placement(App.Vector(), App.Rotation(dir,App.Vector(),App.Vector(0,0,1),"XZY"))
Re: get FreeCAD.Placement out of two FreeCAD.Vector
somehow I missed this.DeepSOIC wrote: ↑Mon Jul 22, 2019 12:31 pm SpecificallyLinearArray also has Dir property, which can be manipulated instead of placement.Code: Select all
dir = App.Vector(1,2,3) App.ActiveDocument.LinearArray.Placement = App.Placement(App.Vector(), App.Rotation(dir,App.Vector(),App.Vector(0,0,1),"XZY"))
But still I do some misstakes, more work needs to be done to understand what is happening ... The planes are somehow turned if I use a linear array. Left is linear array, right is custom placement and an array from the custom placements ...
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: get FreeCAD.Placement out of two FreeCAD.Vector
You may want to set OrientMode to None. At this moment, it only has effect if the array direction is changed with Dir property, not with Placement; unlikewise, PolarArray supports a lot more options there. This is on my todo list, together with removing Dir property altogether and relying on attachment. (if you worry about your scripts being future-proof, it's all right, as I will keep the old code for the lifetime of Lattice2, it will just be unavailable in GUI)
Re: get FreeCAD.Placement out of two FreeCAD.Vector
setting the appropriate count was still missing in the last picture ...