Jump to content
Developer Wiki and Function Reference Links ×

Displaying Calculations in Object Info Panel


MaxStudio

Recommended Posts

I have a Plug In Object. When I select the Plug In Object I would like to see calculations (such as Area) displayed in the Object Info Palette.

Much like how it displays "Area" & "Perimeter" when a person creates a rectangle.

Does anyone know how to make this happen? I already have variables and the calculations. I just need to know how to have it displayed in the OIP.

I will further investigate. Thank You.

Link to comment

Create a parameter of type Static Text. Use SetRField to assign a value to the parameter. Use GetCustomObjectInfo to get the handle to the plug-in, and the plug-in name. Pass the plug-in name as the record name. Don't include the "P" in the field name. Use Num2StrF to convert any distances to strings.

HTH,

Josh

Link to comment

Ok this is what I have and it works. The only problem is it is displaying the results in the OIP in inches... is there a way to get it to display as feet and inches...

ex: the rectangle is 3'-0" wide x 2'-0 high, the width is displaying as 36.00 and the area displays as 864.00

I would like to have it display as width 3'-0" and area as 6 sq ft.

do i have to do the math and break it down using a concat?

Thanks

PROCEDURE plugin;

VAR

x, y, w, h, area : REAL;

widthdisplay, areadisplay: STRING;

result : BOOLEAN;

objname : STRING;

oh,rh,wh : HANDLE;

BEGIN

{ retrieve custom object information }

result:= GetCustomObjectInfo(objname,oh,rh,wh);

{ if object information was successfully retrieved }

IF result THEN BEGIN

{ retrieve parameters }

w := PW;

h := PH;

rect(x,y,x+w,y+h);

area:=w*h;

widthdisplay:=Num2Str(2,w);

areadisplay:=Num2Str(2,area);

SetRField(oh,objname,'Width',widthdisplay);

SetRField(oh,objname,'Area',areadisplay);

END;

END;

Run(plugin);

Link to comment

Thanks guys I was able to get it to work.

Now I'm trying to get more than one calculation to display but it is not allowing me do it.

currently I have the following:

widthstring:=Num2StrF(w);

SetRField(oh,objname,'Width',widthstring);

heightstring:=Num2StrF(h);

SetRField(oh,objname,'Height',heightstring);

Both static parameters show up in the OIP, but only one (the first one) displays the calculation. Any idea why? Do I need to have a separate handle and or object name for each?

Edited by MaxStudio
Link to comment

I don't see any inherent problems in the code. Check to see that your parameter is called "Height," without any spelling errors.

FYI, you can nest procedures, compacting the code to:

SetRField(oh,objname,'Width',Num2StrF(w));

The only downside to doing so is debugging can be a bit harder.

-Josh

Link to comment
  • 4 years later...

I am running into an issue related to this topic, wondering if it has come up for anyone else:

 

On the VW install on which I have been developing a plugin, I have had no problems when units are set to Feet and Inches, but when moving the plugin to other computers, suddenly I get an error trying to set the value of Static Text parameters when the units are in Feet and Inches.  It looks like somewhere within vectorworks, beyond the level of my plugin's code, there is a problem escaping quote marks.  I am building in Python.

 

Here is an example of some code:

diag = (width * width + height * height) ** (0.5)

vs.SetRField(oh, objname, 'Diag', vs.Num2StrF(diag))

 

the variables width and height are all the result of calculations based on dimension parameter fields.  On the computer where things function correctly, the math works out accurately, and the static text parameter called "Diag" is updated with a value that looks correct, and includes feet and inches quote marks

 

however, on some other computers, I get this error:

File "<string>", line 1444
vs.PDiag = '14'1.706"'
                   ^
  
Syntax Error: invalid syntax

There is no direct assignment to the "Diag" parameter in the code, as this error would suggest.  Only the SetRField call shown above.  This would suggest that somewhere behind the scenes, vectorworks is trying this assignment, and failing because of unescaped quote marks.  I do not get this error in other unit modes.  And it is strange that I do not get this error on every computer.

 

Any ideas from the group?

 

 

 

 

Edited by David Bengali
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...