Jump to content
AlHanson

Plug-In Object Control Pts, OIP and Text Handling Qs

Recommended Posts

Posted (edited)

Working on figuring out plug-in tools via Python scripting and have a few questions:

 

-How can I add a separator line to the OIP? Also a slider? Interesting how these are present in Marionette but no direct easy access in the Plug In Manager.

 

-I'm having trouble with the default values on my control points- The defaults are set to values such as (0,30"), however when I insert the object all control points default to (0,0). Nothing in my script is directly updating these values, and they respond to being moved just fine after inserted. 

 

-I have a text object that is inserted at a control point, and a Boolean that toggles whether or not the text is displayed- how can I make this also get rid of the control point?

 

-How can I use the Text controls in the menu to adjust the text settings in my object?

 

 

Edited by AlHanson
added slider

Share this post


Link to post

I'm not too familiar to the Python side of things, but am familiar with Vectorscript, so I'll try to answer the questions as best I can.

  1. Adding a separator to the OIP is "relatively" simple.  The major caveat is that it requires your PIO to be event-based, which introduces a whole level of code that has to be implemented to make the script work, and I don't know the full Python implementation (but I can provide an example of the Vectorscript for it).  The other downside is that all of the event scripts are really poorly documented on the VW side of things, so it could take a bit of trial and error to get everything working properly.  Getting well acquainted with the Function Reference will help a lot.  To answer your question, though, you'll use the vsoAddWidget script or vsoInsertWidget script to add the separator in during the kObjOnInitXProperties block of the event handler.  As far as I know, you can't do a slider control without using the C++ SDK, but separators are type 100.
  2. I don't know about setting the control point defaults, I usually specify them in my scripts using SetRField, pointing toward the PIO's control point record field and then a ResetObject command to force a redraw once the field is set.  I'll play around a little bit if I get some time this evening and figure out the defaults, but that's how I typically set them up in the script.
  3. You can hide control points using the SetCntrlPtVis script.  This command is in the Object Events category, so it likely also requires the PIO to be event-based.
  4. To get your PIO object to respond to the text settings, you have to set the PIO's Object Variable 800 to true using the SetObjectVariableBoolean command.  You'll need a handle to the PIO, so you'll need to run GetCustomObjectInfo to get it.  In both Vectorscript and Python, this command returns a boolean, so I typically have a line of code reading:
    IF GetCustomObjectInfo(objName,objHd,recHd,wallHd) THEN SetObjectVariableBoolean(objHd,800,TRUE);

    You will likewise need to get a handle to the PIO for setting the control points as referenced in point #2 above.

I think there are a couple of users here who will be able to point you in the direction of how to do event-based scripts in Python, but you'll essentially be using vsoGetEventInfo to set up various "blocks" of code to setup the OIP, handle buttons in the OIP, and to determine the reset behavior of the PIO.  A quickish example I wrote for someone else on the Vectorscript forum might be help you decipher the Python side of things as the example does include a separator:

PROCEDURE TestObject;

	CONST

		kResetEventID = 3;
		kObjOnInitXProperties = 5;
		kObjOnObjectUIButtonHit = 35;
		kObjXPropHasUIOverride = 8;
		kWidgetSeparator = 100;
		kWidgetStaticText = 13;
		kFieldCoordDisp = 12;
		kSeparator1ID = 3001;
		kStaticText1ID = 4001;
		kCoordDisp1ID = 5001;

	VAR

		length1,length2,sumLength:REAL;
		objName,sumStr:STRING;
		objHd,recHd,wallHd:HANDLE;
		theEvent,theButton:LONGINT;
		result:BOOLEAN;
		dialog,layoutDialog:LONGINT;
		
	FUNCTION DrawDialog(DName:STRING) : LONGINT;

		BEGIN
			dialog:=CreateLayout(DName,TRUE,'OK','Cancel');
			
			{CreateControl(dialog,11,3,'Hmmm...Color',11);}
			
			CreateColorPopup(dialog,11,50);
			
			SetFirstLayoutItem(dialog,11);
			
			DrawDialog:=dialog;
		END;

	PROCEDURE GatherInfo(VAR item,data:LONGINT);

		BEGIN
			CASE item OF
				SetupDialogC:
					BEGIN
						SetColorButton(dialog,11,65535,0,0);
					END;
				1:
					BEGIN
					END;
				2:
					BEGIN
					END;
			END;
		END;

	BEGIN
		length1:=PNumber1;
		length2:=PNumber2;
		
		vsoGetEventInfo(theEvent,theButton);
		CASE theEvent OF
			kObjOnInitXProperties:
				BEGIN
					result:=SetObjPropVS(kObjXPropHasUIOverride,TRUE);
					result:=SetObjPropVS(kWidgetStaticText,TRUE);
					result:=vsoInsertAllParams;
					
					result:=vsoInsertWidget(3,kWidgetSeparator,kSeparator1ID,'',0);
					result:=vsoInsertWidget(4,kWidgetStaticText,kStaticText1ID,'Test',0);
					result:=vsoInsertWidget(5,kFieldCoordDisp,kCoordDisp1ID,'Blah',0);
				END;
			kObjOnObjectUIButtonHit:
				CASE theButton OF
					kCoordDisp1ID:
						BEGIN
							dialog:=DrawDialog('BlahBlahBlah');
							layoutDialog:=RunLayoutDialog(dialog,GatherInfo);
						END;
				END;
			kResetEventID:
				BEGIN
					sumLength:=length1+length2;
					sumStr:=Num2StrF(sumLength);
		
					TextOrigin(0,0);
					CreateText(sumStr);
					
						
					IF GetCustomObjectInfo(objName,objHd,recHd,wallHd) THEN SetRField(objHd,'Update Object Test','sumResult',sumStr); {This will update the static text parameter}
					vsoWidgetSetText(kStaticText1ID,sumStr); {This will update the widget}
				END;
		END;
	END;

	Run(TestObject);

 

  • Like 1

