michnov Posted July 19, 2022 Share Posted July 19, 2022 How to create script for step scaling viewport. For example: tap one button +5 scaling, tap another button twice -10. Quote Link to comment
Jesse Cogswell Posted July 19, 2022 Share Posted July 19, 2022 @michnov There are two approaches to this. The first is to write a separate script for Increase, and a separate script for Decrease. Do this by going to Tools - Plug-ins - Plug-in Manager and creating a new Command. The scripts would look something like this, with the constant kAmount defining the scale amount. The scripts would look something like this: Increase: PROCEDURE IncreaseViewportScale; {Increase scale of selected Viewports by value of constant kAmount} CONST kViewport = 122; VAR currentLayer:STRING; PROCEDURE IncreaseScale(h:HANDLE); {Increases scale and resets given viewport} CONST kAmount = 5; kScale = 1003; VAR currentScale:REAL; BEGIN currentScale:=GetObjectVariableReal(h,kScale); SetObjectVariableReal(h,kScale,currentScale + kAmount); ResetObject(h); END; BEGIN currentLayer:=GetLName(ActLayer); ForEachObject(IncreaseScale,(SEL & (L=currentLayer) & (T=kViewport))); END; Run(IncreaseViewportScale); Decrease: PROCEDURE DecreaseViewportScale; {Decrease scale of selected Viewports by value of constant kAmount} CONST kViewport = 122; VAR currentLayer:STRING; PROCEDURE DecreaseScale(h:HANDLE); {Decreases scale and resets given viewport} CONST kAmount = 5; kScale = 1003; VAR currentScale:REAL; BEGIN currentScale:=GetObjectVariableReal(h,kScale); SetObjectVariableReal(h,kScale,currentScale - kAmount); ResetObject(h); END; BEGIN currentLayer:=GetLName(ActLayer); ForEachObject(DecreaseScale,(SEL & (L=currentLayer) & (T=kViewport))); END; Run(DecreaseViewportScale); You would then bind the scripts to shortcut keys through the Workspace Editor. These scripts would work for any selected viewports on the active layer. The other way to do this would be to make a user interactive "mode" that reacts to key presses. The following code could be put into a drawing by creating a new script through the Resource Manager or by making a new menu command through the Plug-in Manager. The way the code works is that, once started, it is listening for specific key presses, - to decrease the scale, + to increase the scale, and Esc to exit the mode. PROCEDURE ViewportScaleMode; {Allows user to scale selected viewports using + and - keys} CONST kMinusKey = 45; kPlusKey = 61; kEscKey = 27; kViewport = 122; VAR check:BOOLEAN; scaleAmount:REAL; keyHit:LONGINT; currentLayer:STRING; PROCEDURE IncreaseScale(h:HANDLE); CONST kScale = 1003; VAR currentScale:REAL; BEGIN currentScale:=GetObjectVariableReal(h,kScale); SetObjectVariableReal(h,kScale,currentScale+scaleAmount); ResetObject(h); END; PROCEDURE DecreaseScale(h:HANDLE); CONST kScale = 1003; VAR currentScale:REAL; BEGIN currentScale:=GetObjectVariableReal(h,kScale); SetObjectVariableReal(h,kScale,currentScale-scaleAmount); ResetObject(h); END; BEGIN currentLayer:=GetLName(ActLayer); check:=FALSE; scaleAmount:=RealDialog('Enter scale value:','5.00'); AlertInform('Viewport Scaling Mode','Use + and - keys to change scale, ESC to exit',FALSE); WHILE NOT check DO BEGIN IF KeyDown(keyHit) THEN CASE keyHit OF kMinusKey: BEGIN ForEachObject(DecreaseScale,(SEL & (L=currentLayer) & (T=kViewport))); ReDrawAll; END; kPlusKey: BEGIN ForEachObject(IncreaseScale,(SEL & (L=currentLayer) & (T=kViewport))); ReDrawAll; END; kEscKey: check:=TRUE; END; END; END; Run(ViewportScaleMode); One caveat of the second option is that you will get something of a "preview" of the viewport without annotations until the operation is complete. PLEASE NOTE: I wrote and tested the code on a PC. If you are running this on a Mac, there's no guarantee that KeyDown will return the same values, so there's a slight chance that you can get stuck in this mode if the Esc key number doesn't match up. Save all of your work before attempting to use this script. If needed, you can use the following script to determine the number of key presses in case you want to change the keys to something more to your liking or if the keyboards don't match: PROCEDURE KeyScript; VAR keyHit:LONGINT; BEGIN WHILE NOT KeyDown(keyHit) DO SysBeep; AlrtDialog(Concat('Key Pressed: ',Num2Str(0,keyHit))); END; Run(KeyScript); 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.