Jump to content
Developer Wiki and Function Reference Links ×

Rectangle Plugin with Parameters referring to each other


VvierA

Recommended Posts

Hello there,

I'm trying to script a rectangular plugin with some parameters concerning the tilt of a line.

The parameters should refer to each other like that:

When you enter the angle as a parameter for the tilt in the palette, the parameter for the tilt in percentage should be calculated and vice versa.

And want to this just like the reference between polar-angle and classical x/y coordinates mode. No matter which values you enter - the other parameter will be calculated.

My idea is, to do that with

GetCustomObjectInfo(objName,objHd,recHd,wallHd);

and

SetRField(objHd,GetName(recHd),?Tilt?, Num2StrF(tilt));

The problem is, that Vectorworks stops with the errors:

Line #17: SetRField(objHd,GetName(recHd),?Tilt?, Num2StrF(tilt));

|

{ Error: Expected a new factor here. }

|

{ Error: Expected a string. }

|

{ Error: Expected , }

|

{ Error: Expected a new factor here. }

|

{ Error: Expected a DYNARRAY of CHARs. }

|

{ Error: Expected ) }

|

{ Error: Did not expect this after end of statement - missing ;? }

________________________________________

Can anybody help?

Q1:

Is this the correct method to build a plugin with Parameters refering to each other?

Q2:

If it's the right method - what's the cause for the error message?

Q3:

Am I right, that it is not possible to call the function 'GetCustomObjectInfo' directly? I have to use it like a handle for example: status:=GetCustomObjectInfo...;

And with defining the status handle by that, all the other information will be retrieved an be usable for the SetRField procedure.

Q4:

Are there any examples or open source plugins where I can study the correlation between two parameters in a rectangle object.

Thank you very much,

VvierA

Link to comment

Q1:

Yes, with

SetRField(PIOHandle,PIOName,ParameterName,ParameterValue);

you can adjust the value of your parameters of your PIO

Q2:

SetRField(objHd,objName,?Tilt?, Num2StrF(tilt));

Asuming that parameter name is 'Tilt' off course

Q3:

Yes, it's a function. Functions always return a value, in this case a Boolean. So your syntax will be:

...
VAR
bool : BOOLEAN;
objName : STRING;
objHd,recHd,wallHd : HANDLE;
BEGIN
bool:=GetCustomObjectInfo(objName,objHd,recHd,wallHd);
...

Q4:

I don't understand the question, but here's a simple example of a rectangular PIO:

PROCEDURE Example;
VAR
length,width : REAL;
BEGIN
{the length between click 1 and 2}
length:=PLineLength;
{When Mode 1: double of the length between click 2 and 3}
{When Mode 2: the length between click 2 and 3}
width:=PBoxWidth;
Rect(0,-width/2,length,width/2);
END;
RUN(Example);

Link to comment

@maarten

Thank you for your help. It seems to be that I was on the right way.

Unfortunately the error message is still there and I cannot find the typo I might have in my script.

Another question concerning your example: What do I need the bool variable for?

Or is it just used to get the handles for the setrfield function?

Q4:

I was looking for a example for a PIO where a parameter can be given in two or more ways. For example a PIO where you can set the tilt via delta y, or angle or as percentage.

@ Miguel

Thank you also. That sounds interesting. Can you give some links to information about 'event enabled method' and custom made parameter changes?

VvierA

Link to comment
Unfortunately the error message is still there and I cannot find the typo I might have in my script.

Could you post the line just above the one that's causing the error, sometimes the error is in the previous line.

Another question concerning your example: What do I need the bool variable for?

Or is it just used to get the handles for the setrfield function?

The Boolean is used to know if the function GetCustomObjectInfo was successful. That's why some programmers start their scripts like this:

...

BEGIN

IF GetCustomObjectInfo(objName,objHd,recHd,wallHd) THEN

BEGIN

{the rest of the script}

END;

...

That way they know for sure that they get the objName,objHd,recHd and wallHd of the now executing PIO.

Link to comment

The two lines producing the error message are:

resultstatus:=GetCustomObjectInfo(objectName, objectHand, recordHand, wallHand);

SetRField(objectHand,GetName(recordHand),?Space Width?,'Test');

