11export script_name = " Align and Distribute"
22export script_description = " Align and distribute lines relative to something"
3- export script_version = " 0.0.1 "
3+ export script_version = " 0.0.2 "
44export script_author = " PhosCity"
55export script_namespace = " phos.AlignAndDistribute"
66
@@ -23,15 +23,15 @@ LineCollection, ASS, AegiGui, AssfPlus = depctrl\requireModules!
2323
2424createGUI = ( lines, hasClip, playRes, layoutRes) ->
2525 relativeToTable = {}
26+
2627 if # lines > 1
2728 relativeToTable = { " First Line" , " Last Line" , " Custom Line" }
2829
30+ relativeToTable[ # relativeToTable + 1 ] = " Video"
31+
2932 if hasClip
3033 relativeToTable[ # relativeToTable + 1 ] = " Clip"
3134
32- if AssfPlus . _util. checkVideoIsOpen!
33- relativeToTable[ # relativeToTable + 1 ] = " Video"
34-
3535 if # playRes > 1
3636 relativeToTable[ # relativeToTable + 1 ] = " PlayRes"
3737
@@ -75,6 +75,8 @@ calculate_deltas = (tbl) ->
7575
7676main = ( sub, sel) ->
7777
78+ AssfPlus . _util. windowAssertError AssfPlus . _util. checkVideoIsOpen!, " You must have video open to use this script."
79+
7880 lines = LineCollection sub, sel
7981 return if # lines. lines == 0
8082
@@ -111,7 +113,7 @@ main = (sub, sel) ->
111113 targets =
112114 " First Line" : -> boundingBox[ 1 ]
113115
114- " Last Line" : -> boundingBox[ - 1 ]
116+ " Last Line" : -> boundingBox[ # boundingBox ]
115117
116118 " Custom Line" : -> boundingBox[ tonumber res. customLine]
117119
@@ -155,6 +157,11 @@ main = (sub, sel) ->
155157 if res. horizontal
156158 dx = horizontal_delta[ res. horizontalOptions] ( target, currentBoundingBox)
157159
160+ position = data\ getTags { " position" }
161+ if # position == 0
162+ effective_tags = ( data\ getEffectiveTags - 1 , true , true , false ) . tags
163+ data\ insertTags effective_tags. position
164+
158165 data\ modTags { " position" , " origin" , " clip_vect" , " iclip_vect" , " clip_rect" , " iclip_rect" , " move" } ,
159166 ( tg) -> tg\ add dx, dy
160167 data\ commit!
@@ -174,23 +181,15 @@ main = (sub, sel) ->
174181 " Left Edge" : ( item) -> item[ 1 ]
175182 " Right edge" : ( item) -> item[ 3 ]
176183
177- verticalTargetValues = {}
178- horizontalTargetValues = {}
179-
180184 local verticalDelta, horizontalDelta
181185 if res. vertical
182186 selector = verticalSelectors[ res. verticalOptions]
183- if selector
184- verticalTargetValues = [ selector( item) for item in * boundingBox ]
185-
186- verticalDelta = calculate_deltas( verticalTargetValues)
187+ verticalDelta = calculate_deltas( [ selector( item) for item in * boundingBox] )
187188
188189 if res. horizontal
189190 selector = horizontalSelectors[ res. horizontalOptions]
190- if selector
191- horizontalTargetValues = [ selector( item) for item in * boundingBox ]
191+ horizontalDelta = calculate_deltas( [ selector( item) for item in * boundingBox] )
192192
193- horizontalDelta = calculate_deltas( horizontalTargetValues)
194193
195194 lines\ runCallback (( lines, line, i) ->
196195 data = ASS \ parse line
@@ -200,6 +199,11 @@ main = (sub, sel) ->
200199 dy = verticalDelta and verticalDelta[ i] or 0
201200
202201 if dx != 0 or dy != 0
202+ position = data\ getTags { " position" }
203+ if # position == 0
204+ effective_tags = ( data\ getEffectiveTags - 1 , true , true , false ) . tags
205+ data\ insertTags effective_tags. position
206+
203207 data\ modTags { " position" , " origin" , " clip_vect" , " iclip_vect" , " clip_rect" , " iclip_rect" , " move" } ,
204208 ( tg) -> tg\ add dx, dy
205209 data\ commit!
0 commit comments