FMA Posted April 25 Share Posted April 25 I have to ask this again, I thought I would get it to work but I still didn't. How is it possible to interrupt/get input during the RunTempTool Function? RunTempTool from the function reference: (This draws a simple temporary line and the function gets interrupted with the first mouse click, so far so good) PROCEDURE Test; VAR pt1, pt2 : POINT; FUNCTION TempToolCallback(action, msg1, msg2 : LONGINT) : LONGINT; VAR pt : POINT; BEGIN TempToolCallback := 0; CASE action OF 3: BEGIN {kOnToolDoSetupEventID} vstSetHelpString ( 'Just click once.' ); END; 103 : BEGIN {kToolDrawEventID} vstGetCurrPt2D( pt.x, pt.y ); vstDrawCoordLine( pt.x, pt.y, pt1.x, pt1.y ); END; END; END; BEGIN pt1.x := 0; pt1.y := 0; RunTempTool( TempToolCallback, FALSE ); END; RUN( Test ); But in the Function reference someone also wrote that: If toolCallback returns 0 it exits on first click, if it returns 1 it keeps gathering clicks. The thing is, if I set TempToolCallback:= 1, then the function will just go on for ever. I've tried setting TempToolCallback to 0 and that technically works, but in a very unreliable way. For example: PROCEDURE Test; VAR pt1, pt2 : POINT; key: LONGINT; bool: BOOLEAN; FUNCTION TempToolCallback(action, msg1, msg2 : LONGINT) : LONGINT; VAR pt : POINT; BEGIN TempToolCallback := 0; IF bool = FALSE THEN TempToolCallback := 1 ELSE TempToolCallback := 0; IF KeyDown(Key) = TRUE THEN bool:= TRUE; message(bool); CASE action OF 3: BEGIN {kOnToolDoSetupEventID} vstSetHelpString ( 'Just click once.' ); END; 103 : BEGIN {kToolDrawEventID} vstGetCurrPt2D( pt.x, pt.y ); vstDrawCoordLine( pt.x, pt.y, pt1.x, pt1.y ); END; END; END; BEGIN bool:= FALSE; pt1.x := 0; pt1.y := 0; RunTempTool( TempToolCallback, FALSE ); END; RUN( Test ); This will set the Callback to 0 when a key is pressed (Which will stop it at the next click) but the RunTempTool in VS only appear to be running when the mouse is moved. So the Key input can only be registered while the mouse is moving. Using IF MouseDown(X,Y) = TRUE THEN bool:= TRUE; is even more inconsistent (It is also very unintuitive for the user to move the mouse while for example clicking on a point). Getting Key input during a RunTempTool Function is also generally difficult when the Callback is just 0 and the function simply runs once (I believe that is, as I said, because the function only runs when mouse movement is detected). Has anybody got their head wrapped around this Function or found convenient ways to declare the callback, or found a work around? I've spent quite some time with it now and I would really like to get it. There also appears to be a dimension with the tool events to it that I don't fully understand (CASE action OF 3, 103 etc). Quote Link to comment
Pat Stanford Posted April 28 Share Posted April 28 What are you actually trying to do? That might help us give you a better answer. What about adding code to compare the most recent point collected to the previous point. If they are equal then set TempToolCallback to Zero. Then you only need to double click to end the point collection. Quote Link to comment
FMA Posted April 28 Author Share Posted April 28 I want to draw a 2D object that requires multiple user input steps to be completed. For example like the rectangle tool: The second click sets the length of one side, the third click sets the length of the second side, all while a temptool is running. My object is a little bit more complicated than that and I would like it to be possible to have divergent options during the process, for example if you press COMMAND between the second and third step then the rectangle will be rounded, or if you press SHIFT then the rectangle will have even sides etc. This requires Key (Or mouse) input to be registered during the Running of the Temptool function (if you want the change to be immediately visible via the temptool). And this is as far as I know only possible while the mouse is being moved, which makes the whole thing a little bit unhandy, though not completely unworkable. Now when it comes to letting the temptool run continiously, by setting TempToolCallback:= 1, I am kind of at a loss on how to make use of that. The Mouse input during the Temptool just seems to be erratic. For example this script will at times end after you click twice, and at times after you click thrice, depending on how you shuffle around with the mouse: PROCEDURE Test; VAR pt1 : POINT; key: LONGINT; bool: BOOLEAN; X,Y: REAL; FUNCTION TempToolCallback(action, msg1, msg2 : LONGINT) : LONGINT; VAR pt : POINT; BEGIN TempToolCallback := 0; IF MouseDown(X,Y) = TRUE THEN bool:= TRUE; IF bool = FALSE THEN TempToolCallback := 1 ELSE TempToolCallback := 0; message(bool); CASE action OF 3: BEGIN {kOnToolDoSetupEventID} vstSetHelpString ( 'Just click once.' ); END; 103 : BEGIN {kToolDrawEventID} vstGetCurrPt2D( pt.x, pt.y ); vstDrawCoordLine( pt.x, pt.y, pt1.x, pt1.y ); END; END; END; BEGIN bool:= FALSE; pt1.x := 0; pt1.y := 0; RunTempTool( TempToolCallback, FALSE ); message(x,' ',y); END; RUN( Test ); Have you, or anybody ever used this aspect of the function in a program in some useful way? I would very gladly be taking notes about that. Quote Link to comment
Pat Stanford Posted April 28 Share Posted April 28 I have not used RunTempTool. Why does the command down need to be inside the loop? Why not end your object with a double click and then do the check for the keydown outside of the Callback? Have you seen this thread? Quote Link to comment
FMA Posted April 29 Author Share Posted April 29 Because I would like the Key input to have an impact on the TempToolFunction. For example the temporary function draws a circle, and when I press a button it draws a rectangle. Doing this after the temptool function would require more clicks which is not optimal because I want this whole thing as efficient as possible. I think I have actually seen this before. I am very unfamiliar with tool events, so I couldnt understand too much of it. Quote Link to comment
FMA Posted April 29 Author Share Posted April 29 But the other problem might be related to the issue I have, the RunTempTool Function also 'waits' to get mouse input/change in mouse position. I have never gotten it to run in Python in the first place though, and that might also be the reason of it. Quote Link to comment
Pat Stanford Posted April 29 Share Posted April 29 I don't think you are going to be able to create your vision in a basic Vectorscript. I think you will need to go to an Event Enabled script that will give you far more control over how the object/tool interacts with the UI. I have never done Event Enabled, so I will not be much help there. @Jesse Cogswell has done several posts about Event Enabled including this one with an example script. I think he did another longer text description also, but I can't find it right now. Python (at least the VW implementation) does not have a good way to pause execution while waiting for operator input, so you might be better off keeping this object in Vectorscript to make using the UI commands simpler. Good Luck. 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.