How can you zoom in and out of a document via scripting?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Catamount
Posts: 3
Joined: Mon Jan 27, 2014 1:33 am

How can you zoom in and out of a document via scripting?

Post by Catamount »

I would like to be able to zoom in or out of a FreeCAD document in a python script. Can this be done?
wmayer
Founder
Posts: 20113
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How can you zoom in and out of a document via scripting?

Post by wmayer »

Sorry, that's currently not possible. Feel free to open a feature request.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: How can you zoom in and out of a document via scripting?

Post by jmaustpc »

Catamount wrote:I would like to be able to zoom in or out of a FreeCAD document in a python script. Can this be done?
Do you mean that you want to zoom in and out by some specified value?

You don't just mean that you only want to zoom to "fit all", do you? Zoom to fit all is there in Python.

I just thought I would check, just in case that was what you wanted.
Catamount
Posts: 3
Joined: Mon Jan 27, 2014 1:33 am

Re: How can you zoom in and out of a document via scripting?

Post by Catamount »

Given a new window with several objects, I would like to be able to view them all, or zoom in on one or more, or change the "Standard View", i.e. front back, top etc.
User avatar
quick61
Veteran
Posts: 3803
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: How can you zoom in and out of a document via scripting?

Post by quick61 »

  • Gui.SendMsgToActiveView("ViewFit")
  • Gui.activeDocument().activeView().viewTop()
  • Gui.activeDocument().activeView().viewBottom()
  • Gui.activeDocument().activeView().viewFront()
  • Gui.activeDocument().activeView().viewRear()
  • Gui.activeDocument().activeView().viewRight()
  • Gui.activeDocument().activeView().viewLeft()
  • Gui.activeDocument().activeView().viewAxometric()
or zoom in on one or more
This one I'm not sure how to do or if it can be done.
This post made with 0.0% Micro$oft products - GOT LINUX?
mario52
Veteran
Posts: 4670
Joined: Wed May 16, 2012 2:13 pm

Re: How can you zoom in and out of a document via scripting?

Post by mario52 »

Hi
type " Menu > View > View > check Report view and Python console "
Report view = displays errors and other information
Python console = Displays the Python code executed by freecad and you can reproduce in your macro
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Catamount
Posts: 3
Joined: Mon Jan 27, 2014 1:33 am

Re: How can you zoom in and out of a document via scripting?

Post by Catamount »

Problems solved, thank you.
-----------------------------------

To show all the objects in the active view

Gui.SendMsgToActiveView("ViewFit")

To zoom in or out, change the camera angle etc. use

Gui.activeDocument().activeView().setCamera('#Inventor V2.1 ascii \n OrthographicCamera { \n viewportMapping ADJUST_CAMERA \n position 0 0 87 \n orientation 0 0 1 0 \n nearDistance 37 \n farDistance 137 \n aspectRatio 1 \n focalDistance 87 \n height 119 }')

and change the arguments accordingly.
rrvaidya
Posts: 1
Joined: Tue May 12, 2015 2:34 pm

Re: How can you zoom in and out of a document via scripting?

Post by rrvaidya »

I could zoom using the script provided in the previous post but the geometry is getting displayed in the top right corner. Is there any script available bring the geometry in center of the screen (without disturbing the zoom level)?
Also, just curious if the zoom function using Macro (Python API) is added in any version of FreeCAD?
elemes
Posts: 1
Joined: Wed Jul 29, 2015 1:13 pm

Re: How can you zoom in and out of a document via scripting?

Post by elemes »

Hello,
when changing focalDistance with a single command on the console nothing is changed on the document window.
I would expect something like "wide angle camera" or "telephoto camera" but really nothing changed.

>>> Gui.activeDocument().activeView().setCamera('#Inventor V2.1 ascii\n\n\nPerspectiveCamera {\n viewportMapping ADJUST_CAMERA\n position 140 -250 130\n orientation -1 0 0 4.7\n nearDistance 111\n farDistance 888\n aspectRatio 1\n focalDistance 12345\n heightAngle 0.6\n\n}\n')
>>> Gui.activeDocument().activeView().getCamera()
'#Inventor V2.1 ascii\n\n\nPerspectiveCamera {\n viewportMapping ADJUST_CAMERA\n position 140 -250 130\n orientation -1 0 0 4.6999998\n nearDistance 168.08426\n farDistance 825.59351\n aspectRatio 1\n focalDistance 12345\n heightAngle 0.78539819\n\n}\n'
>>> Gui.activeDocument().activeView().setCamera('#Inventor V2.1 ascii\n\n\nPerspectiveCamera {\n viewportMapping ADJUST_CAMERA\n position 140 -250 130\n orientation -1 0 0 4.7\n nearDistance 222\n farDistance 777\n aspectRatio 1\n focalDistance 54321\n heightAngle 0.6\n\n}\n')
>>> Gui.activeDocument().activeView().getCamera()
'#Inventor V2.1 ascii\n\n\nPerspectiveCamera {\n viewportMapping ADJUST_CAMERA\n position 140 -250 130\n orientation -1 0 0 4.6999998\n nearDistance 168.08426\n farDistance 825.59351\n aspectRatio 1\n focalDistance 54321\n heightAngle 0.78539819\n\n}\n'
>>>

executing these commands there was no change on the Document. However, as if focalDistance would affect zoom granularity of roll button in the mouse.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: How can you zoom in and out of a document via scripting?

Post by DeepSOIC »

I think, when you set focal distance, it merely changes the point the camera rotates around; the camera position itself doesn't change. You need to move the camera so as to keep the focus point constant, to achieve the effect of zooming. But I may be wrong on this...
Post Reply