Macro Rotate View/cs: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 14: Line 14:
cam.orientation = nrot
cam.orientation = nrot
}}
}}
== Desription==
== Description==
This code for :
This code for axonometric view with Y pointing upwards [[File:Macro_Rotate_View_with_Y_pointing_upwards_.png|axonometric view with Y pointing upwards]]
# axonometric view with Y pointing upwards [[File:Macro_Rotate_View_with_Y_pointing_upwards_.png|axonometric view with Y pointing upwards]] mode 1

# axonometric view with Z pointing upwards [[File:Macro_Rotate_View_with_Z_pointing_upwards_.png|axonometric view with Z pointing upwards]] mode 2
For FreeCAD Version 0.16


{{Code|code=
{{Code|code=
Line 29: Line 31:
rot = coin.SbRotation()
rot = coin.SbRotation()


rot.setValue(coin.SbVec3f(1,0,0),-math.pi/2) # Y pointing upwards
rot.setValue(coin.SbVec3f(1,0,0),-math.pi/2) # Y pointing upwards (mode 1)
#rot.setValue(coin.SbVec3f(0,0,1),math.pi/2) # Z pointing upwards (mode 2 uncomment for use)
nrot = cam.orientation.getValue() * rot
nrot = cam.orientation.getValue() * rot
cam.orientation = nrot
cam.orientation = nrot

Revision as of 09:52, 12 January 2016

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

Popis
Toto makro otočí objekt o 90° doleva. Funguje jen pokud jste v pohledu shora

Autor: Yorik
Autor
Yorik
Download
None
Odkazy
Verze
1.0
Datum poslední úpravy
None
Verze FreeCAD
None
Výchozí zástupce
None
Viz též
None

Description

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


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 code for :

  1. axonometric view with Y pointing upwards axonometric view with Y pointing upwards mode 1
  2. axonometric view with Z pointing upwards axonometric view with Z pointing upwards mode 2

For FreeCAD Version 0.16

import math
import pivy
from pivy import coin

Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")

cam = Gui.ActiveDocument.ActiveView.getCameraNode()
rot = coin.SbRotation()

rot.setValue(coin.SbVec3f(1,0,0),-math.pi/2) # Y pointing upwards (mode 1)
#rot.setValue(coin.SbVec3f(0,0,1),math.pi/2) # Z pointing upwards (mode 2 uncomment for use)
nrot = cam.orientation.getValue() * rot
cam.orientation = nrot
Gui.SendMsgToActiveView("ViewFit")

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