Jump to content
Developer Wiki and Function Reference Links ×

Event Enabled Noob questions


Recommended Posts

I've finally taken the first step over the event enabled line.  {Thanks @Sam Jones!}

 

Question 1:  Now that I can populate the OIP with buttons, can those buttons be used to open a symbol picker or texture picker?

 

How?  Or is there a better way to do this?

 

Question 2:  Is it possible to make the plug-in use styles?  (This probably deserves its own thread.)

Link to comment
  • Vectorworks, Inc Employee

A1. For symbols there are a couple of approaches you can take.

 

Firstly, you can create a custom dialogue containing the symbol picker, which will allow you to choose symbols from different sources. Likely you will want a limited list however, so will need to use one of the BuildResourceList() calls to filter what symbols are displayed. You can then use the older picker (CreateThumbnailPopup in the custom dialogue), or the more commonly seen one that accesses the Resource Selector  (eg. choose the Style Menu > Replace option in Base Cabinet, Fireplace, Table & Chairs, etc.

 

Secondly you can create a popup menu in the OIP containing a dynamic curated list of symbol names to choose from, though this option is only manageable if there is a limited quantity of symbols to display and obviously there will be no preview. For textures you are better off making use of the texture tab in the OIP. See the recent post by Jesse in answer to a question from me. It includes a sample PIO with texturing ability.

 

A2. Yes, but it can get complex if the PIO uses custom dialogs and you need to individually control which parameters are by style and which are not.

Link to comment

@michaelk I've attached an example that should be able to answer most of your event-enabled questions (and probably raise some new ones) as well as provide an example of symbol and texture pickers.  Unfortunately, they are quite complicated, but you can copy and paste my code to get it set up.  The procedure you are looking for is the PopulateResourceArray procedure, which allows you to pass in a resource type and will return the number of parents (IE Resource Manager Folders) and resources, which can then populate the Thumbnail Popup.  My method allows for sorting by folder, so it's easier to stay on top of drawings with a lot of symbols or textures.

 

The PIO itself is fairly straightforward, it takes the selected Symbol and separates out the 2D and 3D components.  The 2D components get their fill set by the Color Index parameter, and the 3D elements get their overall texture set to the selected Texture.  Double-clicking the object will advance the color index by 1.

 

image.png.6bd3c7211b0865f8689537f05a81a63a.png


image.png.25f20ecb4d645ac384cc76c0fa1cfed7.png

 

I know the preview for the texture selection is muddy and backward, but it is the best I've been able to figure out with the CreateImageControl procedure.  There is a CreateImageControl2 added in 2012, but I've never been able to figure out how to get a texture into it.

 

As for PIOs and Object Styles, I haven't gone through with adapting my plug-ins to using them (I overhauled all of my plug-ins during the 2020 quarantine JUST before VW2021 came out, and I haven't had enough time to incorporate styles since), but @Julian_Carr and @_c_ included a ton of good information in this thread:

 

Event Enabled Example.vso

Link to comment
  • 5 months later...

Trying to filter the resource browser but I am having trouble.  

 

result:=vsoButtonGetResource('SymbolName', kSymbol, 13, '')

Doesn't filter anything. 

 

but:

result:=vsoButtonGetResource('SymbolName', kSymbol, 13, 'Defaults:Railing Fence:Pickets')

is filtering everthing but open drawings and favorites.

 

How can I get this to filter everthing but symbols in the current drawing and symbols in my Workgroup Folder at 'Defaults:Railing Fence:Pickets'?

Link to comment

To filter to just symbols in the current drawing, you would treat it like a Resource List, using:

vsoButtonGetResource('SymbolName',kSymbol,0,'');

 

This will prevent external libraries from populating in the left-hand pane of the Resource Browser.  In your example above, constant 13 will populate all external libraries in the left-hand pane, but will still default to the current drawing in the main pane.  As for filtering out the open drawing, I don't know if you can.  The syntax for Resource Lists allows for filtering using a negative folder ID (such as -13 in your case), but that doesn't seem to work with the vsoButtonGetResource function and the documentation is dreadfully sparse.  There is also no folder ID listed in the documentation for Workgroup Folders, so there might not be a way to filter to them.

 

