Created
May 23, 2024 00:34
-
-
Save Fenixdg3duy/3b6ce1d450173665a17329b7209d58bc to your computer and use it in GitHub Desktop.
switchcam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc switch_camera() { | |
// List of camera names in the cycle | |
string $cameras[] = {"persp", "front", "side", "top"}; | |
// Get the current camera | |
string $current_camera = `lookThru -query`; | |
// Determine the next index in the cycle | |
int $current_index = -1; | |
// Iterate through camera list to find current camera index | |
for ($i = 0; $i < size($cameras); $i++) { | |
if ($cameras[$i] == $current_camera) { | |
$current_index = $i; | |
break; | |
} | |
} | |
// Get the next index in the cycle | |
int $next_index = ($current_index + 1) % size($cameras); | |
// Switch to the next camera in the cycle | |
lookThru $cameras[$next_index]; | |
// Center and adjust the view in all panels | |
fitAllPanels -selectedNoChildren; | |
// Print a message indicating the switched camera | |
print("Switched to camera: " + $cameras[$next_index]); | |
// Check if the current camera is perspective | |
if ($cameras[$next_index] == "persp") { | |
// You can adjust this value as needed | |
float $distance = 2.0; | |
// Move camera closer for perspective view | |
dolly -distance $distance; | |
} else { | |
// If it's not perspective, adjust the orthographic width | |
// Adjust orthographic width for non-perspective views | |
setAttr ($cameras[$next_index] + ".orthographicWidth") 15; | |
} | |
// Check if there are any selected objects | |
string $selectedObjects[] = `ls -selection`; | |
if (size($selectedObjects) == 0) { | |
// Apply viewFit if no objects are selected | |
viewFit; | |
} | |
} | |
// Execute the function to switch the camera and apply corresponding adjustments | |
switch_camera(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment