Help exporting mask vertices

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
tpolson
Posts: 1
Joined: December 28th, 2008, 8:20 pm

i've created a script that exports a layer with a mask to a script file that can then re-import it back into a project. it works fine except the vertices interpolation is not translated. is there a way to set the whether a mask vertex is continuous bezier or corner bezier?
User avatar
mmohl
Posts: 20
Joined: November 24th, 2008, 10:40 am
Contact:

Are you talking
(a) about the spacial interpolation between the points of the mask or
(b) about the temporal interpolation between keyframes?

for (a) I think all information you have are the inTangents and outTangents of the shape object. If a vertex, its inTangent and its outTangent are located on one straight line in space, there is no corner. But this should not bother you, if you just export those values and restore them 1:1 in the new project. If your current script ignores inTangents and outTangents, AE probably generates rotoBezier-Masks; maybe that's your problem?

for (b) you should look at the documentation of the property-object (methods with the "key"-prefix)
pichu
Posts: 2
Joined: January 8th, 2009, 5:54 am

I actually wrote a sniplet that allows to get all the keys properties (including interpolation types, etc) to a JavaScript Object Notation (JSON). Please read through. the try..catch have to be used because some of them just threw exceptions instead. Weird, huh?

Code: Select all

	/**
	 * get all of the keys in a property, and store as a variable (this.keys)
	 */
	this.getKeys = function( )
	{
		var property = this.property ;
		var keys = [ ] ;
		var i , k ;
		for ( i = 0 ; i < this.property.numKeys ; i ++ )
		{
			k = i + 1 ;
			keys[ i ] = 
			{
				  key : k
				, value :  property.keyValue( k )
				, time : property.keyTime( k )
				, interpolationType : [ property.keyInInterpolationType( k ) , property.keyOutInterpolationType( k ) ]
//				, spatialTangents : [ property.keyInSpatialTangent( k ) , property.keyOutSpatialTangent( k ) ]
				, temoralEase : [ property.keyInTemporalEase( k ) , property.keyOutTemporalEase( k ) ]
				, temporalContinuous : property.keyTemporalContinuous( k )
				, temporalAutoBezier : property.keyTemporalAutoBezier( k )
//				, roving : property.keyRoving( k )
				, selected : property.keySelected( k )
			} ;
			try{ keys[i]['spatialTangents'] = [ property.keyInSpatialTangent( k ) , property.keyOutSpatialTangent( k ) ] ; } catch( err ) { }
			try{ keys[i]['roving'] = property.keyRoving( k ) ; } catch( err ) { }
		}
		this.keys = keys ;
		this.settings =
		{
			  propertyValueType : 'propertyValueType'
			, hasMin : 'hasMin'
			, hasMax : 'hasMax'
			, minValue : 'minValue'
			, maxValue : 'maxValue'
			, isSpatial : 'isSpatial'
			, canVaryOverTime : 'canVaryOverTime'
			, isTimeVarying : 'isTimeVarying'
			, unitsText : 'unitsTime'
			, expressionEnabled : 'expressionEnabled'
			, expression : 'expression'
			, canSetExpression : 'canSetExpression'
			, expressionError : 'expressionError'
			, keyframeInterpolationType : 'keyframeInterpolationType'
		} ;
		for ( i in this.settings )
		{
			try { this.settings[i] = property[this.settings[i]] ; } catch(err) { this.settings[i] = undefined ;}
		}
		return this ;
	}
I wrote another function to do setKeys, but it has a different purpose than what you need, so it's done a bit differently and a bit more complicated, but just reverse this function and you can get what you need perfectly. :)

Edit: setKey is as follows:

Code: Select all

	/**
	 * @function setKey -- set a single key
	 * @param newKey (object) -- current, new key to be set
	 * @param keyIndex -- the current key index on newKey
	 * @param names -- names -- an array of the name list; undefined to use all.
	 */
	this.setKey = function( newKey , keyIndex , names )
	{
		var i , method , name ;
		var index = null ;
		if ( names == undefined )
		{
			names =
			[	  "value"
					, "interpolationType"
					, "spatialTangents"
					, "temporalEase"
					, "temporalContinuous"
					, "spatialContinuous"
					, "roving"
					, "selected"
					, "temporalAutoBezier"
					, "spatialAutoBezier" ] ;
		}
		if ( newKey.time != undefined )
		{
			index = this.property.addKey( newKey.time ) ;
		}
		for ( i = 0 ; i < names.length ; i ++ )
		{
			name = names[i] ;
			method = "set" + name[0].toUpperCase( ) + name.substring( 1 ) + "AtKey" ;
			a = newKey[name] == undefined ? this.keys[keyIndex-1][name] : newKey[name] ;
			if ( a == undefined ) { continue ; }
			if ( ( name != 'value' ) && ( a instanceof Array ) )
			{
				try{ this.property[method]( index != null ? index : keyIndex , a[0] , a[1] ) } catch( err ) { }
			}
			else
			{
				this.property[method]( index != null ? index : keyIndex , a ) ;
//				try{ this.property[method]( index != null ? index : keyIndex , a ) ; } catch( err ) { throw( "Error: " + method ) }
			}
		}
		return this ;
	}
	
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

So how would I use your getKeys function in a script?

Say I have a layer object called "layer" and it has a mask on it.

I want to call your function to get the mask shape information.

What would the code look like?
"Up And Atom

No...No

Up And At Them!"
Post Reply