That being said, you could build a Resource List which does filter out the current drawing resources and create your own dialog box similar to the one from my example above rather than using the default VW Resource Browser one.  Certainly a lot more code, but may be the only way get the filtering to work for you.

Edited by Jesse Cogswell
Link to comment

 

On 7/3/2023 at 1:32 PM, Jesse Cogswell said:

To filter to just symbols in the current drawing, you would treat it like a Resource List, using:

vsoButtonGetResource('SymbolName',kSymbol,0,'');

 

Jesse:

Thanks, I do want to see the current drawing as well as the symbols at 'Defaults:Railing Fence:Pickets'.  I am only trying to filter out the rest. 

 

I am able to build the resource list.  Would there be another way to just pick a symbol from the resource list?

 

Currently in my scripts OIP I am just typing in the name of the symbol I would like to use.   I'm trying to add a symbol picker. 

Link to comment

@The Hamma To be perfectly honest, I am not a fan of Resource Pop-up for a whole multitude of reasons (can't resize the window except from the right, so if your OIP is on the right as well as in the default workspace, you're kind of screwed; you can't add additional filters such as filtering for symbols containing attached records; and if you have a lot resources, it can be incredibly slow), so I don't use it in my own plug-ins.  I much prefer to roll my own, and you'll find an example in the attached example plug-in in my first post on this topic.  Feel free to copy the PopulateResourceArray procedure (builds arrays of Resource Manager folders and resources based on given type, you would just need to edit the initial BuildResourceList code at the top of the procedure to filter what you want), and the DrawDialog function and SymbolDialogHandler procedure to deal with the dialog.

 

Another, much more simple way to handle it would be to have your Symbol field be a pop-up parameter and to populate that pop-up during the kObjOnWidgetPrep event.

 

Actually, I added that exact functionality to the plug-in back in June.  I've attached newest iteration of the example plug-in.  You'll want to look at the kObjOnWidgetPrep event.  Not as elegant as a symbol picker, but far simpler to code.

Event Enabled Example.vso

  • Like 1
Link to comment
1 hour ago, Jesse Cogswell said:

Actually, I added that exact functionality to the plug-in back in June.  I've attached newest iteration of the example plug-in.  You'll want to look at the kObjOnWidgetPrep event.  Not as elegant as a symbol picker, but far simpler to code.

 

When I edit line 106

		resList:=BuildResourceList(nResType,13,'Defaults:Railing Fence:Pickets',numItems);
		AlrtDialog(concat(numItems));

 

The numItems = 43 but only one symbol shows up in the picker. 

Not sure what you are doing with the parents but is it restricting the view to only the root of the current drawing?

 

Also get this error almost everytime I edit the script. I have to restart Vectorworks everytime I get the error. 

image.png.bac68d78e877ae35d39af4e0ea5c7d11.png

 

Edited by The Hamma
Link to comment

I think you are getting some of those errors because it is a Plug-in Object not a script.  If you don't have the parameters (they look like variable names but start with a P) defined, then the data will be missing.

 

If you define the parameters make sure you name them exactly like they are in the script, but leave off the initial P.

 

And if I am wrong and this is something you have already checked, then. 🤷‍♂️

Link to comment
8 minutes ago, Pat Stanford said:

Plug-in Object not a script

Sorry, yes it is a Plug-in Object and the parameters are defined.   It's very odd.  Never had that happen before I was working with the three samples attached to this thread.  

Edited by The Hamma
Link to comment
10 minutes ago, Pat Stanford said:

At least in my version of VW2023, there is not folder 'Defaults:Railing Fence:Pickets'. 

 

I added the "Pickets" folder to my library.   I have a resource library file that needs to be added to that directory for my script to pull symbols from. 

 

For experimental purposes I changed it to 'Defaults:Railing Fence' and it worked.  Strange!

Link to comment

@The Hamma After doing some testing, I figured it out.  The issue is that I was using InsertImagePopupObjectItem to populate the thumbnail, which populates using named objects.  Unfortunately, the external resources aren't named objects within the drawing, so while the resource list is feeding the names in properly, the thumbnail popup doesn't know what to do with it.

 

But don't despair, you can use InsertImagePopupResource instead!  What you would need to do is use the script as originally written in my example to build the list for symbols in the drawing, then build a new resource list from within the dialog handler with the external library stuff (use a negative folder number to restrict to just get the external library since the document symbols are already handled), and feed that into InsertImagePopupResource.  It won't be sorted by anything, but it will get the symbols at least.  I can't seem to find a way to pull a resource's source file, but if there's a way to do so, you could theoretically add dividers by source file to the thumbnail popup.

 

The dialog handler in my testing looked like this, you should be able to change the BuildResList code to suit your needs:

{-----------------------DIALOG HANDLING---------------------------------------}
PROCEDURE SymbolDialogHandler(VAR item,data:LONGINT);

{Handles Select Symbol dialog box}

	VAR
	
		i,j,int,totalParents,totalResources:INTEGER;
		str:STRING;
		resList,numItems:LONGINT;

	BEGIN
		CASE item OF
			SetupDialogC:
				BEGIN
					PopulateResourceArray(kSymbol,totalParents,totalResources);
					
					IF(totalResources>0) THEN
						BEGIN
							FOR i:=1 TO totalParents DO
								BEGIN
									int:=InsertImagePopupSeparator(dialog,31,parentArr[i]);
									FOR j:=1 TO totalResources DO
										BEGIN
											str:=resourceArr[i,j];
											IF((str<>'') & (GetObject(str) <> NIL)) THEN int:=InsertImagePopupObjectItem(dialog,31,str);
										END;
								END;
							i:=1;

{-----------------------NEW CODE------------------------------------------------------------------------------------}							
							int:=InsertImagePopupSeparator(dialog,31,'External');
							
							resList:=BuildResourceList(16,-116,'',numItems);
							FOR i:=1 TO numItems DO int:=InsertImagePopupResource(dialog,31,resList,i);
{-----------------------END NEW CODE--------------------------------------------------------------------------------}							
							
							WHILE(int<>kSymbol) DO
								BEGIN
									int:=GetTypeN(GetObject(GetImagePopupObject(dialog,31,i)));
									i:=i+1;
								END;
							IF(symbolName='') THEN
								BEGIN
									SetImagePopupSelectedItem(dialog,31,i-1);
									symbolName:=GetImagePopupObject(dialog,31,i-1);
									UpdateSymbolDisplayControl(dialog,21,symbolName,11,9);
								END
							ELSE
								BEGIN
									int:=GetImagePopupObjectItemIndex(dialog,31,symbolName);
									SetImagePopupSelectedItem(dialog,31,int);
									UpdateSymbolDisplayControl(dialog,21,symbolName,11,9);
								END;
						END;
				END;
			1: {OK}
				BEGIN
					int:=GetImagePopupSelectedItem(dialog,31);
					
					symbolName:=GetImagePopupObject(dialog,31,int);
					SetRField(objHd,GetName(recHd),'symbolName',symbolName);
					
					ResetObject(objHd);
				END;
			2: {Cancel}
				BEGIN
				END;
			31: {Thumbnail Popup}
				BEGIN
					int:=GetImagePopupSelectedItem(dialog,31);
					UpdateSymbolDisplayControl(dialog,21,GetImagePopupObject(dialog,31,int),11,9);
				END;
		END;
	END;

 

  • Like 1
Link to comment
  • 3 months later...

@FranAJA Unfortunately, my Python is more than a little rusty.  I learned Python back in 2010 and wrote some pretty handy little programs in it, but haven't touched it since.  I learned Vectorscript a year later in 2011 and rather enjoy the strictness and structure of it.  Since they added Python in as an option in 2014, relearning Python has been on My List of Things to Do™, but that list is very long and only gets longer by the day.  I find that the Python implementation in VW is a little sloppy, as it forces Python to behave like Pascal and thereby negates a lot of the benefits of Python.  I really haven't been able to wrap my head around variable handling and tuples and the level of documentation and examples is slim (it took me ages to figure out how to make GetCustomObjectInfo to work in Python, and I still don't fully understand it).  My current practice is to do as much in Vectorscript as possible, then use PythonBeginContext, PythonEndContext, and PythonExecute to use Python's extensive libraries for things that aren't covered by Vectorscript.

 

That all being said, I can help as much as I am able.  One nice thing about the VW Python implementation is that all of the functions are basically the same, just with a vs. prefix added to them and returns being handled with tuples instead of constructor arguments, so the biggest hurdle when translating my example is just reworking a bit of the syntax.  The example I have linked above is designed to demonstrate three different, and all fairly complicated, concepts: Event-Enabled plug-ins, dialog handling, and building resource and parent arrays for dialogs.  What are you trying to implement into your PIO?  If you're looking to implement both things, my recommendation is to work on one thing at a time.  Start with getting an Event-Enabled plug-in working.  Something simple like a point object that uses CreateText to put a string parameter on the drawing, and a button in the OIP that launches StrDialog to change that string parameter.  You should be able to follow a similar structure to what I have in the Vectorscript example starting with the vsoGetEventInfo function, substituting an if/elif structure for the CASE statement.  Each line in the driver of my example is commented to explain exactly what the code is doing, so it should be pretty simple to translate it into Python.

 

Dialog handling in Vectorworks is a whole other thing, and something you can practice in a document script outside of a PIO.  Generally, VW requires two different functions for each dialog, a builder and a handler.  The builder (DrawDialog in my example), creates and arranges all of the elements that make up the dialog.  I always approach this in the same way:

  1. Create all elements starting with static text objects, then moving on to interactive (text fields, buttons, checkboxes, etc), then to groups.  What's important to note is that VW will use the element ID order to determine the order when using the Tab key to navigate the dialog, so I try to make sure that I number and create things in the order that I imagine the user will want to interact with them (usually top to bottom).  The other important thing to note is that the OK button will always be element ID 1, and the Cancel button will always be element ID 2, so it's best to start numbering your elements at 11.  I usually make my groups start at element ID 101, but didn't in the above example for some reason.
  2. Set group items.  This uses SetFirstGroupItem to set the first element, then SetBelowItem or SetRightItem to position elements from there.  I generally populate one row at a time, so using SetRightItem to position elements for the row, then SetBelowItem with the first element from the last row as the first argument to start setting the next row.
  3. Set layout items.  I usually try to group a lot of elements, so for me this is mostly setting my groups into the dialog.  Same format as setting group items except you'll use SetFirstLayoutItem to set the first element.
  4. Align items.  This uses AlignItemEdge to line things up to make them look nice.  I use this to make text boxes line up with pop-up menus and make group boxes all line up.  If you get clever with your element numbering, you can use a FOR statement to do a whole bunch of elements at the same time.  One thing to note is that this doesn't really work with Static Text elements, so it's best to make all of your static text the same length by passing in the length of the longest text string as the widthInCharacters argument for all the static text.
  5. Add help strings.  Using SetHelpText, add help text for each element that needs it.  I do this in all of my plug-ins outside of very simple and self-explanatory dialogs, or when I'm feeling lazy and the plug-in is strictly for a forum example.

Once you've created your dialog, you'll need a handler callback function to deal with it so that you can use RunLayoutDialog.  This will use an if/elif structure in your case to handle interactions with any dialog elements.  The RunLayoutDialog page of the online function reference has a decent Python example of how all of this works, but it's missing some things in the handler that are handy to know:

  • If you need to populate or preset any dialog elements, you will need a SetupDialogC item and this will likely want to be the first thing in your if/elif structure.  I'm unclear if vs.SetupDialogC works on its own or if you will need to define a constant as kSetupDialogC = 12255 as shown in this thread.
  • As in the function reference example, item == 1 is what happens when you press the OK button.  This should pull values from the dialog and update global variables or change drawing elements as needed.
  • item == 2 is what happens when you press the Cancel button.  I'll always put this in the code, but often leave it blank.  If my dialog updates global variables and executes things in the driver, I will usually put in a global boolean check that the Cancel button sets to FALSE.
  • item == X, where X equals the dialog element ID that you defined in the builder.  This is where you can set buttons in the dialog to populate elements within the dialog.  In my example, I have code that will update the Symbol Display Control when you interact with the Thumbnail Popup.  In Python, this would read as elif item == 31:

Again, I would practice building a dialog in a document script and get the general concepts and structure down.

 

Now, building arrays of resources and parents for populating the thumbnail popups will be the toughest thing to translate from Vectorscript to Python.  The way Vectorscript handles arrays is very rigid and restrictive, so my PopulateResourceArray procedure has to do some pretty dodgy things to build my resource array.  It's a 2D array, with the X being the parent (folder name in my example) and the Y being the resource name (symbol or texture name).  So it's constantly resizing the Y size of the array if the number of resources in a parent would exceed the bounds of the array. Python is far better than Pascal with dealing with data in this way.  There's probably a clever way to use the Python Dictionary structure that can make this whole process much more simple, but I would need to noodle around with Python a bit before I can really help you with this process.

 

My schedule is more open next week, so if I find my self with some time, I might try to adapt the example to Python, but I can't really make any promises.  Again, any interactions between the code and Vectorworks will largely be the same between Vectorscript and Python, so a lot of adapting my example code is just translating the return syntax to fit Python.  The biggest things to know in terms of structural differences between Python and Vectorscript is that all variables and constants in VS must be declared before they are used and be declared in a specific "block".  This is obviously not the case in Python.  More information about the "block" structure of Vectorscript can be found in this thread:

This might help in navigating the overall structure of my example so that you can translate the structure to Python.

  • Like 1
Link to comment

Hi Jesse, thank you very much for your explanation. It was very helpful, in all the details.
I think I made a good progress just on testing this bit (in the following explaination).
I would like to put anyway the python script for people who will like to use this bit.

The process I chosen it slighty different but I am stuck at one point, but first it is better that I explain what i have done until now:

Introduction:
The script is an external script written by IDE (Pycharm). So it is called in vectorworks in the usual way
 

import nameofthescript
nameofthescript.execute() # def execute() inside the .py file 'nameofthescript'



1) I have created a Event Based object with a button (thanks to the amazing tutorial by _c_):

 

import vs
# Import Dialog
import _dlg_pick_symbol

Spot2DRadius = 30

kObjOnInitXProperties = 5           # extended properties, runs BEFORE kParametricRecalculate
kObjOnWidgetPrep = 41               # after clicking on an obj, for building its OIP, it runs AFTER kParametricRecalculate
kObjOnObjectUIButtonHit = 35        # event for button
kObjXPropHasUIOverride = 8          # allows PIo to override UI
kParametricRecalculate = 3          # the plug-in regenerates, here you'll put the code for geometries
kObjectEventHandled = -8


kWidgetButton = 12

# ButtonParameter
ButtonParameter = 1000

# runs on button click

# Call Dialog
def test_pick_symbol_dialog():
    #vs.AlrtDialog('Push Button Event Works')
    dlg_pick_symbol = _dlg_pick_symbol.CreateDialog()
    vs.RunLayoutDialog(dlg_pick_symbol, _dlg_pick_symbol.DialogHandler)

def create_2d_symbol():
    vs.ArcByCenter(0, 0, Spot2DRadius, 0, 360)

def execute():
    # Handling PIO
    global PIOName, PIOHandle, PIORecordHandle, PIOWallHandle
    empty = 0

    (ok, PIOName, PIOHandle, PIORecordHandle, PIOWallHandle) = vs.GetCustomObjectInfo()
    (theEvent, theButton) = vs.vsoGetEventInfo()

    # Setting Push Button
    if theEvent == kObjOnInitXProperties:
        # User has single-clicked the object's icon.
        # Set kObjXPropPreference to TRUE to handle preferences within the object.
        ok = vs.SetObjPropVS(kObjXPropHasUIOverride, True)
        ok = vs.SetObjPropVS(kWidgetButton, True)
        ok = vs.vsoInsertAllParams()
        ok = vs.vsoAppendWidget(kWidgetButton, ButtonParameter, 'Test Button', empty)

    elif theEvent == kParametricRecalculate:
        create_2d_symbol()

    elif theEvent == kObjOnWidgetPrep:
        vs.vsoSetEventResult(kObjectEventHandled)

    elif theEvent == kObjOnObjectUIButtonHit:
        if theButton == ButtonParameter:
            test_pick_symbol_dialog()



2) The event "..ButtonHIt" call the definition of the dialog.

