hexagon logo

Multi Dimensional Array to Single Dimension Array

Here's something I always seem to forget when I need it and have to think a little bit to remember (so why not document it here for my future self ps. you're memory is deteriorating quickly future self!).

            ASSIGN/ARRAY_1=ARRAY({PNT69},{CIR16},{CIR17})
            ASSIGN/ARRAY_2=ARRAY({LIN12},{PLN6},{PLN7},{PLN8},{LIN13})
            ASSIGN/ARRAY_3=ARRAY({LIN14},{PLN9},{PLN10},{PLN11},{LIN15})
$$ NO,
            load as many arrays into below vvvv
            ASSIGN/MULTI_ARRAY=ARRAY(ARRAY_1,ARRAY_2,ARRAY_3)
$$ NO,
            Push all items in multi dimensional array into a single dimensional array.
            
            ASSIGN/SINGLE_ARRAY=0
            ASSIGN/CNT=1
            ASSIGN/O_CNT=1
            DO/
            ASSIGN/I_CNT=1
            DO/
            ASSIGN/SINGLE_ARRAY[CNT]=MULTI_ARRAY[O_CNT,I_CNT]
            ASSIGN/CNT=CNT+1
            ASSIGN/I_CNT=I_CNT+1
            UNTIL/I_CNT > LEN(MULTI_ARRAY[O_CNT])
            ASSIGN/O_CNT=O_CNT+1
            UNTIL/O_CNT > LEN(MULTI_ARRAY)


