SamIWas Posted November 27, 2013 Share Posted November 27, 2013 This may not be possible, or else I'm just missing it. I am writing some scripts which have some multi-dimensional dynarrays. For instance, the dynarray may hold an X position, Y-position, and rotation for each symbol. Now, I know that you can sort a single-dimension dynarray using the sort command, but it seems odd that you can't sort a multi-dimensional dynrray by choosing which "row" you want to use as the sort. Am I missing something, or would I have to use two separate arrays and some sort of bubble sort to accomplish this? Quote Link to comment
Guest Frank Brault Posted November 27, 2013 Share Posted November 27, 2013 Use SortArray: If arraytosort is an array of records, it sorts on the fieldnumberth field of the record. PROCEDURE SortArray( VAR arraytosort :ARRAY; numtosort :INTEGER; fieldnumber :INTEGER); I think that it would actually be sorted on the column. hth, Quote Link to comment
SamIWas Posted November 28, 2013 Author Share Posted November 28, 2013 SortArray seems to work only on 1-dimensional arrays. It gives an error if used on a 2-dimensional array. Therein lies my problem! Quote Link to comment
MullinRJ Posted December 1, 2013 Share Posted December 1, 2013 Sam, ???If you create a STRUCTURE to represent the column fields of your 2D array, then you can create a 1D array of the structure which is sortable. Here's an example. Note, you can have field names the same as your variable names, but if that's confusing, then don't do it. HTH, Raymond ***** PROCEDURE SortStructureExample; { Sample code for sorting an array of a STRUCTURE. } { Gather X, Y, & Rotation of selected symbols and sort them by their Y value. } { Place multiple symbols on a design layer, select them, and run script. } { Symbols will highlight one at a time from lowest to highest Y value. } { 30 Nov 2013 - Raymond J Mullin } TYPE ???XYR = STRUCTURE ??????h :Handle;??????{ 1st field } ??????x, y, r :Real;???{ 2nd, 3rd & 4th fields } ???end;???{ XYR } VAR ???H :Handle; ???I, CntSel :Integer; ???SymPos :DynArray [] of XYR; BEGIN ???CntSel := NumSelectedObjects; ???Allocate SymPos [1..CntSel]; ???I := 0; ???H := FSActLayer; ???while (H <> nil) do begin ??????if (GetTypeN(H) = 15) then begin???{ symbol instance } ?????????I := I + 1; ?????????GetSymLoc(H, SymPos.x, SymPos.y); ?????????SymPos.r := GetSymRot(H); ?????????SymPos.h := H; ?????????H := NextSObj(H); ??????end;???{ if } ???end;???{ while } ???SortArray(SymPos, I, 3);???{ I = # of selected symbols, 3 = Y field } ???{ Highlight each symbol from lowest to highest Y value. } ???for I := 1 to CntSel do begin ??????DSelectAll; ??????SetSelect(SymPos.h); ??????wait(1); ??????RedrawAll; ???end;???{ for } ???SysBeep; END; Run(SortStructureExample); Quote Link to comment
SamIWas Posted December 2, 2013 Author Share Posted December 2, 2013 Thank you Raymond! That might do exactly what I want. It will be a few days before I can test it out, but I'll try to remember to come back and let you know! 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.