3) I created a very simple dialog with DialogBuilder (Just a label and an image popup):

 

Capture.JPG.e0bb81f92cfbf960eabfc790088fd788.JPG

 

4) I generated the py, embedding the string into the dialog.

5) I called the dialog into my main python script (before open the dialog and uncomment the def DialogHandler and the dlg_nameofdialog variable. 
I did not uncommented the last one because i am running it on my script.

 

# Uncomment this code if you want to display the dialog

def DialogHandler(item, data):
	pass

dlg_pick_symbol = CreateDialog()
#vs.RunLayoutDialog( dlg_pick_symbol, DialogHandler )

 

 

6) the result is nice :
 

Capture2.thumb.JPG.d8bf145208ec618d5348ce3d1b4b3fb8.JPG

 

However the pick Symbol is completely cblank, i am trying to figuring out how to include the actual symbols of the resoruce manager into the popup but it is a bit complicate (which is the last part of your post). 
Any idea ?
 

Edited by FranAJA
Link to comment

One other limitation with Python in VW (and maybe other places) is that it does not handle waiting for user input (specifically mouse clicks) very well. So if you are writing scripts that need to be interactive with objects in the drawing or need to be able to place objects in the drawing, these take extra code to handle than using Vectorscript that will basically just pause until the required input is received.

  • Like 1
