Sorting question

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jsmain
Posts: 62
Joined: 07 Feb 2014, 08:21

Sorting question

13 Apr 2015, 15:21

I have a file I am sorting some content from.

My desired sort would appear like this...

!var[$abm_active,0,1] # tracks abm active state
!var[$deck_a_bend,0,21] # non-zero = currently bending
!var[$deck_b_bend,0,21]
!var[$deck_a_bend_down,0,1] # 1 = bend down
!var[$deck_b_bend_down,0,1]
!var[$deck_a_bend_state,0,1] # tracks jog wheel state for bending
!var[$deck_b_bend_state,0,1]
!var[$deck_a_bend_up,0,1] # 1 = bend up
!var[$deck_b_bend_up,0,1]
!var[$deck_a_frame_search,0,1] # 1 = in frame search mode
!var[$deck_b_frame_search,0,1]
!var[$global_shift,0,1] # global shift state


The actual sort comes out like this...

!var[$abm_active,0,1] # tracks abm active state
!var[$deck_a_bend,0,21] # non-zero = currently bending
!var[$deck_a_bend_down,0,1] # 1 = bend down
!var[$deck_a_bend_state,0,1] # tracks jog wheel state for bending
!var[$deck_a_bend_up,0,1] # 1 = bend up
!var[$deck_a_frame_search,0,1] # 1 = in frame search mode
!var[$deck_b_bend,0,21]
!var[$deck_b_bend_down,0,1]
!var[$deck_b_bend_state,0,1]
!var[$deck_b_bend_up,0,1]
!var[$deck_b_frame_search,0,1]
!var[$global_shift,0,1] # global shift state

Each line is a variable declaration, and I would brefer to keep the Deck A & B declarations side by side.

Any suggestions on how to do this please?

Thanks for any assistance you can provide!
hd0202
Posts: 183
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Sorting question

13 Apr 2015, 15:52

Here is my suggestion:

Code: Select all

input =
(
!var[$abm_active,0,1] # tracks abm active state
!var[$deck_a_bend,0,21] # non-zero = currently bending
!var[$deck_b_bend,0,21]
!var[$deck_a_bend_down,0,1] # 1 = bend down
!var[$deck_b_bend_down,0,1]
!var[$deck_a_bend_state,0,1] # tracks jog wheel state for bending
!var[$deck_b_bend_state,0,1]
!var[$deck_a_bend_up,0,1] # 1 = bend up
!var[$deck_b_bend_up,0,1]
!var[$deck_a_frame_search,0,1] # 1 = in frame search mode
!var[$deck_b_frame_search,0,1]
!var[$global_shift,0,1] # global shift state
)
forsort =
loop, parse, input, `n, `r
{
  stringsplit, x, a_loopfield, ]
  if (instr(x1, "_a_"))
    forsort .= x1 . "]1]" . x2 . "`n"
  else if (instr(x1, "_b_"))
    forsort .= x1 . "]2]" . x2 . "`n"
  else
    forsort .= x1 . "]" . x2 . "`n"
}
stringreplace, forsort, forsort, _a_,, all
stringreplace, forsort, forsort, _b_,, all
stringtrimright, forsort, forsort, 1
sort, forsort
out =
loop, parse, forsort, `n
{
  stringsplit, x, a_loopfield, ]
  if (x2 = 1)
    stringreplace, x1, x1, $deck, $deck_a_
  else if (x2 = 2)
    stringreplace, x1, x1, $deck, $deck_b_
  else
    x3 := x2
  out .= x1 . "]" . x3 . "`n"
}
msgbox, % out
Hubert
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Sorting question

13 Apr 2015, 17:21

Why didn't you use the command Sort?
ciao
toralf
jsmain
Posts: 62
Joined: 07 Feb 2014, 08:21

Re: Sorting question

13 Apr 2015, 17:35

Personally, I did toraf, and the output wasn't ordered the way I would like.
Hubert, That looks like it will do what I'm after!

Thank you!
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Sorting question

