DrawScript Problem
David R. Lane (77) 766 posts |
I have written as simple a program as I can to illustrate a problem I am having with DrawScript. The intention is that the program draws 3 rectangles, then doubles all the co-ordinates of the corners of the rectangles and then draws the new double-sized rectangles in a new (second) Draw window. It is also intended that it prints out both the original rectangle data and then the new ‘double-size’ data. Running it from a task window, it correctly produces the two Draw windows and prints out the new ‘double-size’ data, but not the original data. The same is true if it is run by double-clicking on the program icon. The Drawscript program and the data file for its input can be found “here” http://www.eudoxus.me.uk/web_references.html . The data is for 3 rectangles and the text version of the data is as follows. DATA 3 The first number in each row after the first is the rectangle number (not used). The rest of each row consists of the co-ordinates of the bottom left corner followed by the length and height of the rectangle. The program expects to find the data in the root (or current?) directory and outputs a data file to the same directory. Can anyone throw some light on why the original data is not printed out as text? |
Chris Hall (132) 3584 posts |
Can anyone throw some light on why the original data is not printed out as text? You read in the original data, print them to the screen, double them, print them out to a file, read them back from a file and then print them to the screen. Printing to the screen in a multi-tasking environment is problematic. In single tasking it opens a window for such output. In multi tasking it just writes it onto the desktop and it may disappear under a window. Running in a task window can affect what appears on the screen in unpredictable ways – some things work, some don’t. Graphics mode and text mode (VDU 5 etc.) also work differently. I never use taskwindows (except for ps2pdf, which terminates with OS_Exit, so you have to). You may find ‘NewDrawing’ erases the original data. |
David R. Lane (77) 766 posts |
Thanks for that, Chris. I will probably alter my programs to write text output to a file which can be looked at after the program has run, thus avoiding printing it to the screen. I have been getting a lot of memory insufficient errors. I will be away from computers for a week and will not be using my mobile phone much. But I will be keen to see any other replies on return. |
Bernard Boase (169) 212 posts |
Chris is right. Plus, in my tests, a BASIC PRINT command in a DrawScript program produces no output to the desktop unless the DrawScript PROCNewDrawing has been executed, after which PRINT works but has to have its non-desktop window (default text viewport) closed before the Draw file plots are displayed. This is presumably a side-effect of the compromise between being able to run a DrawScript program in the desktop (or in a Task window) for immediate Draw file display versus the restrictions on running BASIC in an environment (the Desktop) for which it is not, at its simplest level, designed. |
David R. Lane (77) 766 posts |
Chris, I deleted the NewDrawing command from the test rectangles program, but it still did not print out the original data. Worse, it didn’t print out the double-size data either, just the two sets of 3 rectangles (the before and after) in one Draw window. |
David Pitt (3386) 1248 posts |
Yes. See the “Scripts Running” page from the help. “When a drawscript file icon is double-clicked in a Filer display its instructions are obeyed and any drawings constructed are delivered to a !Draw window(s). In this mode All VDU output statements in the script (e.g. PRINT, DRAW, CIRCLE etc) are disabled.” That is nice and clear one would think, the actual problem then becomes why is the final data printed out. See the use of the Alt key in the above “Scripts Running” page. “If the Alt key is held down while double-clicking the script icon, all VDU output will be delivered to a text file in an editor window. This can be useful where a record of text output from PRINT statements is required in addition to drawfile output.” This does capture the first data set, but not the last! |
David Pitt (3386) 1248 posts |
A pragmatic work around. Print the second batch of data before the NewDrawing command and Alt-double click the file. TD=OPENIN "RectanglesData" INPUT#TD,N DIM TN(N): DIM A(N): DIM B(N): DIM W(N): DIM H(N) PRINT N FOR I=1 TO N INPUT#TD,TN(I),A(I),B(I),W(I),H(I) PRINT TN(I)", ";A(I);", ";B(I);", ";W(I);", ";H(I) NEXT I CLOSE#TD ÚFrameSize(2,1.5,24,18) ÚAxesStyle("MathsAxes") ÚAxesScalesStyle("MathsScales") ÚAxes`(0,120,0,90) ÚAxesScales(24,5,18,5) ÚWidth(0.25) FOR I=1 TO N ÚRectangle(A(I),B(I),W(I),H(I)) NEXT I REM ÚNewDrawing PROCdoublesize END DEF FNMathsAxes(axis) CASE axis OF WHEN x_axis,y_axis ÚWidth(0.5) ÚTriangularEndCaps(6,15) =TRUE ENDCASE DEF FNMathsScales(axis,scale) LOCAL result CASE scale OF WHEN major CASE axis OF WHEN x_axis,y_axis ÚWidth(0.25) pipslength=10 pips=centre result=TRUE ENDCASE WHEN minor CASE axis OF WHEN x_axis,y_axis ÚWidth(0.25) pipslength=8 pips=centre result=FALSE ENDCASE ENDCASE =result DEF PROCdoublesize FOR I=1 TO N A(I) = 2*A(I): B(I) = 2*B(I): W(I) = 2*W(I): H(I) = 2*H(I) NEXT I TD = OPENOUT "RectanglesOut" PRINT#TD,N PRINT'N FOR I=1 TO N PRINT#TD,TN(I),A(I),B(I),W(I),H(I) PRINT TN(I)", ";A(I);", ";B(I);", ";W(I);", ";H(I) NEXT I CLOSE#TD ÚNewDrawing ÚFrameSize(2,1.5,24,18) ÚAxesStyle("MathsAxes") ÚAxesScalesStyle("MathsScales") ÚAxes`(0,120,0,90) ÚAxesScales(24,5,18,5) ÚWidth(0.25): ÚColour(&00000000) FOR I=1 TO N ÚRectangle(A(I),B(I),W(I),H(I)) NEXT I TD=OPENIN "RectanglesOut" INPUT#TD,N REM PRINT N REM FOR I=1 TO N REM INPUT#TD,TN(I),A(I),B(I),W(I),H(I) REM PRINT TN(I)", ";A(I);", ";B(I);", ";W(I);", ";H(I) REM NEXT I CLOSE#TD ENDPROC |
David R. Lane (77) 766 posts |
Thanks very much for finding this out. I should have RTFM, as they say. Anyway, I think it will be more staightforward to omit the BASIC command PRINT and instead print to file which can be looked at after the program has finished running. Also, it seems that the only way to input data to a program is from a data file, unlike BASIC where you can also input data from the keyboard. |
Martin Avison (27) 1512 posts |
Searching in StrongHelp is one of the reasons why I like SH: it is very fast to find things. It does not find those words because they are not in the v2.11 SH manual!
That is quite easy using TextSeek – gives results in a Throwback window, so a click gets it into your editor, then run it to get the page in your browser. |