Link to comment

Checking on the forum i have to build the Dialog Handler since the only thing the dialog builder in VW does is this one:
 

def DialogHandler(item, data):
	pass

 

...which does basically nothing.

I found a very nice topic in here link

However, i am still learning these kconstant which are a pain. There are millions, and it is not pretty clear how to use them. 
I hope someone with a good heart will write a guide of python in VW. 

 

Even if i am getting quite appassionate about studying vectorworks stuff in python, it is too way complicate even for easy stuff, it is not really a good way to debug and check step for step, or see what thing causes thing immediately (except for vectorscript debug)... 

Edited by FranAJA
Link to comment

I have studied some topics in the forum, so I wrote the remaining part of code:

1) Probably is better having the CreateDialog and the DialogHandler definition in the same script so the definition can communicate better with the rest. The dialog Builder is awesome to give the source code for the dialog without building by myself. 

 

2) The constant of the ImagePopup has been set to 6 (initially was 5). Probably there was a conflict which the kObjOnInitXProperties = 5 which deal with the PIO button. After a VW restart the button was disappear, so i changed it to 6 and reappeared again. 

 

3) I have just to understand better how to parse properly the folders for the BuildingResources as is getting also what i do not want.

 

import vs

# Parameter for geometry 2D
Spot2DRadius = 30

