Jump to content
nkunstle

Color parameter (with picker) in OIP

Recommended Posts

New to scripting for vectorwork, so apologies if I am asking a simple question...

 

I am scripting a PIO that includes a collection of lights, I want to put a parameter in the OIP that works like the color picker that shows up there when inserting an individual light.  Functionally I can do numerical fields to capture the RGB data but without the color picker it's a long processes to get the right color.  Is there any way to put a "color" parameter in a python script so that it shows up in the OIP as a color picker button? 

Share this post


Link to post

The light objects are part of Vectorworks’ core, so their interface elements aren’t part of any of the APIs. As far as I know, you’ll have to use a button widget to call a custom dialog with a color pop up. 

Share this post


Link to post
On 6/12/2018 at 10:50 PM, JBenghiat said:

The light objects are part of Vectorworks’ core, so their interface elements aren’t part of any of the APIs. As far as I know, you’ll have to use a button widget to call a custom dialog with a color pop up. 

 

Thanks for the quick response.  Trying to work through creating the custom dialogues, I'll let you know my progress in a few days.  Is there a direction you can point me to in order to learn how to insert the button widget in the OIP?  Most of the OIP stuff I have done so far are parameters defined by the "Parameters" tab in the "Edit Definition" window.

Share this post


Link to post

Search the archive (including Vectorscript) for event enabled objects.  You will have to add some more structure to your code to handle events (your current code goes in the reset event).  The InitXProperties event allows you to add buttons (as well as set other properties), and you will also get an event when the user clicks on a button.

  • Like 1

Share this post


Link to post

Josh, Custom menu now working now just trying to get the OIP button.  I am  rewriting the Vectorlab Events demo3 from Vectorscript to Python so I understand how events work.  @JBenghiat Thank you so much fo all of your help, not sure I would even have made it this far without your help!!

 

Still having an issue with my event based scripts.  The code below compiles and executes without errors however the code in the reset block never runs, so I never get my rect object.  I am VERY new to this so I am sure there is a rookie mistake somewhere, .  Also if you see other things in the code structure that I can improve let me know, just learning python so I am sure the code has room to improve.

 

import vs
def run():
 #Declare constants
 kObjOnInitXProperties = 5
 kResetEventID = 3
 kObjXPropPreventWallInsertion = 7
 kObjXPropHasUIOverride = 8
 kWidgetButton = 12
 kObjOnObjectUIButtonHit = 35
 buttonID_1 = 1234
 thisDoesNothing = 0
 #this call gets the event ID and button if applicable
 theEvent, theButton = vs.vsoGetEventInfo()
  
 #If its the property inialization event - Do this
 if theEvent == kObjOnInitXProperties:
  
  vs.SetObjPropVS(kObjXPropPreventWallInsertion, True)
  vs.SetObjPropVS(kObjXPropHasUIOverride, True)
  vs.vsoInsertAllParams()
  sourceFieldNumber = 1
  displayString = 'My Great Field Name'
  vs.vsoAppendParamWidget(sourceFieldNumber, displayString, thisDoesNothing);
  displayString = 'My Great Button';
  vs.vsoAppendWidget(kWidgetButton, buttonID_1, displayString, thisDoesNothing);
    
 #If The button is pressed detect which button and Do this        
 elif theEvent == kObjOnObjectUIButtonHit:
  if theButton == buttonID_1:
   vs.AlrtDialog('Custom Button Dialog')
                
  #Where the standard PIO scripting goes to generate the object when reset us called
  elif theEvent == kResetEventID:
   vs.Rect(0, 0, 1, 1)
run()

 

Share this post


Link to post

Just a quick glance, but python uses leading white space to determine code structure. I think you have some extra space before the final elif. 

  • Like 1

Share this post


Link to post

Facepalm 🤦‍♂️, can't believe I missed that, I think I stared at that code for an hour before I gave up.  Anyway thanks for helping me find my solve! 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

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.

×