What I was wondering is: The SetRField function needs a handle and some strings. Maybe the handle 'objectHand' is not successfully retrieved by the line above the SetRField command?

Link to comment

My guess is that some of your variables are not the right type. Make sure you have the following:

BOOLEAN:=GetCustomObjectInfo(STRING, HANDLE, HANDLE, HANDLE);

SetRField(HANDLE, GetName(HANDLE), STRING, STRING);

Also try passing objectName as the name of the record instead of GetName(recordHand).

HTH,

Josh

Link to comment

Thank you all. I found my mistake. I copied the string from the PDF Vectorscript Language Guide and the single quotes were not copied correctly. The difference was hardly visible. Now the function makes no error message but there is another problem:

I cannot set the parameter to the new value. The name of the Parameter is GEFPROZENT and the name of the variable (real) is also gefprozent.

I use the message function to get feedback and see what the values are.

In my example the variable gefprozent is '1', the Num2StrF of gefprozent is also '1' but PGEFPROZENT remains '0'.

What is my mistake?

Code:

resultstatus:=GetCustomObjectInfo(objectName, objectHand, recordHand, wallHand);

recordname:=GetName(recordHand);

gefaelle:=PGEFGRAD;

gefprozent:=tan(deg2rad(gefaelle));

SetRField(objectHand,recordname,'GEFPROZENT',Num2StrF(gefprozent));

message (gefprozent,' ',Num2StrF(gefprozent), ' ',PGEFPROZENT);

Link to comment

Parameters are constants, so they will remain exactly that throughout your script -- constant. If you were to run the script a second time, you should see the new parameter value (or just look in ObjectInfo).

For this reason, you should think about your parameters existing an a separate world from the variables you use to draw your object. In other words, gefprozent is what you should use for drawing calculations. Whether you get that value from the parameter or from tan(deg2rad(gefaelle)) depends on which field changed. Whether you store a new value to PGEFGRAD or to PGEFPROZENT also depends on which field changes.

You may want to have a look at the VS debugger, which you call with {$DEBUG}. It's far from perfect, but in your case it would save you from having to look at your variables with Message.

-Josh

Link to comment

My aim is to build something that is similar to the x/y coordinates vs. angle length mode in the object info palette for a line.

I want to have the option to enter the tilt of my PIO via angle or tilt in percentage.

And I want the object info palette to recalculate the other field when I define one field.

In order to do that I defined a variable to transfer the value of the parameter to it.

Than I wanted to do the recalculations and write the result back to the other parameter hoping that the value of the parameter in the object info palette will be refreshed.

Maybe that concept doesn't work?

Do I have to switch between the two methods to enter the tilt of my object by changing the visibility of the parameters?

I will try the debugger but I do not know yet if this helps me to finish my script successfully.

Maybe you know another example of an PIO where one parameter is calculated by another referring to each other?

Unfortunately it is not possible to study the built in tools like the 'Draw a Line' tool where one could study the correlation between the x/y fields and the angle/length mode. That's exactly what I am aiming for.

Link to comment

Your goals are perfectly clear. My above post adresses why you will not see a parameter constant value change in the same script after modifying it with SetRField.

Here are your next steps:

- Make sure you have a handle on setting parameter fields within a PIO.

- You need a method to determine which field is being changed by the user, the angle or percentage. If you have VW 2012 (and maybe 2011, I can't remember), you can use vsoStateGetParamChng to determine which parameter triggers a reset.

The other method is to store previous values for angle and percentage in an additional, hidden field. You compare values to see if one has changed.

-Josh

Link to comment

Do I get the handle on setting the parameter fields via:

resultstatus:=GetCustomObjectInfo(objectName, objectHand, recordHand, wallHand);

Or do I have to make it sure in another way?

Regarding the 'vsoStateGetParamChng' I am currently studying the Vectorscript References with all event and parameter related information. Not so easy - but maybe I get it. Some sample script might help if somebody knows one.

VvierA

Link to comment

Hello Josh,

thank you very much so far. Finally I got it. I read some warning about the complexity of event management in Vectorscript and decided to try the other method with the hidden parameter to compare the values. It works great.

The setting of the parameter also works now even though I do not know what the problem was. Maybe the restart of VW helped. The debugger is also very helpful.

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