# Extended properties
kObjOnInitXProperties = 5  # extended properties, runs BEFORE kParametricRecalculate
kObjOnWidgetPrep = 41  # after clicking on an obj, for building its OIP, it runs AFTER kParametricRecalculate
kObjOnObjectUIButtonHit = 35  # event for button
kObjXPropHasUIOverride = 8  # allows PIo to override UI
kParametricRecalculate = 3  # the plug-in regenerates
kObjectEventHandled = -8

# Widget
kWidgetButton = 12

# ButtonParameter PIO (decided by user, big number to do not have conflicts)
ButtonParameter = 1000

# Dialog Constant
SetupDialogC = 12255                # A predefined constant value that is passed to the dialog event handler subroutine
                                    # when a modern custom dialog is initially displayed onscreen.
SetdownDialogC = 12256              # This constant is passed to the event handler routine to signal dialog setdown.
ResizeDialogC = 12611               # This constant is passed to the event handler routine to signal the dialog has been resized.
DisplayDialogHelpC = 12916          # This constant is passed to the event handler routine to signal the dialog
                                    # that it should display its contextual help using the help string given by the Contextual Help Manager menu.
DialogTimerEventMessageC = 13028    # This constant represents the message that is sent periodically to a dialog
                                    # handler after it has been registered to receive timer events.

