Jump to content
Developer Wiki and Function Reference Links ×

How to make a PIO Styled?


Recommended Posts

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 }

  • Like 2
Link to comment
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...

 

 

Link to comment

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:

 

917209497_ScreenShot2021-02-24at4_32_29pm.thumb.png.bb432369ebc58840bea278d5414f6e4e.png

 

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?

Link to comment
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???

Link to comment
  • 1 year later...

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.

image.png.2b5f9f436627391f66429c549e1528a1.png

 

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? 🙂

image.png.db3169996a12d786e0377c273f675524.png

 

Link to comment

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()

 

 

956713257_Screenshot2022-07-09at11_48_53.png.1a2f80eda61e4615140a613b288d469e.png

Edited by _c_
  • Like 2
Link to comment
  • 9 months later...

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.

  1. To have my Button in OIP AND in plugin-style-dialog is ok, i managed to do so
  2. How do I manage to have a pick-box to this button (better: the drawing behind it) in the settings? (screenshot)
  3. 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"
  4. 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"...?
  5. 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

 

image.png.1775d13266e21b9549f89660b2228be0.png

Edited by Gregi
Link to comment
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 😉

Link to comment
  • 2 weeks later...
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 😱

Link to comment

@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

 

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