// Test script to verify shape layer creation fix
// This tests the specific parameters that were causing errors
// Test Case 1: Star with scale [0, 0]
var test1 = {
compId: 1,
name: "Icon Lightning",
shapeType: "star",
properties: {
fillColor: [1, 0.92, 0.23],
innerRadius: 15,
outerRadius: 40,
points: 4,
position: [960, 800],
scale: [0, 0], // This was causing the error
opacity: 100
}
};
// Test Case 2: Star without scale property
var test2 = {
compId: 1,
name: "Icon Lightning",
shapeType: "star",
properties: {
fillColor: [1, 0.92, 0.23],
innerRadius: 15,
outerRadius: 40,
points: 4,
position: [960, 800]
}
};
// Generated script for test case 1
var script1 = 'var comp = app.project.itemByID(1);\n' +
'if (!comp || !(comp instanceof CompItem)) {\n' +
' throw new Error("Composition not found");\n' +
'}\n\n' +
'var layer = comp.layers.addShape();\n' +
'layer.name = "Icon Lightning";\n' +
'\n' +
'// Parse properties\n' +
'var props = {"fillColor":[1,0.92,0.23],"innerRadius":15,"outerRadius":40,"points":4,"position":[960,800],"scale":[0,0],"opacity":100};\n' +
'var shapeType = "star";\n\n' +
'// Add shape content - create a shape group for better control\n' +
'var contents = layer.property("ADBE Root Vectors Group");\n' +
'var shapeGroup = contents.addProperty("ADBE Vector Group");\n' +
'shapeGroup.name = "Shape 1";\n\n' +
'// Get the vectors group within the shape group\n' +
'var vectors = shapeGroup.property("ADBE Vectors Group");\n\n' +
'// Add the shape path based on type\n' +
'var shapePath;\n' +
'shapePath = vectors.addProperty("ADBE Vector Shape - Star");\n' +
' \n' +
'// Set properties in specific order to avoid hidden property issues\n' +
'try {\n' +
' // First set the points - this is usually safe\n' +
' shapePath.property("ADBE Vector Star Points").setValue(4);\n' +
' \n' +
' // Then set the outer radius\n' +
' shapePath.property("ADBE Vector Star Outer Radius").setValue(40);\n' +
' \n' +
' // Set the type (polygon vs star) - do this AFTER setting basic properties\n' +
' shapePath.property("ADBE Vector Star Type").setValue(2); // 2 = star\n' +
' // Only set inner radius for actual stars\n' +
' shapePath.property("ADBE Vector Star Inner Radius").setValue(15);\n' +
'} catch (e) {\n' +
' // If any property fails, continue with defaults\n' +
' // The shape is still created\n' +
'}\n\n' +
'// Add fill to make the shape visible - add to vectors group\n' +
'var fill = vectors.addProperty("ADBE Vector Graphic - Fill");\n' +
'fill.property("ADBE Vector Fill Color").setValue([1,0.92,0.23]);\n\n' +
'// Set transform properties through Transform group for better compatibility\n' +
'try {\n' +
' var transform = layer.property("ADBE Transform Group");\n' +
' if (!transform) {\n' +
' throw new Error("Could not access transform group");\n' +
' }\n\n' +
' // Set position with validation\n' +
' var position = [960,800];\n' +
' var positionProp = transform.property("ADBE Position");\n' +
' if (positionProp && positionProp.canSetValue) {\n' +
' positionProp.setValue(position);\n' +
' }\n\n' +
' // Set scale - avoid zero scale which can cause issues\n' +
' var scaleProp = transform.property("ADBE Scale");\n' +
' if (scaleProp && scaleProp.canSetValue) {\n' +
' var scaleValue = [0,0];\n' +
' // Ensure scale is not exactly zero to avoid property access issues\n' +
' if (scaleValue[0] === 0 && scaleValue[1] === 0) {\n' +
' scaleValue = [0.01, 0.01];\n' +
' }\n' +
' scaleProp.setValue(scaleValue);\n' +
' }\n\n' +
' // Set opacity with validation\n' +
' var opacityProp = transform.property("ADBE Opacity");\n' +
' if (opacityProp && opacityProp.canSetValue) {\n' +
' opacityProp.setValue(100);\n' +
' }\n' +
'} catch (e) {\n' +
' // If transform properties fail, layer is still created with defaults\n' +
' // This prevents the entire operation from failing\n' +
'}\n\n' +
'"Shape layer created successfully";';
// This script can be run in After Effects to test the fix
alert("Test script generated. Copy the script1 variable content to test in After Effects.");