You super users out there.. if you know a quicker, simpler, easier way to do this I would greatly appreciate it if you shared it below.
Parents
  • When you have the feature names enclosed in the "{" and "}" symbols within the array(s), what does that do?

    This code is coolAlien, when would you use something like this?


    Those there are pointers to features.
    Example:
     ASSIGN/V1={CIR10}
    $$ NO,
                V1.X <-- this is the same as CIR10.X
    


    This probably has a few different uses.

    The use I was in need of that day was this:

    1. First think of the "line too long" error Pc-Dmis gives you when an assignment that is just too, well, long. To try this create an ASSIGN/V1 = ARRAY(<put something here that's too long>, <to break it>Wink. In my case I had arrays with pointers to features eg. {CIR21} is a pointer to AUTO/FEATURE CIR21 that's a 2D circle.

    2. When it gets too long you have no choice but to break them up into multiple array variables (ASSIGN/V1=ARRAY()). When you do this you'll end up with your data broken up into different variables, not good when your Function only takes one variable array! So, you must take all of your data/variables and combine them into one.

    3. My brain always goes to this thought "hey, just take your variables and combine them into one array!" and I always, I mean always, make the mistake of using this:
                ASSIGN/ARRAY_1=ARRAY({PNT69},{CIR16},{CIR17})
                ASSIGN/ARRAY_2=ARRAY({LIN12},{PLN6},{PLN7},{PLN8},{LIN13})
                ASSIGN/ARRAY_3=ARRAY({LIN14},{PLN9},{PLN10},{PLN11},{LIN15})
                ASSIGN/ARRAY_4=ARRAY({PNT35},{PNT51})
                ASSIGN/ARRAY_ALL=ARRAY(ARRAY_1, ARRAY_2, ARRAY_3, ARRAY_4)
    


    which unfortunately doesn't yield what I expect!!!! It does not give the expected results, you'd think I'd remember what the above does exactly given that I commit this mistake a bunch but, I just don't remember what the above yields I just remember that it doesn't combine all of your arrays into one handy array (too easy, right?!). That is what the original post purpose was crated for... to assist me when my bad memory strikes again! Hopefully I remember that I made this post...
    UPDATE: memory came back.. the above is only parts way done. This creates a multi dimensional array (see original post for making it a single dimensional array).


    Now if you're wondering why I use these 'pointer to features'? Well that's a slightly different story...

    1. In my environment called the workplace and "the way we do things around here!" (imagine a hardcore east-coast mobster accent). We machine parts in multiple ops... sometimes some features will be milled in but will have no datums to measure them to and on the next operation the feature will be inaccessible (great! not great).

    2. What I do (not saying it's the best solution but it's my only goto solution that I thought up and have stuck to)... I measure the said feature export it's characteristics to a text file and then recreate it on the next OP via the builtin generic feature from the characteristics that were read in from the text file.

    3. I am lazy. I hate having to type stuff out over and over and then not to mention what long run maintenance will hinder me. My solution was to create a function with two inputs

    a. array of features and
    b. text file string

    to export. And on the next OP to import I have a function look for a text file that matches ID and part name (that's already in the program for other reasons) and it creates every feature in generic form that I can reference like this:
    first create what will create all the generic features in a subroutine
    $$ NO,
                _____________________________________________________________________________________________
                
                Import data
                _____________________________________________________________________________________________
                (alignment is translated at export so no need to create an 'Import Alingment')
                
    CS1        =CALLSUB/BUILD_FROM_TXT,C:\Users\Public\Documents\WAI\PC-DMIS\2015.1\Subroutines\SubRoutineLibrary.PRG:PART,SERIAL,,,,,
    


    and then I reference them with ......................................here vvvvvvvvvvvvvvvvvv
    DIM D14_1= 2D DISTANCE FROM PLANE PLN9 TO CS1:ISUB2[1] PAR TO   ZAXIS,NO_RADIUS  UNITS=IN,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    M       0.7300     0.0100     0.0100     0.7300     0.0000     0.0000 ----#----
    


    It all happens in the background I just send a group of mixed features eg vector point, circles, etc oh and variable of non feature types like "hello" (no limit on the quantity) and on the next OP I build them back up automatically. Saves me a bunch of time (mainly cuz I'm lazy).







    To simplify it here's some more of the same code:

    EXPORT (first op1)
    $$ NO,
                _____________________________________________________________________________________________
                
                Export data
                _____________________________________________________________________________________________
                
                RECALL/ALIGNMENT,INTERNAL,EXPORT_ALN
                ASSIGN/ARRAY_1=ARRAY({PNT69},{CIR16},{CIR17})
                ASSIGN/ARRAY_2=ARRAY({LIN12},{PLN6},{PLN7},{PLN8},{LIN13})
                ASSIGN/ARRAY_3=ARRAY({LIN14},{PLN9},{PLN10},{PLN11},{LIN15})
                ASSIGN/ARRAY_4=ARRAY({PNT35},{PNT51})
                ASSIGN/MULTI_ARRAY=ARRAY(ARRAY_1,ARRAY_2,ARRAY_3,ARRAY_4)
    $$ NO,
                Push all items in multi dimensional array into a single dimensional array.
                
                ASSIGN/SINGLE_ARRAY=0
                ASSIGN/CNT=1
                ASSIGN/O_CNT=1
                DO/
                ASSIGN/I_CNT=1
                DO/
                ASSIGN/SINGLE_ARRAY[CNT]=MULTI_ARRAY[O_CNT,I_CNT]
                ASSIGN/CNT=CNT+1
                ASSIGN/I_CNT=I_CNT+1
                UNTIL/I_CNT > LEN(MULTI_ARRAY[O_CNT])
                ASSIGN/O_CNT=O_CNT+1
                UNTIL/O_CNT > LEN(MULTI_ARRAY)
    CS1        =CALLSUB/WRITE_TO_TXT,C:\Users\Public\Documents\WAI\PC-DMIS\2015.1\Subroutines\SubRoutineLibrary.PRG:PART,SERIAL,SINGLE_ARRAY,,,,
                WORKPLANE/ZPLUS
                RECALL/ALIGNMENT,INTERNAL,MAIN_ALN
    


    IMPORT (next op2)
    $$ NO,
                _____________________________________________________________________________________________
                
                Import data
                _____________________________________________________________________________________________
                (alignment is translated at export so no need to create an 'Import Alingment')
                
    CS1        =CALLSUB/BUILD_FROM_TXT,C:\Users\Public\Documents\WAI\PC-DMIS\2015.1\Subroutines\SubRoutineLibrary.PRG:PART,SERIAL,,,,,
    


    Obviously the subroutine program isn't shown as that was built by me but my employer owns it and I don't feel like asking to share their stuff.

    PS.
    I can't believe how much fit in this single post and the forum didn't bark at me "post too long"!

    PS-PS
    Forgot that PcDmis help files are online. Here check out this link towards the bottom you'll find curly bracket material:
    https://docs.hexagonmi.com/pcdmis/2019.1/en/helpcenter/mergedProjects/core/26_expression_topics/Variables.htm
  • I ran into the line too long recently, bad habit of naming features and variables with long ID... never knew this will definitely use
Reply Children
No Data