I'm very new to scripting, but what I'm hoping to be able to do seems very straightforward...I just have no idea how to start.
We have thousands upon thousands of script files that we use to define particle emitters. These don't follow any logical formatting, but I'd like to rectify that through a script. Here is an example of an unformated particle script:
What I'd like to be able to do is open up one of these particle files, and run a javascript that will go through and read each line and store the values as a variable, then output them into a more formatted version of the file that looks something like this:
So far, I've figured out how to have UltraEdit ask me for a file name, create the new file, paste the template version of the particle script into it (line by line)...but that's it. I'm at a complete loss as to how to read a variable from one file and paste it into the new one.
Here's my progress so far:
I have it mostly figured out...the part I'm not sure how to address is this part:
How can I read the current document and look for a line that contains a certain string (ie, NewPerFrame), then copy that whole line in as a variable that I can then use the lastIndexOf and slice to par down to the final variable/string I need to paste into my new format?
We have thousands upon thousands of script files that we use to define particle emitters. These don't follow any logical formatting, but I'd like to rectify that through a script. Here is an example of an unformated particle script:
Code: Select all
##############################
#Particle System
System
NewPerFrame .05
StartSize .2
StartSizeJitter 0.05
ExpandRate 0.9
ExpandType 1
EndSize 5
OrientationJitter 180
FadeInBy 0
FadeOutStart 3
FadeOutBy 5
Burst 0
WorldOrLocalPosition 1
FrontOrLocalFacing 0
EmissionType 0
EmissionRadius 0.0
EmissionHeight 0.0
EmissionStartJitter 0.01 0.01 0.01
InitialVelocity 0 0 0.0
InitialVelocityJitter 0.0 0.0 0.0
VelocityJitter 0.0 0.0 0.0
Spin 0
SpinJitter 0
TightenUp 0
StreakType 0
StreakScale 0
StreakOrient 1
StreakDirection 0
TextureName sharpstar.tga
TexScroll1 0.0 0.0 0.0
TexScrollJitter1 0.0 0.0 0.0
AnimFrames1 0
AnimPace1 0.0
AnimType1 0
TextureName2 0
TexScroll2 0.0 0.0 0.0
TexScrollJitter2 0.0 0.0 0.0
AnimFrames2 0
AnimPace2 0.0
AnimType2 0
Blend_mode 1
Alpha 130
StartColor 255 255 255
ColorChangeType 0
End
Code: Select all
#############################################################
## ParticleScriptName.part
#############################################################
System
## FLAGS ###########################################################
Flags AlwaysDraw IgnoreFxTint
## EMITTER ###########################################################
KickStart 0
TimeToFull 10
EmissionLifeSpan 0 +
EmissionLifeSpanJitter 0 +
DieLikeThis 0 #:BobbleDeath.part
DeathAgeToZero 0
Burst 0
NewPerFrame 0.0
MoveScale 1.0
BurbleAmplitude 1.0
BurbleType 0
BurbleThreshold 0.0
WorldOrLocalPosition 0
EmissionType 0
EmissionRadius 0.0
EmissionHeight 0.0
EmissionStartJitter 0.0 0.0 0.0
TightenUp 0.0
## MOTION ###########################################################
InitialVelocity 0.0 0.0 0.0
InitialVelocityJitter 0.0 0.0 0.0
VelocityJitter 0.0 0.0 0.0
Magnetism 0.0
Gravity 0.0
Drag 0.0
Stickiness 1.0
## PARTICLE ###########################################################
FrontOrLocalFacing 0
SortBias 0.5
OrientationJitter 0
Spin 0
SpinJitter 0
StartSize 5.0
StartSizeJitter 0.0
ExpandRate 0.0
ExpandType 0
EndSize 0.0
StreakType 0
StreakScale 20
StreakOrient 1
StreakDirection 1
## TEXTURE ###########################################################
Blend_mode Normal
TextureName white.tga
TexScroll1 0.0 0.0 0.0
TexScrollJitter1 0.0 0.0 0.0
AnimFrames1 0
AnimPace1 1
AnimType1 0
TextureName2 spark.tga
TexScroll2 0.0 0.0 0.0
TexScrollJitter2 0.0 0.0 0.0
AnimFrames2 0
AnimPace2 1
AnimType2 0
## PARTICLE ALPHA ###########################################################
Alpha 255
FadeInBy 0
FadeOutStart 0
FadeOutBy 0
StartColor 255 255 255
ColorChangeType 0
BeColor1 0 0 0
ByTime1 0
BeColor2 0 0 0
ByTime2 0
BeColor3 0 0 0
ByTime3 0
BeColor4 0 0 0
ByTime4 0
ColorOffset 0 0 0
ColorOffsetJitter 0 0 0
#############################################################
End
Here's my progress so far:
Code: Select all
// ----------------------------------------------------------------------------
// Format_Particle_Script.js
// Reads in variables from particle script and outputs into a templated format
// ----------------------------------------------------------------------------
// UltraEdit is our application object. All UltraEdit operations will use this
// object.
// Operations may be performed on the activeDocument property of the UltraEdit
// object.
// See UltraEdit Help for more details.
//Define Default Variables
var KickStart=0
var TimetoFull=10
var EmissionLifeSpan=0
var EmissionLifeSpanJitter=0
var DieLikeThis=0
var DeathAgeToZero=0
var Burst=0
var NewPerFrame=0.0
var MoveScale=1.0
var BurbleAmplitude=1.0
var BurbleType=0
var BurbleThreshold=0.0
var WorldOrLocalPosition=0
var EmissionType=0
var EmissionRadius=0.0
var EmissionHeight=0.0
var EmissionStartJitter="0.0 0.0 0.0"
var TightenUp=0.0
var InitialVelocity="0.0 0.0 0.0"
var InitialVelocityJitter="0.0 0.0 0.0"
var VelocityJitter="0.0 0.0 0.0"
var Magnetism=0.0
var Gravity=0.0
var Drag=0.0
var Stickiness=1.0
var FrontOrLocalFacing=0
var SortBias=0.5
var OrientationJitter=0
var Spin=0
var SpinJitter=0
var StartSize=5.0
var StartSizeJitter=0.0
var ExpandRate=0.0
var ExpandType=0
var EndSize=0.0
var StreakType=0
var StreakScale=20
var StreakOrient=1
var StreakDirection=1
var Blend_mode="Normal"
var TextureName="white.tga"
var TexScroll1="0.0 0.0 0.0"
var TexScrollJitter1="0.0 0.0 0.0"
var AnimFrames1=0
var AnimPace1=1
var AnimType1=0
var TextureName2="0"
var TexScroll2="0.0 0.0 0.0"
var TexScrollJitter2="0.0 0.0 0.0"
var AnimFrames2=0
var AnimPace2=1
var AnimType2=0
var Alpha=255
var FadeInBy=0
var FadeOutStart=0
var FadeOutBy=0
var StartColor="255 255 255"
var ColorChangeType=0
var BeColor1="0 0 0"
var ByTime1=0
var BeColor2="0 0 0"
var ByTime2=0
var BeColor3="0 0 0"
var ByTime3=0
var BeColor4="0 0 0"
var ByTime4=0
var ColorOffset="0 0 0"
var ColorOffsetJitter="0 0 0"
// Get filename of current document
var filepath = UltraEdit.activeDocument.path + "\r\n";
var i = filepath.lastIndexOf("\\");
var ParticleScriptName = filepath.slice(i + 1);
// Get variables from current document
var NewPerFrameSource="NewPerFrame 0.1"
var i = NewPerFrameSource.lastIndexOf(" ");
var NewPerFrame = NewPerFrameSource.slice(i + 1);
//Create a new file, which will become the currently active document
UltraEdit.newFile();
//Write the new Particle Script file
UltraEdit.activeDocument.write("#############################################################\r\n");
UltraEdit.activeDocument.write("## " + ParticleScriptName);
UltraEdit.activeDocument.write("#############################################################\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("System\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("## FLAGS ###########################################################\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("#Flags AlwaysDraw IgnoreFxTint\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("## EMITTER ###########################################################\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("KickStart " + KickStart + "\r\n");
UltraEdit.activeDocument.write("TimeToFull " + TimetoFull + "\r\n");
UltraEdit.activeDocument.write("EmissionLifeSpan " + EmissionLifeSpan + "\r\n");
UltraEdit.activeDocument.write("EmissionLifeSpanJitter " + EmissionLifeSpanJitter + "\r\n");
UltraEdit.activeDocument.write("DieLikeThis " + DieLikeThis + "\r\n");
UltraEdit.activeDocument.write("DeathAgeToZero " + DeathAgeToZero + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("Burst " + Burst + "\r\n");
UltraEdit.activeDocument.write("NewPerFrame " + NewPerFrame + "\r\n");
UltraEdit.activeDocument.write("MoveScale " + MoveScale + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("BurbleAmplitude " + BurbleAmplitude + "\r\n");
UltraEdit.activeDocument.write("BurbleType " + BurbleType + "\r\n");
UltraEdit.activeDocument.write("BurbleThreshold " + BurbleThreshold + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("WorldOrLocalPosition " + WorldOrLocalPosition + "\r\n");
UltraEdit.activeDocument.write("EmissionType " + EmissionType + "\r\n");
UltraEdit.activeDocument.write("EmissionRadius " + EmissionRadius + "\r\n");
UltraEdit.activeDocument.write("EmissionHeight " + EmissionHeight + "\r\n");
UltraEdit.activeDocument.write("EmissionStartJitter " + EmissionStartJitter + "\r\n");
UltraEdit.activeDocument.write("TightenUp " + TightenUp + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("## MOTION ###########################################################\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("InitialVelocity " + InitialVelocity + "\r\n");
UltraEdit.activeDocument.write("InitialVelocityJitter " + InitialVelocityJitter + "\r\n");
UltraEdit.activeDocument.write("VelocityJitter " + VelocityJitter + "\r\n");
UltraEdit.activeDocument.write("Magnetism " + Magnetism + "\r\n");
UltraEdit.activeDocument.write("Gravity " + Gravity + "\r\n");
UltraEdit.activeDocument.write("Drag " + Drag + "\r\n");
UltraEdit.activeDocument.write("Stickiness " + Stickiness + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("## PARTICLE ###########################################################\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("FrontOrLocalFacing " + FrontOrLocalFacing + "\r\n");
UltraEdit.activeDocument.write("SortBias " + SortBias + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("OrientationJitter " + OrientationJitter + "\r\n");
UltraEdit.activeDocument.write("Spin " + Spin + "\r\n");
UltraEdit.activeDocument.write("SpinJitter " + SpinJitter + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("StartSize " + StartSize + "\r\n");
UltraEdit.activeDocument.write("StartSizeJitter " + StartSizeJitter + "\r\n");
UltraEdit.activeDocument.write("ExpandRate " + ExpandRate + "\r\n");
UltraEdit.activeDocument.write("ExpandType " + ExpandType + "\r\n");
UltraEdit.activeDocument.write("EndSize " + EndSize + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("StreakType " + StreakType + "\r\n");
UltraEdit.activeDocument.write("StreakScale " + StreakScale + "\r\n");
UltraEdit.activeDocument.write("StreakOrient " + StreakOrient + "\r\n");
UltraEdit.activeDocument.write("StreakDirection " + StreakDirection + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("## TEXTURE ###########################################################\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("Blend_mode " + Blend_mode + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("TextureName " + TextureName + "\r\n");
UltraEdit.activeDocument.write("TexScroll1 " + TexScroll1 + "\r\n");
UltraEdit.activeDocument.write("TexScrollJitter1 " + TexScrollJitter1 + "\r\n");
UltraEdit.activeDocument.write("AnimFrames1 " + AnimFrames1 + "\r\n");
UltraEdit.activeDocument.write("AnimPace1 " + AnimPace1 + "\r\n");
UltraEdit.activeDocument.write("AnimType1 " + AnimType1 + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("TextureName2 " + TextureName2 + "\r\n");
UltraEdit.activeDocument.write("TexScroll2 " + TexScroll2 + "\r\n");
UltraEdit.activeDocument.write("TexScrollJitter2 " + TexScrollJitter2 + "\r\n");
UltraEdit.activeDocument.write("AnimFrames2 " + AnimFrames2 + "\r\n");
UltraEdit.activeDocument.write("AnimPace2 " + AnimPace2 + "\r\n");
UltraEdit.activeDocument.write("AnimType2 " + AnimType2 + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("## PARTICLE ALPHA ###########################################################\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("Alpha " + Alpha + "\r\n");
UltraEdit.activeDocument.write("FadeInBy " + FadeInBy + "\r\n");
UltraEdit.activeDocument.write("FadeOutStart " + FadeOutStart + "\r\n");
UltraEdit.activeDocument.write("FadeOutBy " + FadeOutBy + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("StartColor " + StartColor + "\r\n");
UltraEdit.activeDocument.write("ColorChangeType " + ColorChangeType + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("BeColor1 " + BeColor1 + "\r\n");
UltraEdit.activeDocument.write("ByTime1 " + ByTime1 + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("BeColor2 " + BeColor2 + "\r\n");
UltraEdit.activeDocument.write("ByTime2 " + ByTime2 + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("BeColor3 " + BeColor3 + "\r\n");
UltraEdit.activeDocument.write("ByTime3 " + ByTime3 + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("BeColor4 " + BeColor4 + "\r\n");
UltraEdit.activeDocument.write("ByTime4 " + ByTime4 + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("ColorOffset " + ColorOffset + "\r\n");
UltraEdit.activeDocument.write("ColorOffsetJitter " + ColorOffsetJitter + "\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("#############################################################\r\n");
UltraEdit.activeDocument.write("\r\n");
UltraEdit.activeDocument.write("End");
Code: Select all
// Get variables from current document
var NewPerFrameSource="NewPerFrame 0.1" //This line is just a placeholder to work on the next two instructions.
var i = NewPerFrameSource.lastIndexOf(" ");
var NewPerFrame = NewPerFrameSource.slice(i + 1);