Macro Align View to Face/fr: Difference between revisions

From FreeCAD Documentation
mNo edit summary
(Updating to match new version of source page)
Line 12: Line 12:


<syntaxhighlight>
<syntaxhighlight>

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

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

</syntaxhighlight>
</syntaxhighlight>



Revision as of 11:48, 6 May 2014

File:Text-x-python Macro Align View to Face

Description
Cette macro aligne la vue sur la face sélectionnée

Auteur: Rockn
Auteur
Rockn
Téléchargement
None
Liens
Version Macro
1.0
Dernière modification
None
Version(s) FreeCAD
None
Raccourci clavier
None
Voir aussi
None

Description

Cette macro pivote la vue courante perpendiculairement sur la face sélectionnée d'un objet existant.

Utilisation

  1. Sélectionnez la face d'un objet.
  2. Lancez la 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")