Orthographic/Perspective auto switch
Forum rules
and Helpful information
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help
Also, be nice to others! Read the FreeCAD code of conduct!
Also, be nice to others! Read the FreeCAD code of conduct!
Orthographic/Perspective auto switch
Hi, I'm new to FreeCAD, great program. I'm working on the LEGO brick tutorial in the Yorik's manual. I played in the past with Rhino3D ans Sketchup and I'm used to work in perspective view mode, that I prefer with respect to orthographic projection. However, I admit that in the Sketcher tool the better viewing projection is orthographic. I was wondering if it is possible to get 'automatically' switched this two modes, when I change the benchmark between Sketcher and PartDesign. Thanks and regards.
Gigi
[EDIT]: It seems that the keyboard shortcuts V,O V,P doesn't work in Sketcher
--------------------------------------------
OS: Ubuntu 19.10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.3.
Build type: Release
Python version: 3.7.4
Qt version: 5.12.4
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)
Gigi
[EDIT]: It seems that the keyboard shortcuts V,O V,P doesn't work in Sketcher
--------------------------------------------
OS: Ubuntu 19.10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.3.
Build type: Release
Python version: 3.7.4
Qt version: 5.12.4
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: Orthographic/Perspective auto switch
Use the macro openBrain created here:
https://forum.freecadweb.org/viewtopic.php?f=22&t=43390
Create a new view in the view menu. Set the workbench and desired view mode for each view tab. When you switch between tabs the view mode is remembered.
https://forum.freecadweb.org/viewtopic.php?f=22&t=43390
Create a new view in the view menu. Set the workbench and desired view mode for each view tab. When you switch between tabs the view mode is remembered.
Re: Orthographic/Perspective auto switch
If needed, I can tweak a bit the macro so it fit your needs without need to open several views. Let me know.
Re: Orthographic/Perspective auto switch
Hi!
I'd like for the exact same thing to happen. Sketcher in ortho-mode, everything else in perspective mode (also for the reason that the text displayed for constraints is broken in perspective view and gets unreadably small). I tried the macro, but i don't get how it is supposed to do that.
OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23756 (Git)
Build type: Release
Branch: master
Hash: 9c6e9184930a52b165a0b7274e3a45d1006bfe67
Python version: 3.8.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: German/Austria (de_AT)
I'd like for the exact same thing to happen. Sketcher in ortho-mode, everything else in perspective mode (also for the reason that the text displayed for constraints is broken in perspective view and gets unreadably small). I tried the macro, but i don't get how it is supposed to do that.
OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23756 (Git)
Build type: Release
Branch: master
Hash: 9c6e9184930a52b165a0b7274e3a45d1006bfe67
Python version: 3.8.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: German/Austria (de_AT)
Re: Orthographic/Perspective auto switch
Ok, so I tried this (I recorded a macro and then changed the commands it created, and looked at the macro linked above):
The camera type gets changed when I open a sketch, but it does not switch back when closing the sketch. The camera does switch back and forth as I would expect it when I use the workbench dropdown. The Gui.runCommand() active or not does not change that (the macro recorder created them but they seem not to be needed). Btw. I found that Gui.activeWorkbench().name() is undefined at the first call of the event handler for every workbench type after the restart of FreeCAD; in subsequent ones Gui.activeWorkbench().name() is the same as wb.
The difference when closing the sketcher is that the model is recomputed, while just selecting a different workbench does not do that. The debug messages appear in all cases though. How can I do the switch reliably? Is there some event like "viewReady"?
[EDIT] I just found that it is the sketcher option "restore camera position after editing" that sets the camera to orthgraphic mode. Guesswork again: it saves the camera parameters right after entering the sketcher, but before moving the camera to the top view. But apparently at that point the camera has already been set to orthgraphic by my macro. I do like the restoration of the camera position. How can I call my macro after the "save"/"restore" functions have run?
Code: Select all
import FreeCADGui as Gui
def on_wb_changed(wb):
print(wb)
if wb == 'SketcherWorkbench':
print('O')
Gui.activeDocument().activeView().setCameraType('Orthographic')
#Gui.runCommand('Std_OrthographicCamera',1)
#Gui.runCommand('Std_PerspectiveCamera',0)
else:
print('P')
Gui.activeDocument().activeView().setCameraType('Perspective')
#Gui.runCommand('Std_PerspectiveCamera',1)
#Gui.runCommand('Std_OrthographicCamera',0)
Gui.getMainWindow().workbenchActivated.connect(on_wb_changed)
The difference when closing the sketcher is that the model is recomputed, while just selecting a different workbench does not do that. The debug messages appear in all cases though. How can I do the switch reliably? Is there some event like "viewReady"?
[EDIT] I just found that it is the sketcher option "restore camera position after editing" that sets the camera to orthgraphic mode. Guesswork again: it saves the camera parameters right after entering the sketcher, but before moving the camera to the top view. But apparently at that point the camera has already been set to orthgraphic by my macro. I do like the restoration of the camera position. How can I call my macro after the "save"/"restore" functions have run?
Re: Orthographic/Perspective auto switch
My solution, that works well for me now (including restoring the camera position):
IMHO a function like this should be coming with FreeCAD out of the box (like the option "restore camera position"). I've set up the script as a startup macro. The camera type is now set after a delay of 100ms by a timer and not immediately on the workbench change. At that point FreeCAD has apparently done all it's other stuff that it wants to do with the camera and setting the camera type "sticks".
Code: Select all
from PySide.QtCore import QTimer
import FreeCADGui as Gui
timer = None
wb = None
def set_camera():
timer.stop()
print('setting camera for ' + wb)
if wb == 'SketcherWorkbench':
print('Orthographic mode')
Gui.ActiveDocument.ActiveView.setCameraType('Orthographic')
else:
print('Perspective mode')
Gui.ActiveDocument.ActiveView.setCameraType('Perspective')
def on_wb_changed(workbench):
global wb
wb = workbench
print('wb change')
timer.start(100)
def setup_macro():
global timer
timer = QTimer()
timer.timeout.connect(set_camera)
Gui.getMainWindow().workbenchActivated.connect(on_wb_changed)
##Ensure main instructions are still called in case of manal run
if __name__ == '__main__':
setup_macro()
Re: Orthographic/Perspective auto switch
Bad guess. The problem is your macro Actually you change the camera type when entering Sketcher WB to orthographic. But the camera save isn't done yet as it only happens when the Sketcher enters edit mode -- that happens after the WB switch --. So the orthographic view that is restored is just the one you set up.Lupin wrote: ↑Sat Mar 13, 2021 12:57 pm [EDIT] I just found that it is the sketcher option "restore camera position after editing" that sets the camera to orthgraphic mode. Guesswork again: it saves the camera parameters right after entering the sketcher, but before moving the camera to the top view. But apparently at that point the camera has already been set to orthgraphic by my macro.
Anyway, I just submitted a PR to add the option in Sketcher preferences to 'force orthographic view when entering edit mode'.
Re: Orthographic/Perspective auto switch
PR merged as version #24893. Will be available in weekly builds with at least this version number.
Re: Orthographic/Perspective auto switch
I have an option to do that in my Vision macro. It's old and the code is rough but I still use the macro daily. Maybe looking around the code will give you some ideas.
https://forum.freecadweb.org/viewtopic. ... 20#p427049
I call the option 3D view sketch and it keeps the current view so there is no change to ortho or go normal when a sketch is opened.
https://forum.freecadweb.org/viewtopic. ... 20#p427049
I call the option 3D view sketch and it keeps the current view so there is no change to ortho or go normal when a sketch is opened.
Re: Orthographic/Perspective auto switch
Close enough for meopenBrain wrote: ↑Thu May 06, 2021 4:59 pm Bad guess. The problem is your macro Actually you change the camera type when entering Sketcher WB to orthographic. But the camera save isn't done yet as it only happens when the Sketcher enters edit mode -- that happens after the WB switch --. So the orthographic view that is restored is just the one you set up.
Thanks a lot! I will keep using my macro for now, because I'm pretty much only working with release versions (I'm more of a user than a developer). But nevertheless it's good to see that my "hack" is made obsolete in the future.