Search the Community
Showing results for tags 'getpt()'.
-
Hi All So I'm trying to add functionality into an already existing Event based PIO that allows the user to click a button in the OIP and choose a Lighting fixture on the drawing, and get some information from it. The bit I'm struggling with is finding a way to use vs.GetPt() (or any similar user interactive command) within a Python Event based plug in object. The structure of the Plug In is pretty standard, the main outline of which is below. def makeOIP(): global objectHand , BackgrdColourDict, ForeGrdColDict, position_note_rec_name ok, objectName, objectHand, recordHand, wallHand = vs.GetCustomObjectInfo() 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 ok = vs.SetObjPropVS(tb.Constants.kObjXPropPreference,True) # Enables preferences menu for PIO ok = vs.SetObjPropVS(tb.Constants.kObjXHasCustomWidgetVisibilities,True) vs.vsoInsertAllParams() # Inserts all Parameters floato OIP result, scaleWidID = vs.vsoPrmName2WidgetID('','Scale') thisDoesNothing = 0 result = vs.vsoAppendWidget(tb.widgetTypes.WidgetButton, link_pos_button_id,'Get Position Info', thisDoesNothing) if theEvent == tb.Constants.kObjOnWidgetPrep: WidgetPrep() # Sets Info within the OIP if theEvent == tb.Constants.kObjXPropPreference: defaultVals = {} # Creates blank Dict for default vals MakePropertiesDialog() if theEvent == tb.Constants.kObjOnObjectUIButtonHit: # If the event is a button being pressed if theEventData == link_pos_button_id: # If the Button Pressed is Link Position Button link_to_hp() # Runs if theEvent == tb.Constants.kResetEventID: # If Object is reset init() # Creates the Object When the button is pressed it calls a function, link_to_hp() def link_to_hp(): vs.SetObjPropVS(tb.Constants.kObjXHasCustomWidgetVisibilities, False) # Sets widget custom visibility to false try: vs.GetPt(PickPointCallback) except Exception as e: vs.AlrtDialog(str(e)) h, p = 0,0 Fix_H = vs.Rpstr_GetValueStr(tb.ValueStrings.FixtureHandle_TempValString,False) # Stores the Fixture handle as a Vectorworks Value String vs.Message(str(Fix_H)) vs.SetObjPropVS(tb.Constants.kObjXHasCustomWidgetVisibilities, True) # Sets widget custom visibility to True def PickPointCallback(pt): vs.Message('X: ', pt[0], 'Y: ', pt[1]) Fix_H = vs.vstGetPickObject(pt[0],pt[1]) # Stores the fixture handle as a VWX Value string for retrieving later after GetPt callback has been run vs.Rpstr_SetValueStr(tb.ValueStrings.FixtureHandle_TempValString,Fix_H) vs.SetObjPropVS(tb.Constants.kObjXHasCustomWidgetVisibilities, True) # Sets the Custom Widget visibulites back to True The main issue I'm having is that whenever I press the button, the GetPt cross hairs appear, I'm able to select a point, but then Vectorworks crashes, with no error message. I understand the main issue is that the Python function GetPt will not block execution, so I need to use the callback function. However I am still getting the same results. From a fair amount of searching of the forums, I have found several suggested solutions such as @Paolo suggestion in this thread to disable custom widget visibilities whilst vs.GetPt is running, however sadly this does not seem to have any affect. I've seen suggestions that there cannot be any functions inbetween the GetPt call, purely as a test I've tried adding a vs.GetPt() at the end of the of the file, with some very dodgy logic to allow it only to run after the UIButton has been hit. E.g: makeOIP() if runGetPt: vs.GetPt(PickPointCallback) Still no improvement, still crashes with no error. I've tried completely emptying the PickPointCallback, in case it was something inside there, but still no change. Does anyone have any suggestions as to how to achieve this kind of functionality within a Python Script? Surely people have managed to find a way around this? @Vlado @JBenghiat @twk Thank you in advance!
-
Hi, Some years ago I wrote a few tools in Vectorscript based on a number stamp. The idea is simple enough: enter a starting number in a dialog, start clicking, the number increments and is "printed" in the drawing on each mouse click. In the actual implementation there is other stuff going on too, but it's just this part I need help with at the moment. The Vectorscript tools work fine, but now I would like to re-write them in Python, but I can't get it working at all! This is because I am probably too stupid to understand what I need to do, but also it is because of the way GetPt() seems to works in Python. Also I don't get how to use KeyDown() in Python. I am open to any suggestion on how to do this in python in any way it works: Enter a starting number in a dialog Start clicking to add numbers (as text) that increment with each mouse click. It seems like this should be simple enough, but I have been trying to get it to work for a while and i can't! Any help would be much appreciated. Here, below, is a simplified version of my Vectorscript that works fine, and below that one example of how I have tried (and failed miserably) to translate it to Python: { V4 Simple Number Stamp Tool By: Benedick Miller Date: 2014-10-06 } Procedure SimpleNumberStamp; VAR n,i,keyhit:INTEGER; pt:POINT; t:STRING; BEGIN n:=IntDialog('Enter the starting number','1'); IF NOT DidCancel THEN keyhit:=27; i:=1; DSelectAll; while not keydown(keyhit) do begin t:=num2Str(0,n); getpt(pt.x,pt.y); TextOrigin(pt.x,pt.y); CreateText(t); n:=n+i; redrawall; end; END; Run(SimpleNumberStamp); And the Python translation: # Print Incremental Numbers on each mouse click until [Esc] # NOT WORKING!!! import vs def label(pt): vs.TextOrigin(pt[0],pt[1]) vs.CreateText(str(n)) vs.ReDraw() def kdwn(): k=vs.KeyDown() return k[1] keyhit = 27 i = 1 n = 1 vs.DSelectAll() n = vs.IntDialog('Enter the starting number', n ) if not vs.DidCancel(): while not kdwn() == keyhit: vs.GetPt(label) n = n + i
- 3 replies
-
- number stamp
- python
-
(and 1 more)
Tagged with: