origin of face of a prism, map rectangle to face

Need help, or want to share a macro? Post here!
Chri1
Posts: 68
Joined: Wed Oct 17, 2018 9:00 am

origin of face of a prism, map rectangle to face

Postby Chri1 » Mon Oct 14, 2019 8:39 pm

Hi

I have a prism, select one face of the prism, make the face to actual workingplane and draw a rectangle (-> obj)
Now I map the rectangle to the face by code:

Code: Select all

....       
bk = FreeCADGui.Selection.getSelectionEx()[0]  #The selected face
flae = bk.SubElementNames[0]
...          
P0 = obj.Placement.Base  #The origin of the rectangle

obj.Support = [(bk.Object,flae)]  #map
obj.MapMode = 'FlatFace'  #map
As far it is ok. But: After mapping, the rectangle jumps to the origin of the face, therefore I want to correct this, but have troubles to get P1:

Code: Select all

P1 = bk.SubObjects[0].?????????   # Should be the origin of the face in worldcoordinates
dP = P1-P0
P2 = obj.AttachmentOffset.Base
P2 = P2 + dP

obj.AttachmentOffset.Base = P2
Thanks
Chri1
Chri1
Posts: 68
Joined: Wed Oct 17, 2018 9:00 am

Re: origin of face of a prism, map rectangle to face

Postby Chri1 » Tue Oct 15, 2019 8:14 am

Ok, as I have thought so far, it does not work.
Will have to deal with coordinate system transformations...
Chri1
Posts: 68
Joined: Wed Oct 17, 2018 9:00 am

Re: origin of face of a prism, map rectangle to face

Postby Chri1 » Fri Oct 18, 2019 12:34 pm

Ok, I also have to take care about rotation, but not now - first, I take a circle instead of rectangle.

I dont' understand it!:

The manual workflow would be:
I draw a cube (10,10,10) in position(0,0,0)
I select the face of the cube, which is parallel to yz and x = 10 and make it to current workingplane
I draw a circle: midpoint (10,5,6), r = 2
I map the circle to the face - and it jumps to (10,0,0)
I set "Attachment/Position" of circle to x=5, y=6 and it jumps back.

And now by macro:
circle is already drawn and mapped - I want the "Attachment/Position" to let the circle jump back.

Code: Select all

mp_before = FreeCAD.Vector(10,5,6)
# The face is selected:
bk = FreeCADGui.Selection.getSelectionEx()[0]
App.DraftWorkingPlane.alignToFace(bk.SubObjects[0]) 
FreeCADGui.Snapper.setGrid(init=True)

wp = App.Draft.Workingplane
mp = wp.getLocalCoords(mp_before)   #returns  (-0, -1, -0)   WHY? What is this?
mp should be (5,6,0) !?

And the macro should work also with any orientation of the face
Chri1
Posts: 68
Joined: Wed Oct 17, 2018 9:00 am

Re: origin of face of a prism, map rectangle to face

Postby Chri1 » Sat Oct 19, 2019 2:59 pm

I think I got it!
Has nothing to do with the actual workplane

obj: circle is already drawn

Code: Select all

#Before mapped:
P0 = obj.Placement.Base  
...
#After mapped:
mi=obj.Placement.toMatrix()
mi=mi.inverse()
P2=multVec(P0)
obj.AttachmentOffset.Base.x=P2.x
obj.AttachmentOffset.Base.y=P2.y
Chri1 wrote:
Fri Oct 18, 2019 12:34 pm
mp = wp.getLocalCoords(mp_before) #returns (-0, -1, -0) WHY? What is this?[/code]
This seems to be the origin of the workplane, It is the point on the workplane with the shortest distance to the world-origin