Jump to content
tbexon

TrackObjectN

Recommended Posts

I know this has been discussed in several threads before, but after extensive reading and experimenting I'm still clearly missing something.

 

I'm trying to get the handle for a user selected object within an event enabled Plug in Tool. 

e.g

User clicks button in OIP -> Highlight mode is turned on and user clicks on desired object -> Handle is returned and code continues onwards.

 

I've created the event enabled object, and added the button to the OIP fine, and used TrackObjectN() to allow highlighting of only relevant objects. 

 

The issue I'm running into is actually getting the handle of the object. I understand that TrackObjectN is only highlighting, and not a selection mode, but from my reading of the wiki for TrackObjectN:

def vs.TrackObjectN(traverseType, callback):
    return (outObj, p)

It should return the handle and Co Ords whenever the user mouses over or clicks an object that relates to the criteria. e.g if the last action is a click on the desired object it should return that handle, or atleast it's co ordinates from which I could then use PickObject to get the handle.

In reality when I try:

outObj , p = vs.TrackObjectN(0, trackObjCallback)

It throws a TypeError 'NoneType' object is not iterable. 

 

Given that when I try:

vs.TrackObjectN(0,trackObjCallback)

It functions as expected, but without returning any handle or co ordinates i'm guessing either i'm using this wrong or it doesn't actually return such information.

 

I'm wondering if I need to try using vstGetEventInfo to look for a mouse button click and then capture the mouse's current Co Ordinates, however after searching "MiniCadHookIntf.h" I couldn't obviously see any obvious constant for a mouse click.

 

TL/DR I'm trying to capture a handle for a user selected object, within a event enabled object and have clearly missed a step somewhere!

 

Any help or nudges in the right direction would be greatly appreciated!

 

Relevant parts of current code pasted below:

 

import vs

def makeOIP():
    link_pos_button_id = 1234  # User Button Id

    theEvent, theEventData = vs.vsoGetEventInfo()  # Gets Object Event info

    if theEvent == tb.Constants.kObjOnInitXProperties:  # If the event is the initialisation of the object
        ok = vs.SetObjPropVS(tb.Constants.kObjXPropPreference, True)  # Allows for creation of custom OIP??????
        ok = vs.SetObjPropVS(tb.Constants.kObjXPropHasUIOverride, True)  # Custom OIP Overrides standard UI
        vs.vsoInsertAllParams()  # Inserts all Parameters into OIP

        displayString = "Link to HP"  # text for button
        result = vs.vsoAppendWidget(tb.Constants.kWidgetButton,link_pos_button_id,displayString,doesNothing())  # Add Button to OIP

    if theEvent == tb.Constants.kObjOnObjectUIButtonHit:  # If the event is a button being pressed
        if theEventData == link_pos_button_id:
            link_to_hp()  # Function to run to allow user to select object.
    if theEvent == tb.Constants.kResetEventID:  # If Object is reset
		# Code to run on object reset

def doesNothing():
    pass


def trackObjCallback(h,x,y):

    HPHandle = vs.PickObject((x,y))

    if vs.GetTypeN(h) == 86:
        return True
      
def link_to_hp():
 
	vs.TrackObjectN(0, trackObjCallback)
    outAction, outMessage1, outMessage2 = vs.vstGetEventInfo()


    #vs.Message(str(outObj))
    
makeOIP()

 

Share this post


Link to post

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.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...