Macro Align View to Face: Difference between revisions

From FreeCAD Documentation
(Created page with "<translate> {{Macro|Name=Macro Align View to Face|Description=This macro aligns the current view to a selected face|Author=Rockn}} ==Description== This macro rotates the cur...")
 
(Marked this version for translation)
Line 1: Line 1:
<translate>
<translate>
<!--T:1-->
{{Macro|Name=Macro Align View to Face|Description=This macro aligns the current view to a selected face|Author=Rockn}}
{{Macro|Name=Macro Align View to Face|Description=This macro aligns the current view to a selected face|Author=Rockn}}


==Description==
==Description== <!--T:2-->


<!--T:3-->
This macro rotates the current view to point perpendicularly at a selected face of an existing object.
This macro rotates the current view to point perpendicularly at a selected face of an existing object.


==How to use==
==How to use== <!--T:4-->
# Select a face on an object
# Select a face on an object
# Run the macro
# Run the macro


==Script==
==Script== <!--T:5-->


</translate>
</translate>
Line 42: Line 44:


<translate>
<translate>
<!--T:6-->
[[Category:Python Code]]
[[Category:Python Code]]
</translate>
</translate>

Revision as of 21:46, 12 March 2014

Macro Align View to Face

Description
This macro aligns the current view to a selected face

Author: Rockn
Author
Rockn
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Description

This macro rotates the current view to point perpendicularly at a selected face of an existing object.

How to use

  1. Select a face on an object
  2. Run the macro

Script

 # -*- 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")