Share this post


Link to post

I should also mention that you will want to check the "Events-Based" box on the Options tab of the Edit Plug-in Definition dialog box for your PIO to make sure that it uses Object Events.  Also, I cannot recommend enough having the Vectorscript/Python Function Reference open while you are working on scripts.  It can be found in the installation directory of VW in the VWHelp folder and Script Reference sub folder.  I often have it open and use Ctrl+F to quickly find the functions that I need.  I find that HTML file to be far friendlier to navigate than the developer wiki page, but the developer page also tends to have more examples of code, so sometimes having both open is a good idea.

  • Like 1

Share this post


Link to post

Excellent, thanks for all the fantastic info @Jesse Cogswell! Lots to dig through here, will take me some time to explore and definitely keep me busy this weekend!

 

The function reference has definitely been my friend lately and has it's own dedicated screen at this point, but knowing what to look for is 90% of the battle- especially when can't just search for a clear term and have to guess on some abbreviations like 'CntrlPt' because searching for 'Control' doesn't help. Also, was not aware of the Script Reference HTML and it looks to be another great resource. I had previously steered clear of the VSO and Event Based stuff as I thought I saw in some post that these were really only available to C++ but looks like I'll need to spend some time reading and exploring this more.

Share this post


Link to post

Event-based plug-ins are very powerful, but suffer from the worst documentation.  There used to be a comprehensive breakdown of how they worked on an old website called vectorlab, which was a wiki page run by a group of very talented Vectorscript and SDK developers that filled in a lot of gaps within the documentation, but their page has been down for quite a while and is not coming back.  In fact, the official developer wiki still points to the old vectorlab page for the GetEvent documentation.

 

One of the vectorlab users, _c_, currently hosts some of the articles on the developer wiki, though not the events one.  She does have one you might find interesting regarding python development as well a comprehensive breakdown of Vectorscript's second-most least documented feature, List Browsers, which can be found here.

  • Like 1

Share this post


Link to post

_c_'s ears must have been burning, because she just started a thread on the very subject of Events-based Python plug-ins with examples.  Probably a great place to start.

 

 

  • Like 1

Share this post


Link to post
Posted (edited)

Still slowly working through things and haven't gotten into the event based stuff yet, but DEFINITELY spending some time playing with this example. Great to see this, I was just thinking about starting to make similar simple example projects to help the community and this is a great reference.

 

Here's a few things I have found so far:

-Incorrectly placed control points just seems to be a refresh bug. I've found that creating the control point the in the definition and then later changing it as I'm updating what the defaults should be as my script evolves doesn't take internally. It'll show the new default value but it's still holding the initial default value and sending that into the script. The only way I've been able to deal with this so far is to delete the control point in the definition, exit the plug in manager, (let the script spaz out with errors), and then go back into the plug in manager and create new control points with the corrected values. It's obnoxious but it's simple enough for a couple points since it auto names everything anyway.

 

-Hiding the control points definitely seems to be an event based function because I initially just built the hide portion into and ELSE statement, but when the conditions changed to true it wouldn't come back until I also built the make visible line into the the initial IF portion of the script. Interestingly though, there doesn't seem to be any need to check the Event Based execution in the definition options. Haven't dug into this any further since it's working just fine for my current needs, perhaps there's some distinction here that will become more obvious as I dig into the event based code more. 

 

 

Edited by AlHanson

Share this post


Link to post
On 3/27/2021 at 8:50 PM, Jesse Cogswell said:

_c_'s ears must have been burning, because she just started a thread on the very subject of Events-based Python plug-ins with examples.  Probably a great place to start.

 

 

 

It is a total coincidence, I have been called in for another thread from the German Forum. Quite spooky, though.

Share this post


Link to post
On 3/26/2021 at 8:33 PM, Jesse Cogswell said:

Event-based plug-ins are very powerful, but suffer from the worst documentation.  There used to be a comprehensive breakdown of how they worked on an old website called vectorlab, which was a wiki page run by a group of very talented Vectorscript and SDK developers that filled in a lot of gaps within the documentation, but their page has been down for quite a while and is not coming back.  In fact, the official developer wiki still points to the old vectorlab page for the GetEvent documentation.

 

One of the vectorlab users, _c_, currently hosts some of the articles on the developer wiki, though not the events one.  She does have one you might find interesting regarding python development as well a comprehensive breakdown of Vectorscript's second-most least documented feature, List Browsers, which can be found here.

 

Hello, I was Vectorlab in form of Orso.B.Schmid.

The event article was written by Charles Chandler somewhere around 2007, I can bring his work into the dev wiki, but there is documentation and @Vlado certainly will want to do it right, a lot happened ever since. If Vlado gives me the go, I'll bring it there until he has something better.

  • Like 1

Share this post


Link to post

Hi @_c_, please please go ahead.

Also, please feel free to modify the https://developer.vectorworks.net/, it's a wiki for that reason, to allow invested users to contribute with their knowledge.

 

Regards,

Vlado

  • Like 2

Share this post


Link to post

Grazie Vlado, I bring it on dev, Charles' article is very very good, helped all of us. People will love to have it back!

It can be updated and expanded once is there.

 

  • Like 2

Share this post


Link to post

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.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...