Is there a script to toggle local and world coordinate?

Is there a script to toggle local and world coordinate?

Comments

  • SofaCitizenSofaCitizen Posts: 1,881

    Why do you need a script to do this? You can just use the drop-down in the Tool setting panel.

  • JamesJames Posts: 1,025

    efficiency.
    Since I switch between them many times.
     

  • SofaCitizenSofaCitizen Posts: 1,881

    Fair enough. I did look to see if there was a menu item you could assign a hotkey to which would do the job but I didn't spot one. There is no search there so I might have missed it.

    I haven't heard of an existing script that would do this but a quick look in the API shows that DzUniversalTool::setCoordinateSpace() exists and so I imagine it's certainly possible to have a script that does this.

  • SofaCitizenSofaCitizen Posts: 1,881

    My Bad! There is an example script that almost does this: View_Tool_Set_Coordinate_Space.dsa - that will force the coordinates to WorldSpace. Technically you can then make a copy and swap the values in line 60 to make a version that forces LocalSpace.  However, if you check in this thread then Flortale has already done the work to turn that script into the toggle you wanted. The forum CSS turns the inline code into an unhelpful ribbon that scrolls of the side of the page, but if you click to quote that post and then double-click the code block it turns into something from which you can copy and paste.

    You can then save this script in your My Library/Scripts folder, right click it and create an action and then finally go into Window->Workspace->Customise and assign a hotkey to it.

     

  • JamesJames Posts: 1,025

    Doesn't seem to work the script in that thread.
    Nothing happens

  • SofaCitizenSofaCitizen Posts: 1,881

    It was working for me when I tried it. However, it is tied to the Universal (move + rotate) tool tho, are you using a different tool?

  • JamesJames Posts: 1,025
    edited July 2023

    I tried universla, rotate, move
    This script right?

    // Define an anonymous function;// serves as our main loop,// limits the scope of variables(function(){ 	// Get the viewport manager	var oViewportMgr = MainWindow.getViewportMgr();	// If we don't have an viewport manager	if( !oViewportMgr ){		// We're done...		return "";	} 	// Find the tool;	// DzUniversalTool, DzUniversalRotateTool, DzUniversalTranslateTool, DzUniversalScaleTool	//var oTool = oViewportMgr.findTool( "DzUniversalRotateTool" );	// If the tool was not found	//if( !oTool ){		// We're done...	//	return;	//}        // Find the tool;	// DzUniversalTool, DzUniversalRotateTool, DzUniversalTranslateTool, DzUniversalScaleTool	//var oTool = oViewportMgr.findTool( "DzUniversalTranslateTool" );	// If the tool was not found	//if( !oTool ){		// We're done...	//	return;	//}     // get active tool    var oTool = oViewportMgr.getActiveTool();    // get current tool coordinate space    var oToolCoordinateSpace = oTool.getCoordinateSpace();        // if local space    if (oToolCoordinateSpace == DzUniversalTool.LocalSpace) {        // Set the coordinate space of the tool to world space        oTool.setCoordinateSpace( DzUniversalTool.WorldSpace );    } else {        // Set the coordinate space of the tool to local space        oTool.setCoordinateSpace( DzUniversalTool.LocalSpace );    }    //} // Finalize the function and invoke})();
    Post edited by James on
  • SofaCitizenSofaCitizen Posts: 1,881

    That looks to be the right script but it could be that the silly formatting of the code block has broken it. I tried to attach it to this post but the uploads are still broken and actually now returning a write failure rather than just hanging forever.

    I have uploaded it here for the time being: sofacitizen.uk/files/misc/Toggle Universal Tool CoOrdinates.dsa

    With this, I have saved it into the scripts folder of My LIbrary, right-clicked on it in Content Library and created a custom action. Then gone into Window->Workspace->Customise, expanded the "Custom" section under Actions, right-clicked on the script and "Changed Keyboard Shortcut", picked a key combo and then hit Accept. With this done I created a new Primative, made sure the UniversalTool was active and the Tool Settings panel is open. Then when hitting the key combo I chose I could see the tool switching from World Coordinates to local and back again. To see it change on the tool widget you do have to rotate the primative a bit first since by default it is positioned in a way that world and local corrdinates are the same.

    Hopefully that helps.

  • JamesJames Posts: 1,025
    edited July 2023

    It works! Thank you.
     

    Post edited by James on
Sign In or Register to comment.