Jump to content
Developer Wiki and Function Reference Links ×

Script to draw line with preset object name?


Recommended Posts

Hi,

Trying to create a script within a palette that will let me draw a line with a preset object name defined within the script...

Don't know much about Vectorscript, I've tried using 'NameObject' but it doesn't give the line a name in the object info palette under the data tab as I hoped.

Procedure CustTool;

VAR

Name:STRING;

Result:BOOLEAN;

BEGIN

PushAttrs;

NameClass('NonPlot');

CallTool(-201);

NameObject('testing');

END;

Run(CustTool);

Link to comment

If you want to name an object, you have to call NameObject first.

At least that's what the function reference says.

Declaration:

PROCEDURE NameObject

( objName:STRING ) ;

Description:

Procedure NameObject assigns an object name to the next object created.

Parameters:

objName Name to be assigned to object.

Example:

NameObject('Part 5257');

Rect(0,2,2,0);

Link to comment

NameObject only works with objects drawn by VectorScript. The CallTool is effectively outside of the scope of the script so that does not work.

LNewObj does not work because the object is not defined as being the last new object created by the script until the script is done executing. In this case it might also have to do with the CallTool (see above).

The following does work:

Procedure CustTool;

VAR

Name:STRING;

Result:BOOLEAN;

BEGIN

PushAttrs;

NameClass('NonPlot');

CallTool(-201);

SetName(LObject, Date(2,2));

PopAttrs;

END;

Run(CustTool);

LObject is the last object in the drawing. Since that has to be the thing we just drew, it is safe to use in this case. If you used Send (forward/backward/front/back) in the script it might not be safe.

I am using Date(2,2) to generate a unique string since only a single object in the drawing can have a specific name, it just makes it easier to test without having to remember to delete the named object before running the script.

Link to comment
  • 1 month later...
LNewObj does not work because the object is not defined as being the last new object created by the script until the script is done executing. In this case it might also have to do with the CallTool (see above).

Is it possible that LNewObj does not work because using CallTool temporarily exits the script to give user control of the tool then returns to the script, and by doing this, does not see the object as being created within the script?

If you get rid of the CallTool from the script altogether, then LNewObj works fine:

Procedure CustTool;

VAR

Name:STRING;

Result:BOOLEAN;

p1x,p1y,p2x,p2y:REAL;

BEGIN

PushAttrs;

NameClass('NonPlot');

GetLine(p1x,p1y,p2x,p2y);

MoveTo(p1x,p1y);

LineTo(p2x,p2y);

SetName(LNewObj,Date(2,2));

PopAttrs;

END;

Run(CustTool);

Funny enough though, LObject also works in this case. I did not think LObject would work on the last object created during the script run. I thought until the script finished executing, it would find the last object created before the script run.

Can anyone explain clearly the intricacies of LNewObj versus LObject? Every time I think I understand it, I don't.

Link to comment
  • 6 months later...

Both Pat & Peter's scripts do what I was hoping for. Thanks fellas!

Sorry I'm no help with 'LNewObj' verus 'LObject' differences...

With regard to Pat's point:

"I am using Date(2,2) to generate a unique string since only a single object in the drawing can have a specific name, it just makes it easier to test without having to remember to delete the named object before running the script."

Is there some way I could have the script bleep out "This name is already in use. Reverting to old name." just as VectorWorks does when one tries to name an object with a name already existing in the file.

Thank-you all for your help!

Link to comment

LNewObject is a handle to the last object created using primitive drawing functions in the current script. This is thing like lineto, arcto, and many others. I think it will also give a handle to a 3D object that is created by the script. It will not provide a handle to an object that is created by duplicating another object. It will not provide a handle to a symbol or PIO called by the script because that object does not exist until the script ends and the screen drawing routines place the actual object.

LObject is the last object in the drawing. This will usually be the last object that has been created, but if you change the stacking order it may be the object at the top of the stack.

I think that you can turn on the VW pref to Stop Vectorscript on Warnings to get the behavior you want, but I have not tested it.

Link to comment
  • Vectorworks, Inc Employee

Andrew,

Checking for a duplicate name is simple.

In your case

If GetObject(Date(2,2)) <> NIL then AlrtDialog ('Name In Use');

or put it in a while loop if you just need a unique name

UniName := Date(2,2)

While GetObject(UniName) <> NIL DO

UniName := Concat(UniName,1);

SetName(LNewObj,UniName);

{There are better ways to do this but you get the point.}

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