Joburg Posted February 5, 2018 Share Posted February 5, 2018 Is it possible to write a script that will export coordinates, perhaps start and end points, of lines (or other shapes) of the selected layer into a text format that could then be imported into excel. For example, if I had a 1 x 1 square with its centre at the workspace centre drawn with lines it would export something like: start point: -0.5,0.5 endpoint: 0.5.0.5 startpoint: 0.5,0.5 endpoint: 0.5,-0.5 etc. Quote Link to comment
Pat Stanford Posted February 5, 2018 Share Posted February 5, 2018 Yes, such a script can be written. But before you start, make sure you really think through the problem and know what you are trying to do. The commands to get the end points of lines are different than getting the corner points of rectangles which are different than getting the points of polygons. Think about how you are going to use the data. If you are really going to import it to Excel, do you really want the data on two lines with the Start and End text? Should that all be a single block of text, or should the text be in one cell and the number in a different cell. Do you really need to export to Excel, or would a VW Worksheet work? From there you could copy/paste into excel. I will be happy to try and assist, but based on the minimal description you have given, it feels like this may be a "Can you make it do this too." project. Define is a little more. Tell us WHY you want to do this, not just that you want to, especially if you want to learn how to write the script, you will get a lot of help here. Quote Link to comment
JBenghiat Posted February 5, 2018 Share Posted February 5, 2018 You could always create a report of type Line (using the Create Report... command). The following formula will give you the end points: =XCENTER-LENGTH*0.5*COS(DEG2RAD(ANGLE)) =YCENTER-LENGTH*0.5*SIN(DEG2RAD(ANGLE)) =XCENTER+LENGTH*0.5*COS(DEG2RAD(ANGLE)) =YCENTER+LENGTH*0.5*SIN(DEG2RAD(ANGLE)) You can either report the worksheet or copy and paste data into Excel. Quote Link to comment
Joburg Posted February 6, 2018 Author Share Posted February 6, 2018 9 hours ago, Pat Stanford said: Yes, such a script can be written. But before you start, make sure you really think through the problem and know what you are trying to do. The commands to get the end points of lines are different than getting the corner points of rectangles which are different than getting the points of polygons. Think about how you are going to use the data. If you are really going to import it to Excel, do you really want the data on two lines with the Start and End text? Should that all be a single block of text, or should the text be in one cell and the number in a different cell. Do you really need to export to Excel, or would a VW Worksheet work? From there you could copy/paste into excel. I will be happy to try and assist, but based on the minimal description you have given, it feels like this may be a "Can you make it do this too." project. Define is a little more. Tell us WHY you want to do this, not just that you want to, especially if you want to learn how to write the script, you will get a lot of help here. Thanks Pat, I was definitely a bit too vague. I think it will be easier if I stick with lines only. At the moment the idea is to draw in lines of the outline of a shed. Maybe in a different layer draw in the outlines of openings, etc. This data would then be exported to excel (compiling in a VW worksheet and exporting to excel would work just as well) to be analysed. The actual output of data doesn't matter too much, but the less work I need to do in excel the better. Xstart Ystart Xend Yend would probably be the easiest format. I've had a little bit of success in having a script generate a text doc, with the first row being tab separated headings; "Xstart Ystart Xend Yend". But filling in the actual data has me stumped. Quote Link to comment
Pat Stanford Posted February 6, 2018 Share Posted February 6, 2018 To pull it into a worksheet Josh's method above will work very easily and no scripting required. I am an engineer, and I am still always amazed and the "math" solutions that @JBenghiat, @michaelk (math major in college) and @MullinRJ come up with. Something like the following should do what you want. Note that this is off the top of my head and not tested or run in VW in any way. Based on your previous statement, it appears you already know how to open a file for writing to.: Var X1,Y1,X2,Y2 : Real; H1: Handle; Begin H1:=FActLayer; {Get the first object} While H1<> Nil DO Begin IF GetType(H1)= 2 Then DO Begin GetSegPt1(H1,X1,Y1); {Gets the start point of the line} GetSegPt2(H1,X2,Y2); {Gets the end point of the line} WritteLN(Concat(Num2StrF(X1),Tab(1),Num2StrF(Y1),Tab(1),Num2StrF(X2),Tab(1),Num2StrF(Y2))); {write out the 4 values separated by a tab character} H1:=NextObj(H1); {Go to the next object in the layer. NextObj works because FActLayer game a handle to a list pointing to only objects in the layer) End Else H1:=NextgObj(H1); {If it is not a line just go to the next object} End; {End of the While loop} End; Write back if you need more help Quote Link to comment
Joburg Posted February 6, 2018 Author Share Posted February 6, 2018 3 hours ago, Pat Stanford said: To pull it into a worksheet Josh's method above will work very easily and no scripting required. I am an engineer, and I am still always amazed and the "math" solutions that @JBenghiat, @michaelk (math major in college) and @MullinRJ come up with. Something like the following should do what you want. Note that this is off the top of my head and not tested or run in VW in any way. Based on your previous statement, it appears you already know how to open a file for writing to.: Var X1,Y1,X2,Y2 : Real; H1: Handle; Begin H1:=FActLayer; {Get the first object} While H1<> Nil DO Begin IF GetType(H1)= 2 Then DO Begin GetSegPt1(H1,X1,Y1); {Gets the start point of the line} GetSegPt2(H1,X2,Y2); {Gets the end point of the line} WritteLN(Concat(Num2StrF(X1),Tab(1),Num2StrF(Y1),Tab(1),Num2StrF(X2),Tab(1),Num2StrF(Y2))); {write out the 4 values separated by a tab character} H1:=NextObj(H1); {Go to the next object in the layer. NextObj works because FActLayer game a handle to a list pointing to only objects in the layer) End Else H1:=NextgObj(H1); {If it is not a line just go to the next object} End; {End of the While loop} End; Write back if you need more help That's perfect, thanks Pat. I've got the whole thing working with this: procedure coord; Var X1,Y1,X2,Y2 : Real; obj:handle; i:integer; ofile:string; begin obj:=factlayer; PutFile('Output file', ' ', ofile); while obj<>NIL do begin i:=GetType(obj); if (i=2) then begin GetSegPt1(obj,X1,Y1); GetSegPt2(obj,X2,Y2); write(X1); tab(1); write(Y1); tab(1); write(X2); tab(1); writeln(Y2); end; obj:=nextobj(obj); end; close(ofile); end; run(coord); Bit of a frankenstein's monster of your comment and a couple of other things. Next step for me will be to have it move to the next layer and produce a new report, but for now this is plenty to get me thinking about how excel can interpret the data. Thanks again. Quote Link to comment
Joburg Posted February 6, 2018 Author Share Posted February 6, 2018 (edited) 10 hours ago, JBenghiat said: You could always create a report of type Line (using the Create Report... command). The following formula will give you the end points: =XCENTER-LENGTH*0.5*COS(DEG2RAD(ANGLE)) =YCENTER-LENGTH*0.5*SIN(DEG2RAD(ANGLE)) =XCENTER+LENGTH*0.5*COS(DEG2RAD(ANGLE)) =YCENTER+LENGTH*0.5*SIN(DEG2RAD(ANGLE)) You can either report the worksheet or copy and paste data into Excel. I like this, elegant. I'll have to mess around with reports a bit more. Cheers! Edited February 6, 2018 by Joburg Quote Link to comment
Miguel Barrera Posted February 8, 2018 Share Posted February 8, 2018 My question would be why do you even want to export to excel in the first place? If it is for some kind of mathematical analysis, then why not do it in VW with scripts? Quote Link to comment
Joburg Posted February 9, 2018 Author Share Posted February 9, 2018 9 hours ago, Miguel Barrera said: My question would be why do you even want to export to excel in the first place? If it is for some kind of mathematical analysis, then why not do it in VW with scripts? Because I 'm good at excel, where as I need to post on a forum when I need to make a simple VW script. 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.