query if properties value index is valid

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
jdietz
Posts: 5
Joined: September 28th, 2004, 1:42 pm
Location: Chicago
Contact:

Hello,

I was wondering what my best way to check if a property has a valid
value attribute. I'm looping through Effects and properties and when
I come to some of them my script breaks ie:

var assemble = currentLayer("Effects")("Basic Text").fillAndStroke.value;

I get an invalid object error..

where if I querry it with another index ie:

var assemble = currentLayer("Effects")("Basic Text").fillAndStroke.unitsText;

I get my value I'm looking for. Sooo I know it's there and it's valid
so is there a way for me to query before assigning to make sure it's
valid.. also you'll have to excuse my javascript ignorance but is
there a way to handle an exception like a try{}catch{} type system
that could get me where I need to go??

thanks,

jdietz
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You can check for the type of property using .propertyValueType. Here's a script that goes through all layers, listing each effect's properties and propertyValueTypes. The two that you're probably trying to avoid are NO_VALUE and CUSTOM_VALUE. See page 143 of the scripting guide for a full list of propertyValueTypes.

Paul T

Code: Select all

{ 
	// make sure a comp is selected 
	var activeItem = app.project.activeItem; 
	if (activeItem == null || !(activeItem instanceof CompItem)){ 
		alert("You need to select a comp first."); 

	} else { 
		// create loop to check each layer in comp. 
		for (var f = 1; f <= activeItem.numLayers; ++f) { 
			currentLayer = activeItem.layer(f); 
			alert("Searching layer " + f + ": " + currentLayer.name); 

			// search top level properties for "Effects" 
			for (var g = 1; g <= currentLayer.numProperties; ++g) { 
				if (currentLayer.property(g).name == "Effects") { 
					currentEffects = currentLayer.property(g); 

					// check each of the effects 
					for (var h = 1; h <= currentEffects.numProperties; ++h) { 
						thisEffect = currentEffects.property(h); 

						// check each property
						for (var i = 1; i <= thisEffect.numProperties; ++i) {
							thisParam = thisEffect.property(i);

							if (thisParam.propertyValueType == PropertyValueType.NO_VALUE) { valueType = "NO_VALUE"; }
							if (thisParam.propertyValueType == PropertyValueType.TwoD_SPATIAL) { valueType = "TwoD_SPATIAL"; }
							if (thisParam.propertyValueType == PropertyValueType.TwoD) { valueType = "TwoD"; }
							if (thisParam.propertyValueType == PropertyValueType.OneD) { valueType = "OneD"; }
							if (thisParam.propertyValueType == PropertyValueType.COLOR) { valueType = "COLOR"; }
							if (thisParam.propertyValueType == PropertyValueType.CUSTOM_VALUE) { valueType = "CUSTOM_VALUE"; }

							alert(thisEffect.name + "  " + thisParam.name + "  " + valueType)

						} 
					} 
				} 
			} 
		} 
	} 
}
Post Reply