Jump to content

TrackObject procedure


Recommended Posts

Hey,

 

is vs.TrackObject work in Pyton VW 2016? I need red highlight selection for my tool. I can run this and red selection works good. How can I do something after mouse click during TrackObject works? After mouse click tool stop working, but i need tool still active or run again. I need tool similar "Number Instrument" from spotlight. I known that this procedure do not block script execution. So i need write all inside callback function.  Is it true ? It is many topics at forum but I can not find solution for my problem.

 

Best for All,

 

Robert

Link to comment

I am not familiar with the Number Instrument tool. Can you please explain more about what you are trying to do so I can make better suggestions.

 

It sounds like you just need to put the TrackObject call in a loop. Call track object. When clicked either process the object or set a variable to exit the loop. Repeat.

 

Maybe??

Link to comment

This is my simple script only for test. It works, but I can not do anything after mouse click. Script go terminate. I tried put TrackObject inside loop but script hang. I tried use vs.MouseDown() but it gets no values. I tried many things, no result. Any idea? I can resolve my problem using vs.GetPt() instead TrackObject but GetPt do not red highlight objects. Red highlight is more interactive so its better for me.

 

TriedObject works in VectorScript because it stop execute script. In Python I can not do anything after TrackObject. Any idea?

 

my simple recipe steps:

- move mouse hover over object. If object meets specified criteria go red highlight (TrackObject do this).

- if mouse click on matching object, change some values in record and repeat script (I have no idea how do this).

- if mouse click on empty space, terminate script.

 

 

def CheckObjCallback(h,x,y):

    type = vs.GetType(h)

    if type == 3:

        vs.Message('Rectangle')

        return 1

    return 0

 

vs.TrackObject(CheckObjCallback)

 

 

 

Edited by Robert Janiak
Link to comment

TrackObject only governs object highlighting.  You still need a tool event loop to continually get the cursor values.  Take a look at 

 

RunTempTool

http://developer.vectorworks.net/index.php/VS:RunTempTool

 

and vstGetEventInfo

http://developer.vectorworks.net/index.php/VS:vstGetEventInfo

 

You can also create a DIY loop with GetPt, exiting the loop of the user clicks on empty space.

 

RunTempTool works best when run form a menu command, as VS tools don't start executing code until you click.  To really control tool behaviors, you have to script with the SDK.

 

HTH,
Josh

Link to comment

My Python is not very good and I don't have time to figure it out tonight, but here is a Vectorscript that is close to what you test script does. You are going to have trouble with your script because the Message command is broken in 2015-2017 and does not work during the execution of a script. It will display the last message after the script completes.

 

This script should been every time you cross over the edge of a rectangle. If you hover just right, you can get it to repeated beep. When you click it should quit.

 

Hopefully this gets you somewhat closer to what you want.

 

Procedure TrackObjectTest;

Var	H2: Handle;
	X1,Y1, Z1: Real;

Function CheckObjCallback(Hd1:Handle; X1,Y1:Real):Boolean;
	Begin
		If GetType(Hd1) =3 then SysBeep;
	End;
	
Begin
	While Not Mousedown(X1,Y1) do
		TrackObject(CheckObjCallback, H2, X1,Y1, Z1);
		
End;

Run(TrackObjectTest);

To do your action or not, just add code into the CheckObj procedure. If Hd1=Nil then set flag to tell the main program to exit the loop.

 

I know I am not being very clear. Maybe tomorrow I can do better.

Link to comment
6 hours ago, JBenghiat said:

TrackObject only governs object highlighting.  You still need a tool event loop to continually get the cursor values.  Take a look at 

 

RunTempTool

http://developer.vectorworks.net/index.php/VS:RunTempTool

 

and vstGetEventInfo

http://developer.vectorworks.net/index.php/VS:vstGetEventInfo

 

You can also create a DIY loop with GetPt, exiting the loop of the user clicks on empty space.

 

RunTempTool works best when run form a menu command, as VS tools don't start executing code until you click.  To really control tool behaviors, you have to script with the SDK.

 

HTH,
Josh

 

I tried this before. I thing in Python this not work. When I put vs.TrackObject inside vs.RunTempTool it crash. I tried capture RunTempTool events action and I get only kToolDoSetup, kToolDoSetDown, kToolDraw, kToolGetStatus. Nothing else.

 

If I use vs.vstGetEventInfo with menu or tool I have no event value. I tried capture events values by writing text file with it. This is my test log. Action is random. I can not find it in SDK. Tell me if you think that I am testing wrong way. I am not programing expert, but I like experimenting wit it.

 

