Jump to content

Dropdown Menu


Recommended Posts

Hi

 

I am trying to read a csv file and create a drop down menu item. I have the reading of csv working, however I can't seem to get the drop down to work. I have started with the sample code from the Vectorworks Developer, however when I run the code I don't get any options in the drop down.

 

Also, I don't know that I really understand what the code is doing, can someone shed so light on how this should be working.

 

Here is the code I working with.

 

https://developer.vectorworks.net/index.php/VS:AddChoice

 

When I run the code I get a empty drop down.

 

Thanks

 

 

Link to comment

Sorry, the code is a direct copy from the website. 

 

 

#***************************************************************************

import vs

import math

import csv

 

def execute():

 

#*****************************************************

#Functions

#*****************************************************

 

#*****************************************************

def AddChoiceSample():

#*****************************************************

# control IDs

    global kCreatePullDownMenu

    global kCreatePullDownMenuGroupBox

    global kCreateListBox

    global kCreateListBoxN

    global kCreatePushButton

    global SetupDialogC

    kCreatePullDownMenu = 33

    kCreatePullDownMenuGroupBox = 34

    kCreateListBox = 29

    kCreateListBoxN = 30

    kCreatePushButton = 100

    SetupDialogC = 12255


 

#*****************************************************

def Dialog_Handler(item, data):

#*****************************************************

    if (item == SetupDialogC):

        vs.AddChoice( dialog, kCreatePullDownMenu, 'kCreatePullDownMenu choice', 0 )

        vs.AddChoice( dialog, kCreatePullDownMenuGroupBox, 'kCreatePullDownMenuGroupBox choice', 0 )

        vs.AddChoice( dialog, kCreateListBox, 'kCreateListBox choice', 0 )

        vs.AddChoice( dialog, kCreateListBoxN, 'kCreateListBoxN choice', 0 )

 

#*****************************************************

def CreateMyDialog():

#*****************************************************

    global dialog

    dialog = vs.CreateLayout( 'Select Panel to Import', 1, 'OK', 'Cancel' )

 

#{create controls}

    vs.CreatePullDownMenu( dialog, kCreatePullDownMenu, 24 )

    vs.CreatePullDownMenuGroupBox( dialog, kCreatePullDownMenuGroupBox, 24, 'pull down menu', 1 )

 

    vs.CreatePushButton( dialog, kCreatePushButton, 'push button' )

    vs.SetFirstGroupItem( dialog, kCreatePullDownMenuGroupBox, kCreatePushButton )

 

    vs.CreateListBox( dialog, kCreateListBox, 24, 4 )

    vs.CreateListBoxN( dialog, kCreateListBoxN, 24, 4, 1 )

 

#{set relations}

    vs.SetFirstLayoutItem( dialog, kCreatePullDownMenu )

    vs.SetBelowItem( dialog, kCreatePullDownMenu, kCreatePullDownMenuGroupBox, 0, 0 )

 

    vs.SetBelowItem( dialog, kCreatePullDownMenuGroupBox, kCreateListBox, 0, 0 )

    vs.SetBelowItem( dialog, kCreateListBox, kCreateListBoxN, 0, 0 )

 

    if vs.RunLayoutDialog( dialog, Dialog_Handler ) == 1:

pass

 

 

#*****************************************************

# Main Code

#*****************************************************

    kCreatePullDownMenu = 0

    kCreatePullDownMenuGroupBox = 0

    kCreateListBox = 0

    kCreateListBoxN = 0

    kCreatePushButton = 0     

   SetupDialogC = 0

   dialog = 0

   AddChoiceSample()

   CreateMyDialog()

 

#*****************************************************

# End of Code

#*****************************************************



 

Link to comment

This particular example has some indeed issues, but that may just be cut and paste.

 

Your dialog handler is where you add options to your controls. The SetupDialog event gets called when you first see the dialog, so this is where you would typically load the initial values for the pull-down. As expected, you see the value 'kCreatePullDownMenu choice' as your menu item.

 

Each dialog has an integer ID number, that gets created by the vs.CreateLayout call. Each control in the dialog has an ID number that you manually set. Therefore, the ID numbers are constants, and you can just define them once and, because you do not change them, worry about declaring them as globals.

Link to comment

So I got it work correctly by NOT using any of the code from the documentation and reworking an existing script that was working.

 

Now I have a different question, can I have two dropdown and have the first control the content of the second.

 

For example, the first is supplier, the second is part numbers. If the supplier changes, the part numbers would update with only parts to the correct supplier. I can setup the arrays when I read the csv file, the question is how would I clear the contents of the second dropdown (part numbers) when the first changes.

 

Thanks

 

Link to comment

Hi @Martin Crawford ,

   Yes. When you make a change to the first, you will have to erase the second menu and repopulate it with new values.

See documentation on vs.RemoveChoice(), and vs.AddChoice().

 

   These calls will be issued in your dialog event loop under the item number that controls the first menu. To delete the second menu, execute a loop that deletes the first item of the second menu n-times, where n is the number of items currently in the menu. Then add your new choices.

 

HTH,

Raymond

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...