Tom4 Posted December 6, 2007 Share Posted December 6, 2007 This is simple but, I hope it helps some new users get started. PROCEDURE Note1; VAR Note : STRING; P : REAL; pX, pY:REAL; Name:STRING; Result:BOOLEAN; gridDistance:REAL; xValue, yValue: REAL; gridDistance2:REAL; TextHd:HANDLE; verticalAlignment:INTEGER; scaleXR,scaleYR:REAL; h:HANDLE; LScale:REAL; BEGIN SetOriginAbsolute(0,0); { NameClass('Symbols'); Layer('Symbols'); LScale:=(1/1); SetScale(LScale); gridDistance:= .5; GridLines(gridDistance); gridDistance2:= .125; PenGrid(gridDistance2); } BeginGroup; Note := ('Enter your text Here.'); BEGIN FillBack(0); FillPat(1); PenSize(7); PenPat(2); END; TextFont(GetFontID('Arial')); TextVerticalAlign(1); P := 0.0; pX := 0.0; pY := 0.0; GetPt( pX, pY); MoveTo(pX,pY); RELATIVE; Rect(-0.5, -0.875, 0.5, 0.0); RELATIVE; TEXTJUST (2); TEXTSIZE (10); TEXTORIGIN (-0.0, -0.063); BEGINTEXT; Note ENDTEXT; P := 0.0; pX := 0.0; pY := 0.0; EndGroup; DSelectAll; END; RUN (Note1); Quote Link to comment
Vectorworks, Inc Employee Robert Anderson Posted December 6, 2007 Vectorworks, Inc Employee Share Posted December 6, 2007 Tom, here are some suggestions on this script: 1. I'd (just for clarity's sake) eliminate the commented out code. 2. I would eliminate the SetOriginAbsolute() call. No sense in changing the user's settings unless that is the purpose of the script. 3. The Note variable can easily be set to a user prompt with the StrDialog call, e.g.: Note := StrDialog('Enter the boxed text:','ABC'); 4. The fixed size box seems a little too restrictive. You could use a pair of x,y values and the GetRect() call to have the user enter the box using his cursor. Instead of: GetPt( pX, pY); MoveTo(pX,pY); RELATIVE; Rect(-0.5, -0.875, 0.5, 0.0); You could more simply use: GetRect(x1,y1,x2,y2); Rect(x1,y1,x2,y2); and you'd additionally have the advantage of a "rubberband" rectangle. You could use that same xy pair to locate the origin of the text at the center of the box and then you could dispense with all the RELATIVE() calls. In addition, you could set your text origin to the exact center of the text by adding a SetTextVerticalAlign() call, and then you wouldn't have to do the little vertical offset: TextOrigin(x1+(x2-x1)/2,y1+(y2-y1)/2,); BeginText; note EndText; SetTextVerticalAlign(LNewObj,3); I use the handle-based SetTextVerticalAlign() because I don't want to change the document settings. As for the text size and font, I wouldn't specify them in the code. If you leave them unspecified, the script will use document defaults, and the user has more flexibility. I think this illustrates that even in a simple script, there's room for thought and for the user experience. I'd likt to encourage you to take another pass at this script and really "tighten it up". Good luck! Quote Link to comment
Tom4 Posted December 10, 2007 Author Share Posted December 10, 2007 Thanks Robert your comments are greatly appreciated I will take your advice. This forum is a great addition esspecially when the feed back is so possitive and helpful. Thanks again Quote Link to comment
Tom4 Posted December 11, 2007 Author Share Posted December 11, 2007 I've modified the script to your sugestions Robert, works great thanks. Alot of the predefined parameters were to stop errors as certain types of drawings have thier own standards, but the versatility of this should be very useful. Tom PROCEDURE Note1; VAR Note : STRING; P : REAL; pX, pY:REAL; Name:STRING; Result:BOOLEAN; x1, y1: REAL; x2, y2: REAL; TextHd:HANDLE; verticalAlignment:INTEGER; h:HANDLE; BEGIN BeginGroup; Note := StrDialog('Enter the boxed text:','ABC'); BEGIN FillBack(0); FillPat(1); PenSize(7); PenPat(2); END; TextVerticalAlign(3); GetRect(x1,y1,x2,y2); Rect(x1,y1,x2,y2); RELATIVE; TEXTJUST (2); TEXTSIZE (10); TextOrigin(x1+(x2-x1)/2,y1+(y2-y1)/2); BEGINTEXT; Note ENDTEXT; SetTextVerticalAlign(LNewObj,3); EndGroup; DSelectAll; END; RUN (Note1); Quote Link to comment
mike m oz Posted December 11, 2007 Share Posted December 11, 2007 Robert, is there a way of modifying the script so the 'box' automatically resizes to 'fit' the text? Quote Link to comment
Petri Posted December 11, 2007 Share Posted December 11, 2007 Mike, There is. You can query the width of the text object - but I think in most cases the user wants the text width to be adjusted to the box width. (It is funny that 20 year old cheap/free drafting programs we were able to put a box around a text object, but in VW, we have to have a Program for such a trivial thing.) Quote Link to comment
Vectorworks, Inc Employee Robert Anderson Posted December 11, 2007 Vectorworks, Inc Employee Share Posted December 11, 2007 Mike, you can draw a piece of text and then use the GetBBox() call to determine its bounding box, to which you can then draw a rect. Tom: Excellent improvement! Note that your new script is not only much shorter and easier to read, but also much more functional. NB: you don't need the TextVerticalAlign() call, because you are using the SetTextVerticalAlign() call. They do the same thing in this case, and the latter call is better because it doesn't change the program settings. In like manner, you could use the SetTextJust() call instead of the TextJust() call. My only other question now is the DSelectAll call. Wouldn't you run that (if at all) at the beginning, but leave selected the stuff you've just made? Then this works like any VectorWorks tool. Quote Link to comment
Tom4 Posted December 11, 2007 Author Share Posted December 11, 2007 Robert, I deselect because when I go thru and am at the point to add text to my drawing I've ended up adding alot of text and it all stayed selected and when I would zoom in and move a text line other text would still be selected and move unknown so I just select the text I want to move and I know that's the only change I am making Thank you all for the help on this Tom Quote Link to comment
C. Andrew Dunning Posted January 24, 2008 Share Posted January 24, 2008 Good morning! In celebration of being able to post files, here is a simple PIO that places text in automatically-resizing boxes. (This is in reply to the discussion a while ago about scripting that process...) 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.