Popular Post _c_ Posted March 27, 2021 Popular Post Share Posted March 27, 2021 (edited) There is a question on the German VW forum about plug-ins with dividers and buttons. An ever recurring topic. I am [ever] switching to Python, and I though it could be a nice exercise for me to try it pythonically. Note: this article has been transferred to the Developer wiki for easier maintenance, it is now a subpage in my User space: https://developer.vectorworks.net/index.php/User:CBM-c-/Plug-in_with_widget_basic_example Expand the test file into your User's plug-in folder (there is no installer here) Test.zip The Test PIO _c_ plug-in: uses an external file source (you don't need to script in the Plug-in Editor) is event enabled has a button triggering a script has dividers turns the dividers into expandable group widgets doesn't resolve text alignments, so that will take the active document's settings I am new to Python and am sure that this can be done more efficiently, I'll throw it thus here in the forum, let's learn. Edited January 2, 2022 by _c_ 5 1 Quote Link to comment
_c_ Posted March 29, 2021 Author Share Posted March 29, 2021 About text alignments: you can set a plug-in object to respond to font and text size using vs.SetObjectVariableBoolean(gPio_H, 800, True) but all other text properties, such as horizontal and vertical alignment, etc. must be coded and driven by parameters. Quote Link to comment
_c_ Posted March 29, 2021 Author Share Posted March 29, 2021 Explanation: The plug-in needs to be event enabled: you do this in the Options tab of the Plug-in editor: If you work on Python with external files, the plug-in needs to reload the code, so you must turn off caching during development: Here I break down the events employed. There are bucketloads of events, you'll find them in the SDK: MiniCadHookIntf.h and it does take a lot of time to be comfortable with their usage. Some of them I have really no idea what they do, and believe me, I did spend an inordinate about of time on them. The two major files you might want to study are these, but there is far more (the SDK version is here just irrelevant): The code for the plug-in runs a number of times (and double as much if the developer mode is on), vs.GetCustomObjectInfo is compulsory for fetching the needed basic variables: (ok, gPio_N, gPio_H, gPioRec_H, gWall_H) = vs.GetCustomObjectInfo() Every time the code runs, you must fetch the type of event involved and eventually do something during that event. vs.vsoGetEventInfo is compulsory for fetching event info: (theEvent, theButton) = vs.vsoGetEventInfo() # whereby theButton is a generic message (theEvent, aMessage) = vs.vsoGetEventInfo() 2 Quote Link to comment
Popular Post _c_ Posted March 29, 2021 Author Popular Post Share Posted March 29, 2021 (edited) Init properties: During the init event you set up the Object Info Palette behaviour and other things: if theEvent == kObjOnInitXProperties: If you want to use buttons and/or Custom pull-down menus you need to turn on UIoverride: ok = vs.SetObjPropVS( kObjXPropHasUIOverride, True ) IF, and only IF, you also want to use custom pull-down menus loading custom values, you will also need to enable custom widget visibilities. If you do this, you cannot use vs.SetParameterVisibility or vs.EnableParameter, which use parameter names, you can only use vs.vsoWidgetSetVisible and vs.vsoWidgetSetEnable. These need parameter indexes, so you must keep track of the parameter indexes and store them somehow as file. This does add complexity (I have a sub auto-filling a list as text into the right place): # not used in the test example: vs.SetObjPropVS(kObjXHasCustWidgetVisibilities, True); # only needed for custom pull-down menus with special lists of values # after enabling this prop you need to set visibilities during event kObjOnWidgetPrep To have the lovely widget groups, you must enable them ok = vs.SetObjPropCharVS( kWidgetGroupMode, vs.Chr(kWidgetGroupAutomatic), True ) # add widget groups Add parameters as static text turn the static text into separators. Mind that the routine vs.vsoInsertWidget takes a string and places it in the Object Info Palette. You can use the localised parameter name. Since the function (boo, locParmName) = vs.GetLocalizedPluginParameter(pioRecName, univParmName) returns two vars, it cannot be used directly, so I created one simple sub named O_GetLocParmName that does that: return only a string. ok = vs.vsoInsertWidget( cP___div0 -1, kWidgetSeparator, cP___div0, 'parameter name', empty); # it is advisable to use the localized name ok = vs.vsoInsertWidget( cP___div0 -1, kWidgetSeparator, cP___div0, O_GetLocParmName(gPio_N, '__div0'), empty); # O_GetLocParmName is a subroutine that fetches only the string, dropping the boolean, # so I can use it directly in vs.vsoInsertWidget def O_GetLocParmName(pioRecName, univParmName): (boo, locParmName) = vs.GetLocalizedPluginParameter(pioRecName, univParmName) return locParmName add indenting levels. These turn the widgets into expandable widgets. Don't omit to set the 0-levels, or things are going to mess up: titles = [cP___div0, cP___div1, cP___div2] for i in range(vs.NumFields(gPioRec_H) +1): if (i in titles): vs.vsoWidgetSetIndLvl(i, 0) else: vs.vsoWidgetSetIndLvl(i, 1) Warning: you will need to close and re-open your document to see widget groups display properly EVERY time you change something in the parameter index list (add, delete parameters) Edited March 29, 2021 by _c_ 5 Quote Link to comment
MullinRJ Posted March 29, 2021 Share Posted March 29, 2021 I especially like your last tip. Raymond 2 Quote Link to comment
Gregi Posted May 2, 2021 Share Posted May 2, 2021 I'm really thankfull to this post! I'm doing a lot of try and error, but it works pretty fine! 🙂 On 3/29/2021 at 6:56 AM, _c_ said: Warning: you will need to close and re-open your document to see widget groups display properly EVERY time you change something in the parameter index list (add, delete parameters) I guess, a simple open and close the Editing-Window in the PlugIn Manager is working as well.. 2 Quote Link to comment
twk Posted July 26, 2021 Share Posted July 26, 2021 (edited) Nice share @_c_! Finally got my group widgets working after months of trial and error. My widget indent calls were in the kObjOnWidgetPrep function not the kObjOnInitXProperties. (Funny that indentation works in kObjOnWidgetPrep without the Grouping) Again, thank you and thank you. Edited July 26, 2021 by twk 1 Quote Link to comment
Alexander Zemtsov Posted February 10, 2022 Share Posted February 10, 2022 Hallo _c_! Thank you very much for this example, it is helpful. I have only one problem according the code: there are 51, 52, 53 lines: def main(): gDX = vs.Pwidth gDY = vs.Pdepth gDZ = vs.Pheigth I cannot find this methods in vs. namespace ... what is it ?? 2 Quote Link to comment
MullinRJ Posted February 10, 2022 Share Posted February 10, 2022 @Alexander Zemtsov, 4 hours ago, Alexander Zemtsov said: def main(): gDX = vs.Pwidth gDY = vs.Pdepth gDZ = vs.Pheigth Pwidth, Pdepth, and Pheight are programmer defined parameters in the Plug-in object. The are displayed in the OIP at runtime (without the leading "P") and you use them to change the shape of the Plug-in object on the drawing. You can see all of the plug-in's "P" parameters by using the Plug-In Editor. In the code, they are effectively constants that are loaded before the code runs. HTH, Raymond 3 Quote Link to comment
Alexander Zemtsov Posted February 11, 2022 Share Posted February 11, 2022 Ah stimmt! Thanks a lot, got it Quote Link to comment
Recommended Posts
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.