Andrew Neilson Posted September 25, 2009 Share Posted September 25, 2009 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); Quote Link to comment
Miguel Barrera Posted September 25, 2009 Share Posted September 25, 2009 The name is assigned to the object following the procedure. Since you are calling a tool, it may be assigning the name to a temporary object used to draw the final object. Try assigning the name after the object is created. .... CallTool(-201); SetName(LNewObj,'Test Name'); Quote Link to comment
brudgers Posted September 25, 2009 Share Posted September 25, 2009 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); Quote Link to comment
Pat Stanford Posted September 25, 2009 Share Posted September 25, 2009 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. Quote Link to comment
PeterT Posted November 2, 2009 Share Posted November 2, 2009 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. Quote Link to comment
Andrew Neilson Posted May 3, 2010 Author Share Posted May 3, 2010 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! Quote Link to comment
Pat Stanford Posted May 4, 2010 Share Posted May 4, 2010 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. Quote Link to comment
Vectorworks, Inc Employee klinzey Posted May 4, 2010 Vectorworks, Inc Employee Share Posted May 4, 2010 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.} Quote Link to comment
Recommended Posts
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.