[Draft] Force to draft in current workplane

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
rockn
Veteran
Posts: 1784
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

[Draft] Force to draft in current workplane

Post by rockn »

Hi,
It is possible to make that all the points of the geometry in the course of drawing is constrained in the surface of current workplane ? And this even when one makes use of the snaps tool like intersection and that this intersection is not in the plan of current workplane ?
Formations - Assistance - Développement : https://freecad-france.com
User avatar
bejant
Veteran
Posts: 6075
Joined: Thu Jul 11, 2013 3:06 pm

Re: [Draft] Force to draft in current workplane

Post by bejant »

rockn wrote:... even when one makes use of the snaps tool like intersection and that this intersection is not in the plan of current workplane ?
Hi rockn, I'm pretty sure that at present there is no such a FreeCAD tool but I'm no expert.

I have used a similar tool to what you've described, in other CAD program(s) as something like "Apparent Intersection" or some similar name. From your other posts I can see how this would be a quite useful tool for you, as it would be for others. It would be handy for measuring distances too. We'll wait and see the thoughts of others about this...
User avatar
yorik
Founder
Posts: 13468
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: [Draft] Force to draft in current workplane

Post by yorik »

rockn wrote:It is possible to make that all the points of the geometry in the course of drawing is constrained in the surface of current workplane ? And this even when one makes use of the snaps tool like intersection and that this intersection is not in the plan of current workplane ?
It's actually a good idea... What I usually do is press Shift to constrain in one direction, then you can snap outside of the working plane. But indeed a kind of "lock" that would force the point on the WP would be pretty interesting. I'll open a ticket: issue #1461
User avatar
rockn
Veteran
Posts: 1784
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: [Draft] Force to draft in current workplane

Post by rockn »

Hi,
Thanks for the Mantis Ticket. I would help me a lot, because I'm working a lot in another direction than x or y so the Shift constrain don't help me.
I can draw my line in any direction by initially drawing the two edges perpendicular of the right-angled triangle by helping me of Shift. The hypotenuse will be my line.
But the force workplane lock snap mode will facilitate the operation. ;)
Formations - Assistance - Développement : https://freecad-france.com
User avatar
rockn
Veteran
Posts: 1784
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: [Draft] Force to draft in current workplane

Post by rockn »

Thank you very much Yorik for the fix 1461.
I'm playing with it and work like a charm.

I am now thinking (and searching) that I just need to place the camera in front of the working plane to be in perfect conditions to draw my pieces of wood.
I don't find a lot of thing about View orientation.
I try something like : "Gui.ActiveDocument.ActiveView.setCameraOrientation(0.0,-0.0,1.0)"
But the console say to me that .setCameraOrientation need a tuple... and I don't know where I can get it ? I think it need the normal of the working plane.

In any case thank you again for the WP snap mode. :)
Formations - Assistance - Développement : https://freecad-france.com
User avatar
yorik
Founder
Posts: 13468
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: [Draft] Force to draft in current workplane

Post by yorik »

I don't remember exactly and I cant test right now, but in any case you are giving it 3 separate arguments... If it needs a tuple, you need to do: setCameraOrientation( (0.0,-0.0,1.0) ) but there might be something else needed too.

Have a search in the source code, or on the wiki, or on the forum, there is certainly an example of how to use it...
User avatar
rockn
Veteran
Posts: 1784
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: [Draft] Force to draft in current workplane

Post by rockn »

Ok, the right command is something like this :
FreeCADGui.ActiveDocument.ActiveView.setCameraOrientation( (0.0, 0.0, 1.0, 0.0) )
I see in Sketcher WB code something like this :
https://github.com/FreeCAD/FreeCAD_sf_m ... ommand.cpp line 407

Code: Select all

doCommand(Gui,"Gui.ActiveDocument.ActiveView.setCameraOrientation(App.ActiveDocument.%s.Placement.Rotation.Q)"
Now I try to get the placement of the selected face.
With this code I get the same "tuple" whatever the selected face.

Code: Select all

s=Gui.Selection.getSelectionEx()
obj=s[0]
faceSel = obj.SubObjects[0]
FreeCADGui.ActiveDocument.ActiveView.setCameraOrientation( faceSel.Placement.Rotation.Q )
Why the placement isn't different when I selected different face ?
Formations - Assistance - Développement : https://freecad-france.com
User avatar
yorik
Founder
Posts: 13468
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: [Draft] Force to draft in current workplane

Post by yorik »

I think the placement is only one for each shape, there is no difference for each face... I think the line you took is when you are editing an existing sketch, so you are actually using the placement of the sketch.

You could take the normal of your face with faceSel.normalAt(0,0) and extract the rotation value from it (not sure how to do that,though), but it is maybe easier to do this with pivy, since coin allows you to give a "target point" to orient a camera ( http://www-evasion.imag.fr/~Francois.Fa ... amera.html )

Probably something like this (untested):

Code: Select all

from pivy import coin
dir = faceSel.normalAt(0,0)
cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
pos = FreeCAD.Vector( cam.position.getValue().getValue() )
p = pos.add(dir)
cam.pointAt( coin.SbVec3f(p.x,p.y,p.z) )
User avatar
rockn
Veteran
Posts: 1784
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: [Draft] Force to draft in current workplane

Post by rockn »

Thank you Yorik.
I'm close to get it with this code :

Code: Select all

from pivy import coin
s=Gui.Selection.getSelectionEx()
obj=s[0]
faceSel = obj.SubObjects[0]
dir = faceSel.normalAt(0,0)
cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
camValues = cam.position.getValue()
pos = FreeCAD.Vector( (camValues[0], camValues[1], camValues[2],) )
p = pos.add(dir.negative())
cam.pointAt( coin.SbVec3f(p.x,p.y,p.z) )
Gui.SendMsgToActiveView("ViewFit")
Formations - Assistance - Développement : https://freecad-france.com
User avatar
rockn
Veteran
Posts: 1784
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: [Draft] Force to draft in current workplane

Post by rockn »

So I share with you this macro to set the current view perpendicular to the selected face.

Code: Select all

# -*- coding: utf-8 -*-
# Set the current view perpendicular to the selected face 
# Place la vue perpendiculairement à la face selectionnee
# 2013 Jonathan Wiedemann

from pivy import coin
s=Gui.Selection.getSelectionEx()
obj=s[0]
faceSel = obj.SubObjects[0]
dir = faceSel.normalAt(0,0)
cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
camValues = cam.position.getValue()
pos = FreeCAD.Vector( (camValues[0], camValues[1], camValues[2],) )
p = pos.add(dir.negative())
print(p.x,p.y,p.z)
if dir.z == 1 :
	cam.pointAt( coin.SbVec3f(p.x,p.y,p.z), coin.SbVec3f(0.0,1.0,0.0))
	print("normal = 1")
elif dir.z == -1 :
	cam.pointAt( coin.SbVec3f(p.x,p.y,p.z), coin.SbVec3f(0.0,1.0,0.0))
	print("normal = -1")
else :
	cam.pointAt( coin.SbVec3f(p.x,p.y,p.z), coin.SbVec3f(0.0,0.0,1.0))
	print("normal normale")
Gui.SendMsgToActiveView("ViewSelection")
Formations - Assistance - Développement : https://freecad-france.com
Post Reply