Macro Rotate View

From FreeCAD Documentation
Revision as of 13:03, 21 January 2015 by Mario52 (talk | contribs) (make and add def() with the original code)

File:Text-x-python Rotate View by 90°

Description
This macro rotates the current view by 90° to the left. Only works if you are in Top view

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

This macro rotates the current view by 90° to the left. Only works if you are in Top view


import math
from pivy import coin
cam = Gui.ActiveDocument.ActiveView.getCameraNode()
rot = coin.SbRotation()
rot.setValue(coin.SbVec3f(0,0,1),math.pi/2)
nrot = cam.orientation.getValue() * rot
cam.orientation = nrot

Description

This def paste in the Python console FreeCAD (or your macro) allows you to rotate the view in 3-axis and the angle (in degrees) give

interesting to create a plan to a desired position

Use

paste the code in the Python console FreeCAD and type Enter > Enter

Script

def RotateView(axisX=1.0,axisY=0.0,axisZ=0.0,angle=45.0):
    import math
    from pivy import coin
    try:
        cam = Gui.ActiveDocument.ActiveView.getCameraNode()
        rot = coin.SbRotation()
        rot.setValue(coin.SbVec3f(axisX,axisY,axisZ),math.radians(angle))
        nrot = cam.orientation.getValue() * rot
        cam.orientation = nrot
        print axisX," ",axisY," ",axisZ," ",angle
    except Exception:
        print "Not ActiveView "

tip in the console ex :

RotateView(0,1,0,45)

if there is no open document an error is returned