maplab Posted May 15, 2020 Share Posted May 15, 2020 I would to capture the x,y coordinate pair for each point in a polygon, and then put it into a column of a Vectorworks Worksheet, as a comma delimited string. There is no built in function to do this. Does anyone have such a VectorScript solution? If not, can such a script be developed? Quote Link to comment
Pat Stanford Posted May 15, 2020 Share Posted May 15, 2020 I don't remember ever seeing a script this like this, but it is certainly possible. Tell us more about exactly what you want to do and what you need the output to be and maybe something special will happen. Selected objects or all polys? One long text string for multiple objects or a separate row for each object? What do you expect the maximum number of vertices to be? What are you going to do with the data after you get it into the worksheet? Is there a different form that would be better than the worksheet? Any details appreciated. I don't mind helping but when I see the 4th or 5th "Oh, but it would be so much better it it would do this also." it makes me regret that I ever started on a lot of projects. Quote Link to comment
maplab Posted May 15, 2020 Author Share Posted May 15, 2020 Hello Pat, and thanks for your reply, Here are some answers to your questions: Tell us more about exactly what you want to do… I am drawing Room Polygons on Floor Plans in Vectorworks to seed Emergency Response Indoor Mapping and Tracking web apps. I am using Safe Software FME to transform and translate Vectorworks building models to various formats such as: Apple Indoor Mapping Data Format (IMSD) Google Maps JavaScript API & KML Esri ArcGIS Indoors SVG (Scalable Vector Graphics) OGC IndoorGML Selected objects or all polys? Multiple polygons are created on Layers for Rooms, MEP Equipment Footprints, and POIs (Points of Interest). Layers of these polygons need to be described in plain text coordinates relative to a given x,y origin and scale, to facilitate translation to other formats. One long text string for multiple objects or a separate row for each object? Each polygon is identified with a unique ID (name) and attributed with User Parameters such as Room Name, and Space Category through a Record Resource. Other parameters are functions such as Area, and Perimeter. There is no built-in function to retrieve the individual point coordinates of the vertices. So for each Polygon in the worksheet, there would be a space or comma delimited string of these coordinate pairs. Typical floor can contain 20 to 200 rooms. What do you expect the maximum number of vertices to be? 50 to 100 What are you going to do with the data after you get it into the worksheet? The data export from the worksheet will feed a FileMaker application to “data model” the building, along with the Vectorworks CAD model. Is there a different form that would be better than the worksheet? No See attached Sample file available upon request HelloPat.pdf Quote Link to comment
Pat Stanford Posted May 15, 2020 Share Posted May 15, 2020 Perfect. Your explaination tells me the best way to do this is as a Worksheet Script. It wil be entered into the database row of the worksheet just like any other function (like Area) and will return the value directly to the cell of the worksheet. This actually makes it MUCH simpler. Let me see what we can do. Thanks, Pat Quote Link to comment
maplab Posted May 15, 2020 Author Share Posted May 15, 2020 Thank you, David Coggeshall San Francisco Communications Golden Gate Safety Network 79 Rossi Avenue, SF CA 94118 415 387-8760 415 602-2174 cell ibcomm@aol.comhttp://maplab.org Quote Link to comment
Pat Stanford Posted May 16, 2020 Share Posted May 16, 2020 Try this. Copy everything in the text block below including the Procedure and Run lines at the top and bottom and paste into a new blank Vectorscript. In a worksheet create a database row that will return the polygons you want the points to. In the column you want the points list in set the formula to: =RunScript('Name you gave the script goes here') You should get a dialog box asking if you want to allow the script to run. Say yes. Now every time you recalculate the worksheet it will update the points of the polys. A couple of notes. This only works for 2D Polygons. Rectangles, Polylines, 3D Polygons, Spaces are not Polygons and will return a value of 'Not a Polygon' instead of a list of points. This has been very lightly tested. Test before using for critical applications. Procedure GetPolyPoints; {May 15, 2020} {© 2020 Patrick Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} {A Vectorworks 2020 worksheet script to return the X/Y Coordinates} {of each Polygon object in a worksheet database.} {Run using the RunScript function in the worksheet} {No Warranty Expressed or Implied. Use at your own risk.} {Test on an inconsipcuous spot before using. Do not operate} {heavy equipment while using the script. Here be Dragons.} var S1:String; H1:Handle; Procedure Walk(Hd1:Handle); var X1, Y1: Real; N1: Integer; Begin S1:=''; If GetTypeN(Hd1)= 5 then Begin For N1:= 1 to GetVertNum(Hd1) do Begin GetPolyPt(Hd1, N1, X1, Y1); If S1='' then S1:=Concat(X1, ',', Y1) Else S1:=Concat(S1, ',', X1, ',', Y1); End; End Else S1:='Not a Polygon'; End; Begin H1:=WSScript_GetObject; Walk(H1); WSScript_SetResStr(S1); End; Run(GetPolyPoints); Quote Link to comment
maplab Posted May 16, 2020 Author Share Posted May 16, 2020 Thank you very much Pat, I will test your script today and let you know how it goes. All the best, David C Quote Link to comment
maplab Posted May 16, 2020 Author Share Posted May 16, 2020 Pat, Will this work on a single segment line with just two endpoint coordinates? Quote Link to comment
Pat Stanford Posted May 16, 2020 Share Posted May 16, 2020 As written it will only work with Polygons. If you draw a line or a rectangle it will not work with those object. If could be updated to work with other typed of objects, but they would have to be written as special cases and handled separately. A Rectangle can be converted to a poly. As of VW2020, I am not able to create a polygon with only two vertices. If I try to draw it with the Polygon tool it inserts as a Line. If I draw a Polygon with three vertices, It will not let me delete any of the vertices to make a 2 point poly. Quote Link to comment
maplab Posted May 16, 2020 Author Share Posted May 16, 2020 Hi Pat, I understand. As background, the new Apple format is IMDF (Indoor Mapping Data Format). IMDF requires Polygons for: 1) Venue - Property/Site Boundary 2) Footprint/Level - Floorplate 3) Unit(s) - All Rooms and Spaces drawn to the middle wall 4) Fixtures - Equipment Footprints and Points for: 5) Amenities - Destination POIs But for navigation calculation, IMDF also requires: 6) Door/Openings - expressed as coincident Line Segments on the space boundary I know how to get Points, and your script will handle Polygons, so the last piece of the puzzle is simple Lines. I would like to speak by phone, if you are available, and I have a highly developed Church Model that I can share with confidentiality. David Coggeshall San Francisco Communications Golden Gate Safety Network 79 Rossi Avenue, SF CA 94118 415 387-8760 415 602-2174 cell ibcomm@aol.comhttp://maplab.org Quote Link to comment
Pat Stanford Posted May 16, 2020 Share Posted May 16, 2020 Hi David, Script can be easily modified to handle lines and points. I will try and call you later. Quote Link to comment
Pat Stanford Posted May 16, 2020 Share Posted May 16, 2020 Procedure GetPolyAndLinePoints; {May 16, 2020} {© 2020 Patrick Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} {A Vectorworks 2020 worksheet script to return the X/Y Coordinates} {of each Polygon and Line object in a worksheet database.} {Run using the RunScript function in the worksheet} {No Warranty Expressed or Implied. Use at your own risk.} {Test on an inconsipcuous spot before using. Do not operate} {heavy equipment while using the script. Here be Dragons.} var S1:String; H1:Handle; Procedure Walk(Hd1:Handle); var X1, Y1: Real; N1: Integer; Begin S1:=''; If GetTypeN(Hd1)= 5 then Begin For N1:= 1 to GetVertNum(Hd1) do Begin GetPolyPt(Hd1, N1, X1, Y1); If S1='' then S1:=Concat(X1, ',', Y1) Else S1:=Concat(S1, ',', X1, ',', Y1); End; End Else Begin If GetTypeN(Hd1)= 2 then Begin GetSegPt1(Hd1,X1,Y1); S1:=Concat(X1, ',', Y1); GetSegPt2(Hd1, X1,Y1); S1:=Concat(S1, ',', X1, ',', Y1); End Else S1:='Not a Polygon or line'; End; End; Begin H1:=WSScript_GetObject; Walk(H1); WSScript_SetResStr(S1); End; Run(GetPolyAndLinePoints); Quote Link to comment
maplab Posted May 16, 2020 Author Share Posted May 16, 2020 Wonderful ! Will you call later? Thanks, and I look forward to explaining our project more to you soon. Cheers, Quote Link to comment
maplab Posted May 17, 2020 Author Share Posted May 17, 2020 Hello Pat, I am having a hard time trying to implement your script. I am including a screen shot and a test file. The column function is not recognized as a formula, and is treating like a regular string. I am in Vectorworks 14. I hope that is not the problem ;-( Please advise, thanks. David Coggeshall PolyTest.vwx Quote Link to comment
Pat Stanford Posted May 17, 2020 Share Posted May 17, 2020 Sorry David, VW14 will not do what you want. RunScript was not added until VW2016. Sorry. Quote Link to comment
MullinRJ Posted May 17, 2020 Share Posted May 17, 2020 Hello David, When you do get up to, or beyond VW 2016 (where the WS functions were introduced) you will have to use "=RunScript() instead of "=Run(), as I see in your screen shot. Raymond Quote Link to comment
maplab Posted May 17, 2020 Author Share Posted May 17, 2020 Thank you Pat and Raymond, So I will need to beg a fresh NFR copy of Vectorworks from Robert Anderson some time soon. I am in the non-profit space, on less than a shoe string budget ;-( It is amazing that VW 2014 still does what I need 😉 Best regards, David Coggeshall San Francisco Communications Golden Gate Safety Network 79 Rossi Avenue, SF CA 94118 415 387-8760 415 602-2174 cell ibcomm@aol.comhttp://maplab.org Quote Link to comment
garrrth Posted January 29, 2021 Share Posted January 29, 2021 Hi all I was searching for something to do this a couple years back and couldn't find any examples, but managed to wrangle something together myself using python (VW 2020). Turns out it's pretty much the same method you have above, so at least I know I was on the right track! I do have a question though, which I'm unable to determine from any docs anywhere. When using this method (iterating through the points using vs.GetVertNum(h) and vs.GetPolyPt(h, vertexNum)), does VWX make any guarantees on whether that is done clockwise or counter-clockwise? Hope it's ok to piggyback on this thread - seems relevant to it though. 1 Quote Link to comment
Pat Stanford Posted January 29, 2021 Share Posted January 29, 2021 I don't believe there is any guarantee. I think that it is in the order that the polygon was drawn. So if you always draw clockwise then the returns should always be clockwise. Quote Link to comment
garrrth Posted February 1, 2021 Share Posted February 1, 2021 Thanks for the response. That's a shame though. I see now that vectorworks has a button to show the direction of a polygon with a red arrow, and also has a button for changing that direction. I've seen no reference to this in the vectorscript docs So, for anyone stumbling on this at a later point, I used this method (https://en.wikipedia.org/wiki/Curve_orientation#Orientation_of_a_simple_polygon) to tell me the direction of the polygon, and if it's counter-clockwise, to reverse the array of points that I had. Seems primitive, and I haven't fully tested it yet, but it should do the job. Quote Link to comment
Pat Stanford Posted February 1, 2021 Share Posted February 1, 2021 Check out the Vectorscript Appendix. Is 2D Poly Clockwise. 652. TRUE or FALSE. GetObjectVariableBoolean Quote Link to comment
garrrth Posted February 2, 2021 Share Posted February 2, 2021 Ah, brilliant. Didn't think to check the appendix. Still getting used to Vectorscript! What I'm doing works, but this is probably a more efficient check. Thanks for this. Quote Link to comment
Pat Stanford Posted February 2, 2021 Share Posted February 2, 2021 In my opinion, if you are trying to write Vectorscript and you don't have the local Function Reference in one tab, the Vectorscript Appendix, in a second, and the Developer Wiki in a third you are really hindering yourself. I prefer the swiftness of the local version of the Function Reference, but sometime there have been notes added to the Developer Wiki that are invaluable in figuring out the details. 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.