# control IDs # Dialog
kOK                   = 1
kCancel               = 2
kLabelPick            = 4
kImagePopup           = 6


def CreateDialog():
    global dialog           #define the variable global to be called in other definition.


    # Alignment constants
    kRight                = 1
    kBottom               = 2
    kLeft                 = 3
    kColumn               = 4
    kResize               = 0
    kShift                = 1

    def GetPluginString(ndx):
        # Static Text
        if ndx == 1001:			return 'OK'
        elif ndx == 1002:		return 'Cancel'
        elif ndx == 1003:		return 'Pick Symbol'
        elif ndx == 1004:		return 'Pick a Symbol'
        elif ndx == 1006:		return ''
        # Help Text
        elif ndx == 2001:		return 'Accepts the dialog data.'
        elif ndx == 2002:		return 'Cancels the dialog data.'
        elif ndx == 2004:		return 'Help text.'
        elif ndx == 2006:		return 'Help text.'
        return ''

    def GetStr(ndx):
        result = GetPluginString( ndx + 1000 )
        return result

    def GetHelpStr(ndx):
        result = GetPluginString( ndx + 2000 )
        return result

    dialog = vs.CreateLayout( GetStr(3), True, GetStr(kOK), GetStr(kCancel) )

    # create controls
    vs.CreateStaticText( dialog, kLabelPick, GetStr(kLabelPick), -1 )
    vs.CreateThumbnailPopup(dialog, kImagePopup)

    # set relations
    vs.SetFirstLayoutItem( dialog, kLabelPick )
    vs.SetBelowItem(dialog, kLabelPick, kImagePopup, 0, 0)

    # set alignments

    # set help strings
    cnt = 1
    while ( cnt <= 6 ):
        vs.SetHelpText( dialog, cnt, GetHelpStr(cnt) )
        cnt += 1

    return dialog