13 Apr 2015, 17:52

Code: Select all

input =
(
!var[$abm_active,0,1] # tracks abm active state
!var[$deck_a_bend,0,21] # non-zero = currently bending
!var[$deck_a_bend_down,0,1] # 1 = bend down
!var[$deck_a_bend_state,0,1] # tracks jog wheel state for bending
!var[$deck_a_bend_up,0,1] # 1 = bend up
!var[$deck_a_frame_search,0,1] # 1 = in frame search mode
!var[$deck_b_bend,0,21]
!var[$deck_b_bend_down,0,1]
!var[$deck_b_bend_state,0,1]
!var[$deck_b_bend_up,0,1]
!var[$deck_b_frame_search,0,1]
!var[$global_shift,0,1] # global shift state
)

input := RegExReplace(input, "`am)(\[\$.*?_)([ab])(_[^\]]+\])", "$1$3$2")
Sort, input
MsgBox % RegExReplace(input, "`am)_\K(_[^\]]+\])([ab])", "$2$1")
jsmain
Posts: 62
Joined: 07 Feb 2014, 08:21

Re: Sorting question

13 Apr 2015, 18:42

Even better!

Wish I understood the RegEx strings.

Thanks AlphaBravo!
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Sorting question

13 Apr 2015, 21:41

Code: Select all

inFut = 
(
!var[$abm_active,0,1] # tracks abm active state
!var[$deck_a_bend,0,21] # non-zero = currently bending
!var[$deck_a_bend_down,0,1] # 1 = bend down
!var[$deck_a_bend_state,0,1] # tracks jog wheel state for bending
!var[$deck_a_bend_up,0,1] # 1 = bend up
!var[$deck_a_frame_search,0,1] # 1 = in frame search mode
!var[$deck_b_bend,0,21]
!var[$deck_b_bend_down,0,1]
!var[$deck_b_bend_state,0,1]
!var[$deck_b_bend_up,0,1]
!var[$deck_b_frame_search,0,1]
!var[$global_shift,0,1] # global shift state
)
Punction( a, b )     
{
StringSplit, a, a, _`,
StringSplit, b, b, _`,
Return a3 a4 > b3 b4 ? 1 : a3 a4 < b3 b4 ? -1 : a2 > b2 ? 1 : -1
}
Sort, inFut, F Punction
MsgBox % inFut
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Sorting question

14 Apr 2015, 10:30

Just for Pun

Code: Select all

Bariable  = 
(  
@"
!var[$deck_b_bend_state,0,1]
!var[$deck_b_bend_up,0,1]
!var[$deck_b_bend,0,21]
!var[$deck_b_bend_down,0,1]
!var[$deck_b_frame_search,0,1]
!var[$global_shift,0,1] # global shift state
!var[$abm_active,0,1] # tracks abm active state
!var[$deck_a_bend,0,21] # non-zero = currently bending
!var[$deck_a_bend_down,0,1] # 1 = bend down
!var[$deck_a_frame_search,0,1] # 1 = in frame search mode
!var[$deck_a_bend_state,0,1] # tracks jog wheel state for bending
!var[$deck_a_bend_up,0,1] # 1 = bend up
"
)
Leferences = 
(   Join|
    System.dll
    System.Core.dll
    System.Windows.Forms.dll
    mscorlib.dll
)
Kodes =
(
    using System.Windows.Forms;
    using System.Linq;                              
    using System.Collections.Generic;               
    using System.Text.RegularExpressions;                   
    class Klass
    {
        public void Mesod()
        {
			MessageBox.Show( string.Join("\n", Regex.Matches( %Bariable%, ".*?_(.*?)[,_](.*)[,_].*")
			.Cast<Match>().OrderBy(x => x.Groups[2].Value).ThenBy(x => x.Groups[1].Value))) ;
        }
    }
)
CLR_CreateObject( CLR_CompileC#( Kodes, Leferences), "Klass").Mesod()

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Frogrammer, gongnl and 272 guests