action: 2          msg1: 1514359392       msg2: 1514359392
action: 32        msg1: 1514359392       msg2: 1514359392
action: 32        msg1: 1514359392       msg2: 1514359392
action: 32        msg1: 1514359392       msg2: 1514359392
action: 4          msg1: 1514359392       msg2: 1514359392
action: 32        msg1: 1514362864       msg2: 1514362864
action: 2          msg1: 1514362864       msg2: 1514362864
action: 2          msg1: 1514362864       msg2: 1514362864
action: 2          msg1: 1514362864       msg2: 1514362864
action: 0          msg1: 1514362864       msg2: 1514362864
action: 0          msg1: 1514362864       msg2: 1514362864

 

I am testing vsoGetValue inside object events from Python samples and seem to captured good values.

 

I think that this procedures do not work properly in Python. I will try build my script in old VectorScript or SDK.

Link to comment
5 hours ago, Pat Stanford said:

My Python is not very good and I don't have time to figure it out tonight, but here is a Vectorscript that is close to what you test script does. You are going to have trouble with your script because the Message command is broken in 2015-2017 and does not work during the execution of a script. It will display the last message after the script completes.

 

This script should been every time you cross over the edge of a rectangle. If you hover just right, you can get it to repeated beep. When you click it should quit.

 

Hopefully this gets you somewhat closer to what you want.

 


Procedure TrackObjectTest;

Var	H2: Handle;
	X1,Y1, Z1: Real;

Function CheckObjCallback(Hd1:Handle; X1,Y1:Real):Boolean;
	Begin
		If GetType(Hd1) =3 then SysBeep;
	End;
	
Begin
	While Not Mousedown(X1,Y1) do
		TrackObject(CheckObjCallback, H2, X1,Y1, Z1);
		
End;

Run(TrackObjectTest);

To do your action or not, just add code into the CheckObj procedure. If Hd1=Nil then set flag to tell the main program to exit the loop.

 

I know I am not being very clear. Maybe tomorrow I can do better.

 

I known that Message command do not works good but sometimes it is simple way to get fast result for me. Do you known better way for testing?

 

I thing I have problem because I use Python. In VectorScript seem to works better. I will try write my tool in VectorScript. 

Link to comment

I rewritten my test script in VectorScript. It works !!!. Why in Python it is difficult to do this in the simple way? What should I know to do the same in Python?

 

PROCEDURE Test;
VAR
  h : HANDLE;
  x, y, z : REAL;
  ObjType : INTEGER;
  
  
FUNCTION CheckObjCallback(h : HANDLE; px, py : REAL) : BOOLEAN;
	BEGIN
    	CheckObjCallback := FALSE;
     	IF GetType(h) = 3 THEN
			CheckObjCallback := TRUE;
	END;

BEGIN
	REPEAT  
		TrackObject( CheckObjCallback, h, x, y, z);
		SysBeep;
	UNTIL h = NIL 
END;
RUN( Test );

 

 

Link to comment
2 hours ago, Robert Janiak said:

Why in Python it is difficult to do this in the simple way? What should I know to do the same in Python?

 

Robert, as you have probably surmised, the interactive calls do not work well (if at all) in Python. There have been earlier threads in this forum about vs.GetPt(), vs.GetLine(), vs.GetRect(), etc., with similar complaints. My advice is to use VS for these calls, if you can, until a solution is found for Python. Many people are waiting for these to work in Python. If you do find a way to make it work, please post back with a solution. You will make a lot of people happy.

 

Raymond

Link to comment

I never used this functions but the docu of getpt() says:

 

Quote

In Python this function will NOT block execution. It will execute a callback function with the resulted line (two points as callback function parameters).

 

I guess you have to create a global flag that controls when the execution can go on.

 

wait = True

 

vs.GetPt ()

 

while wait: # Change wait to False in the callback of GetPt

     pass

 

...

 

Maybe this works for TrackObj.

 

 

Edited by Patrick Winkler
  • Like 1
Link to comment

Sorry but this will lead to an infinite loop.

 

Even with a thread I had no succes.

When the main thread is blocked the dialogs and I guess the interactive functions are also blocked.

 

I doubt that there is a working solution.

import vs
from time import sleep

import threading

wait_for_thread = True

class GetPtThread (threading.Thread):
    def __init__ (self):
        super().__init__()    
    
    def run (self):
        '''
        '''
        
        def callback (p):
            global wait_for_thread
            
            vs.AlrtDialog('You slected {}'.format( p ))
            
            # Call this at the end
            wait_for_thread = False
                    
        vs.GetPt(callback)
        vs.AlrtDialog ('Thread Finished')


# Start ne Thread
t = GetPtThread()
t.start()

# Let the main thread wait until this thread has finished.
timeout_secs = 10
t.join(timeout_secs) 

#===============================================================================
# cnt = 0
# while wait_for_thread:
#     sleep(5)
#     cnt += 1
#     
#     if cnt > 4:
#         vs.AlrtDialog(wait_for_thread)
#         break
#===============================================================================
    
vs.AlrtDialog('Script Finished.')

 

 

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...