Pat Stanford Posted February 17, 2021 Share Posted February 17, 2021 I need a high level overview of that it takes to make a PIO Styled. Does it have to be event enabled? Do I need to set a specific Object Parameter? Does VW handle the application of the styled parameters? Or do I have to write that code? Any other pointers? Thanks. Quote Link to comment
Julian Carr Posted February 17, 2021 Share Posted February 17, 2021 Don't have much time but... A1. Yes must be event enabled. A2. You will need this:gFlag := SetObjPropVS(kObjXSupportsStyles, TRUE); { 49 } { Controls whether a parametric type support plug-in styles } and maybe these: gFlag := SetObjPropVS(kObjXPropHideStyleSettingsButton, TRUE ); { 69 } { hide unwanted style editing buttons } gFlag := SetObjPropTxtVS(kObjXPropSupportResourcePopup, 'Object Styles/MyStyledObject'); { 53 } { specified the default content folder } A3. Depends if you are using dialogs to access parameters. If you you have a lot more work to do. If not, then you can let Vw handle it from memory. A4. There are other events you may need too: 60: BEGIN { Edit Plug-in Style } vsoSetEventResult( -10 ); {kObjectEventHandled} { using -10 here causes the object properties dialogue to open next } END; 61: BEGIN { Create Plugin Style } vsoSetEventResult( 0 ); {kObjectEventHandled} END; 62: BEGIN { Update Styled Plugin Object } vsoSetEventResult( 0 ); END; 63: BEGIN { Finalize Create Style } vsoGetPluginStyleSym(gh1); SetAllStyleParams(gh1, 0); { this sets all parameters to not use the style } vsoSetEventResult( 0 ); END; 64: BEGIN { Finalize Update Styled Object } vsoSetEventResult( -8 ); END; 65: BEGIN { Style Widget Chosen } vsoSetEventResult( 0 ); END; { Create Style order of events: 61, 63, 60, 62, 64 } { Edit Style order of events: 60, 62, 64 } 2 Quote Link to comment
Pat Stanford Posted February 17, 2021 Author Share Posted February 17, 2021 Thank you Julian. That should get me started. I guess it is about time for me to relearn event enabled scripts. Quote Link to comment
Vectorworks, Inc Employee klinzey Posted February 18, 2021 Vectorworks, Inc Employee Share Posted February 18, 2021 @Pat Stanford This is the document we put together about adding styles to objects when styles were first implemented. Plugin styles.docx 1 Quote Link to comment
Pat Stanford Posted February 18, 2021 Author Share Posted February 18, 2021 Thank you Kevin. This is extremely helpful. I will have to review carefully this weekend. Could this be posted to the Dev wiki? Quote Link to comment
C. Andrew Dunning Posted February 22, 2021 Share Posted February 22, 2021 On 2/16/2021 at 8:23 PM, Julian Carr said: A3. Depends if you are using dialogs to access parameters. If you you have a lot more work to do. If not, then you can let Vw handle it from memory. Julian - IF/WHEN you have a few minutes, would you mind sharing any insight along these lines? I've got Styles working beautifully for one of my PIOs - all except for parameters set by any of 3 dialogs. I can get the handle to the PIO instance stored as part of the Style Symbol but am having a bear of a time doing much of anything beyond that. For example, "dialog" settings changed while editing Styled don't seem to be sticking. Thanks for sharing any wisdom... Quote Link to comment
Julian Carr Posted February 24, 2021 Share Posted February 24, 2021 I'm not sure I can be of much assistance here Andy. Because my dialogs are usually jamb packed full of controls, it has always been a bridge too far to fit those by style/instance widgets in. For example: This dialog just fits on a 13" screen. For this PIO I do still use styles though, but only as a way to transfer hundreds of different styles from the library into the tool. Once placed, the instance is no longer styled and that works in this case because there are very few repetitions of any particular setup in the drawing, so not much benefit from being able to pick if controls are by style or instance . When you use a style with this object, it comes into the drawing as being unstyled. But if you have managed to get all the widgets into your dialog then I wouldn't have expected things to be too difficult. Maybe someone else has some clues? Quote Link to comment
C. Andrew Dunning Posted February 24, 2021 Share Posted February 24, 2021 9 hours ago, Julian Carr said: Because my dialogs are usually jamb packed full of controls, it has always been a bridge too far to fit those by style/instance widgets in. I'd actually be happy with an approach far simpler than giving individual Style functionality to every parameter in a given dialog. For the time-being, I'd be quite content with applying Styles to settings en-masse for the dialog's settings. For example, a dialog that controls embedded Class settings for a PIO's sub-parts. I'm able to create a Styles List Control that toggles by-style and by-instance. I'm also able to get Style settings to apply - but only as their state when the Style was created. Settings that are changed when editing the Style do not pass in or out of the editing environment. Make sense??? Quote Link to comment
Gregi Posted July 8, 2022 Share Posted July 8, 2022 hello everybody this is really helpful. I'm trying to create my own styled PIO. It works kind of good, but there's one thing i still don't get: I would like to "implement" an Object in the style, like the profile of my 2D-Profile-Object. Is there a Way to "easy" Add a Buton on the "kEditPluginStyleDefault" thing? I tried "AddToPluginStyle" and/or "AddToPIOStyleEdit" with no succes - but i don't know in which part of Event-Trigger i would have to pack anything i couldn't get any information about how drawn objects can be a part of a style, maybe @_c_ does have any idea because of the great things from vectorlab? 🙂 Quote Link to comment
_c_ Posted July 9, 2022 Share Posted July 9, 2022 (edited) Ciao @Gregi, You can do your own dialog for the Plug-in style, this is fairly easy, you place the call into the event OBJONEDITPLUGINSTYLE (60). I never tried to add a custom button to the standard style pop-up only. You must see the whole sequence: In order to fetch the PIO style, you need a PIO handle, but the event 5 (init properties), where you create the button, runs when the Pio handle is NIL. Whereby the question arises of WHEN and WHEREFROM that Plug-in Object Style palette fetches the parameters, since it doesn't seem to run through event 5. It shows the button as needed, so it must pick the stuff loaded in the code for event 5 somehow. If you select an object instance on drawing (PIO H != NIL) and click on "Edit Style" in its OIP, you'll raise the events' sequence 65 > 60 before the standard Plug-in Object Style dialog to appear. No event 5. See screenshot below, the button appears as it would be in the OIP, but there was no event 5 loaded (or detected). That is, I don't know how to show that button ONLY on style edit events. Below a few useful observations about returned events when working with styles (this is an oldish list, there might be more now): OIP selection Events: choose "New Plug-in Style from..." : 65: kObjStyleWidgetChosen the "save sym in folder" dialog appears 61: kObjCreatePluginStyle 63: kObjFinalizeCreateStyle 60: kObjEditPluginStyle 62: kObjUpdatePluginStyleObject 64: kObjFinalizeUpdateStyledObject choose "Edit Style" : 65: kObjStyleWidgetChosen 60: kObjEditPluginStyle 62: kObjUpdatePluginStyleObject 64: kObjFinalizeUpdateStyledObject choose "Replace" : 65: kObjStyleWidgetChosen 60: kObjEditPluginStyle 62: kObjUpdatePluginStyleObject 64: kObjFinalizeUpdateStyledObject choose Convert to Unstyled: 65: kObjStyleWidgetChosen the "choose a Plug-in Style" dialog appears 75: kObjValidateReplacePluginStyle 62: kObjUpdatePluginStyleObject 64: kObjFinalizeUpdateStyledObject contextual menu: 60: kObjEditPluginStyle 62: kObjUpdatePluginStyleObject 64: kObjFinalizeUpdateStyledObject BTW, I wouldn't set view at each regen of a PIO, a PIO has its own environment. You can coerce the Pio to regen on Top plan only in the Plug-in Properties, set "Projection" to "requires 2D" If you need to create 3D geometry from within, you might want to use vs.SetPlanarRefIDToGround on the 2D source shape, convert to NURBS or whatever, then turn it around in 3D as needed. if source2DShape != vs.Handle(0): vs.SetPlanarRefIDToGround(sourceShape) nurbsCurve = vs.ConvertToNURBS(sourceShape, False) Example of style access with alerts testing the events : def execute(): ## Uncomment the following to run this code in debug mode ## For more information refer to: http://developer.vectorworks.net/index.php/Python_Debugging #import pydevd #pydevd.settrace(suspend = False) global gPio_N, gPio_H, gPioRec_H, gWall_H, gPioPoly, gPioStyleN, gPioStyleH empty = 0 gCnt = 0 (ok, gPio_N, gPio_H, gPioRec_H, gWall_H) = vs.GetCustomObjectInfo() (theEvent, messageNr) = vs.vsoGetEventInfo() vs.AlrtDialog(f"{theEvent}") # just test events # test style access, you need the object var not to be NIL in order to fetch the style if gPio_H != vs.Handle(0): gPioStyleN = vs.GetPluginStyle(gPio_H) gPioStyleH = vs.GetObject(gPioStyleN) vs.AlrtDialog(f"{theEvent}\n{gPioStyleN}\n{gPioStyleH}\n{gPio_H}\n{gPioRec_H}") # 5: the PIO might have extended props, runs BEFORE kParametricRecalculate # here is where you add buttons, but here the object variable gPio_H is NIL! if theEvent == ke.OBJONINITXPROPERTIES: vs.SetPrefInt(590, 1) # enable eventing for this plug-in ok = vs.SetObjPropVS(ke.OBJXPROPREDSYMBOLISSTYLE, True) # Red Symbol of this object can be used to drag drop over existing instances to copy the attributes ok = vs.SetObjPropVS(ke.OBJXSUPPORTSSTYLES, True) # adds the Plug-in Style menu in the OIP and contextual menu ok = vs.SetObjPropVS(ke.OBJXPROPHASUIOVERRIDE, True) ok = vs.SetObjPropCharVS(ke.WIDGETGROUPMODE, vs.Chr(ke.WIDGETGROUPAUTOMATIC)) # uses widget groups ok = vs.vsoInsertAllParams() ok = vs.vsoAppendWidget(ke.WIDGETBUTTON, BUT_TEST, 'MyStyleButton...', empty) # event 3: regen elif theEvent == ke.PARAMETRICRECALCULATE: main() vs.vsoStateClear(gPio_H) # event 60, also on edit in res manager elif theEvent == ke.OBJONEDITPLUGINSTYLE: # enable a custom style dialog # if vs.GetCustomObjectInfo(gPio_N, gPioStyleH, gPioRec_H, temp_h) and (gPioStyleH != vs.Handle(0)): # MyCustomPIOStyleDialog(gPioStyleH) vs.vsoSetEventResult(ke.OBJEDITPLUGINSTYLEBYDEFAULT) # -10 # event 41, after selecting an obj, for building its OIP: set widget visib., enablem., fields elif theEvent == ke.OBJONWIDGETPREP: vs.vsoSetEventResult(ke.OBJECTEVENTHANDLED) elif theEvent == ke.OBJONOBJECTUIBUTTONHIT: if gPio_H != vs.Handle(0): someCode() Edited July 9, 2022 by _c_ 2 Quote Link to comment
Gregi Posted April 10, 2023 Share Posted April 10, 2023 (edited) Hello everybody So, almost a year has gone... so I got the "Style" thing a little bit of working, but not in the way i would like to. To have my Button in OIP AND in plugin-style-dialog is ok, i managed to do so How do I manage to have a pick-box to this button (better: the drawing behind it) in the settings? (screenshot) which way would you recommend to have a drawing object inside my PIO? I started with an 2d Path Object, to have the profile-Group for this. The Button just handles to "Edit Profile-Group" If i set the parameters "by style" the fields in OIP are grey (like expected), but on doubleclick i get the handles and if i edit the form, i can change those parameters by instance. to bring them back to "style" i have to open "edit style" an close. do i have to include an override in my code, like "if this param is set by style, copy param from style-sym-def"...? is there any "good" list of event constants anywhere (Appendix or similar)? it is a lot of work to search "all" the stuff about event handling, but it sounds really interesting to work with those things Edited April 10, 2023 by Gregi Quote Link to comment
Gregi Posted April 10, 2023 Share Posted April 10, 2023 On 7/9/2022 at 11:02 AM, _c_ said: BTW, I wouldn't set view at each regen of a PIO, a PIO has its own environment. You can coerce the Pio to regen on Top plan only in the Plug-in Properties, set "Projection" to "requires 2D" If you need to create 3D geometry from within, you might want to use vs.SetPlanarRefIDToGround on the 2D source shape, convert to NURBS or whatever, then turn it around in 3D as needed. I had some trouble in trying this, but id didnt work. maybe come back to this point later in my project. But as long as it works this way, im happy with it 😉 Quote Link to comment
michaelk Posted April 23, 2023 Share Posted April 23, 2023 On 2/16/2021 at 8:23 PM, Julian Carr said: Don't have much time but... A1. Yes must be event enabled. A2. You will need this:gFlag := SetObjPropVS(kObjXSupportsStyles, TRUE); { 49 } { Controls whether a parametric type support plug-in styles } and maybe these: gFlag := SetObjPropVS(kObjXPropHideStyleSettingsButton, TRUE ); { 69 } { hide unwanted style editing buttons } gFlag := SetObjPropTxtVS(kObjXPropSupportResourcePopup, 'Object Styles/MyStyledObject'); { 53 } { specified the default content folder } A3. Depends if you are using dialogs to access parameters. If you you have a lot more work to do. If not, then you can let Vw handle it from memory. A4. There are other events you may need too: 60: BEGIN { Edit Plug-in Style } vsoSetEventResult( -10 ); {kObjectEventHandled} { using -10 here causes the object properties dialogue to open next } END; 61: BEGIN { Create Plugin Style } vsoSetEventResult( 0 ); {kObjectEventHandled} END; 62: BEGIN { Update Styled Plugin Object } vsoSetEventResult( 0 ); END; 63: BEGIN { Finalize Create Style } vsoGetPluginStyleSym(gh1); SetAllStyleParams(gh1, 0); { this sets all parameters to not use the style } vsoSetEventResult( 0 ); END; 64: BEGIN { Finalize Update Styled Object } vsoSetEventResult( -8 ); END; 65: BEGIN { Style Widget Chosen } vsoSetEventResult( 0 ); END; { Create Style order of events: 61, 63, 60, 62, 64 } { Edit Style order of events: 60, 62, 64 } Hi Julian Where in the script do 60-64 go? Does that question even make sense 😱 Quote Link to comment
Vectorworks, Inc Employee Julian_Carr Posted April 25, 2023 Vectorworks, Inc Employee Share Posted April 25, 2023 They go in the main event loop. There are no doubt constant equivalents for these numbers. I just didn't have the list handy when I wrote the code. Quote Link to comment
michaelk Posted April 25, 2023 Share Posted April 25, 2023 @Julian_CarrSorry I'm being so dense about this :-). I'm coming late to event enabled objects. 60-65 must be part of a CASE statement. So the line before this would be Case _____?_____ of I promise some day soon I'll figure all this event aware stuff out! Quote Link to comment
MullinRJ Posted April 25, 2023 Share Posted April 25, 2023 @michaelk, If you are using "Case ________ of" then you must be using VectorScript, in which case you'd use (borrowing from @Julian Carr's example above): ... vsoGetEventInfo(theEvent, theData); case theEvent of { other events here } 60: BEGIN { Edit Plug-in Style } vsoSetEventResult( -10 ); {kObjectEventHandled} { using -10 here causes the object properties dialogue to open next } END; 61: BEGIN { Create Plugin Style } vsoSetEventResult( 0 ); {kObjectEventHandled} END; 62: BEGIN { Update Styled Plugin Object } vsoSetEventResult( 0 ); END; 63: BEGIN { Finalize Create Style } vsoGetPluginStyleSym(gh1); SetAllStyleParams(gh1, 0); { this sets all parameters to not use the style } vsoSetEventResult( 0 ); END; 64: BEGIN { Finalize Update Styled Object } vsoSetEventResult( -8 ); END; 65: BEGIN { Style Widget Chosen } vsoSetEventResult( 0 ); END; { Create Style order of events: 61, 63, 60, 62, 64 } { Edit Style order of events: 60, 62, 64 } { more "other events" here } end; { case theEvent } If you are using Python, there is no "CASE" statement, so you'll have to use an "IF" tree. HTH, Raymond Quote Link to comment
michaelk Posted April 25, 2023 Share Posted April 25, 2023 I’m not cool enough to use python 😄 Thanks Raymond! 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.