def DialogHandler(item, data):
    if item == SetupDialogC:                    #Dialog Called
        #vs.AlrtDialog("Dialog Opened")

        # Build Resources constants
        ObjectType = 16                     # Symbol Definition /VS:Function_Reference_Appendix_D
        FolderIndex = 92                    # BuildResourceList Def for Symbol Folder See Func. Ref
        SubFolderName = 'SymbolTestFolder'  # Nul subfolder get all folders and subfolders

        # Return the list of Symbol to populate the ImagePopup
        SymbolList, NumItems = vs.BuildResourceList(ObjectType, FolderIndex, SubFolderName)  # return tuple (int,int)

        # Loop to populate the image popup
        for i in range(NumItems + 1):
            name = vs.GetNameFromResourceList(SymbolList, i)
            vs.InsertImagePopupResource(dialog, kImagePopup, SymbolList, i)

        pass


# Call Dialog
def test_pick_symbol_dialog():

    # vs.AlrtDialog('Push Button Event Works')
    dialog = CreateDialog()
    vs.RunLayoutDialog(dialog, DialogHandler)


def create_2d_symbol():
    vs.ArcByCenter(0, 0, Spot2DRadius, 0, 360)


def execute():
    # Handling PIO
    global PIOName, PIOHandle, PIORecordHandle, PIOWallHandle
    empty = 0

    (ok, PIOName, PIOHandle, PIORecordHandle, PIOWallHandle) = vs.GetCustomObjectInfo()
    (theEvent, theButton) = vs.vsoGetEventInfo()

    # Setting Push Button
    if theEvent == kObjOnInitXProperties:
        # User has single-clicked the object's icon.
        # Set kObjXPropPreference to TRUE to handle preferences within the object.
        ok = vs.SetObjPropVS(kObjXPropHasUIOverride, True)
        ok = vs.SetObjPropVS(kWidgetButton, True)
        ok = vs.vsoInsertAllParams()
        ok = vs.vsoAppendWidget(kWidgetButton, ButtonParameter, 'Test Button', empty)

    elif theEvent == kParametricRecalculate:
        create_2d_symbol()

    elif theEvent == kObjOnWidgetPrep:
        vs.vsoSetEventResult(kObjectEventHandled)

    elif theEvent == kObjOnObjectUIButtonHit:
        if theButton == ButtonParameter:
            test_pick_symbol_dialog()

 

 

The result: 

 

Untitled-1.thumb.jpg.bcd046e90d283700d2a128db46d7fc55.jpg

Edited by FranAJA
  • Love 1
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...