Script Error(s)

What type of scripts do you need?

Moderator: byronnash

Post Reply
jsphar
Posts: 3
Joined: April 4th, 2006, 6:52 am
Location: Waco, TX

I am a new poster and a beginner at scripting. Last week there was a post on the AE List mentioning a French site called nabscripts.com.

On that site was a script that created triangles and Carpet of Sierpinsky triangles. I wanted very much to try the script, but the downloaded script file had numerous word wrap and (apparently) nesting errors.

I've fiddled with the following function for several hours, and can't get the AE ExtendScipt window to run it. I think it has to do with the if...else statements, and I know that the brackets must match. But I can't find any help in the AE javascript debugger or the scripting guide of how to identify the error(s).

Any help getting the following function to work properly would be very much appreciated. Any suggestions for learning how to debug would also be welcome.

---------------
Code
---------------
function Triangle()
{app.beginUndoGroup("SierpinskyTriangle.jsx");
if(!app.project)
alert("Vous must initially open a project and select a copy"); }
else
{var myComp = app.project.activeItem; yew (myComp == null ||!(myComp instanceof CompItem))
alert("Vous must select a copy");
else
{yew (myComp.selectedLayers.length! = 1),
alert ("Vous must select one and only one copy.");
else
{yew (MaxIterationsEdit.text == ""),
alert("Vous must initially specify the iteration count.") }
else
{var myLayer = myComp.selectedLayers[0 ];
var W = myLayer.width;
var H = myLayer.height;
var D = 10;
//borders in px
var A = [ W/2, D ];
var B = [ D, H-d ];
var C = [ W-d, H-d ];
SierpinskyTriangle(myLayer, A, B, C);
}}}}
app.endUndoGroup(); }
----------
End code
----------

Thanks,

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

I can't guarantee it'll work, but give this a try:

Code: Select all

function Triangle() 
{
	app.beginUndoGroup("SierpinskyTriangle.jsx"); 

	if(!app.project) 
		alert("You must initially open a project and select a copy");
	else 
	{
		var myComp = app.project.activeItem; 
		if (myComp == null ||!(myComp instanceof CompItem)) 
			alert("You must select a copy"); 
		else 
		{
			if (myComp.selectedLayers.length != 1)
				alert ("You must select one and only one copy."); 
			else 
			{
				if (MaxIterationsEdit.text == "")
					alert("You must initially specify the iteration count.");
				else 
				{
					var myLayer = myComp.selectedLayers[0]; 
					var W = myLayer.width; 
					var H = myLayer.height; 
					var D = 10; 

					//borders in px 
					var A = [ W/2, D ]; 
					var B = [ D, H-d ]; 
					var C = [ W-d, H-d ]; 
					SierpinskyTriangle(myLayer, A, B, C); 
				}
			}
		}
	} 
	app.endUndoGroup(); 
} 
jsphar
Posts: 3
Joined: April 4th, 2006, 6:52 am
Location: Waco, TX

Paul,

Thank you very much for looking at this. I see now that it's the else statements that are bracketed, and I presume that is because the elses are nested. I also see how you matched the levels of indent. That makes it clear.

The AE ExtendScipt window was just stopping at the first else. So I wasn't able to figure out the error.

Now to debugging the other functions.....

Thanks again,

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

You can get away without brackets if there is just a single line of code following it, otherwise you need them. It just happens to be all the else's that have more than one line in this case.
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

Hello,
the problem you encoutered has probably occured in your copy/paste operation from your translater (google for example) to your jsx file.
I've tried the script on the EN version and it seems to work as it it works on the french version.
One other reason could be the format of the script. When a script uses french specific symbols (such as accents), the script must be saved with the UTF-8 code.
It's one of my "work in progress" manipulating masks and it's still experimental ...
I've not posted this script on my download page but you can find it on the "repaire.net" french forum
http://www.repaire.net/forums/adobe-aft ... ctals.html
I'm using AE 6.5 and i didn't try it on 7.0...
Last edited by nab on April 7th, 2006, 9:03 pm, edited 1 time in total.
jsphar
Posts: 3
Joined: April 4th, 2006, 6:52 am
Location: Waco, TX

Hello nab,

It must have been a pasting error, because I returned to the repaire forum and downloaded the .jsx script again, and now it is working.

Today, I've been able to make a Sierpinsky carpet and a fern, which are beautiful. I do have some questions, if you have time to answer:

1) The ferns with the nicest shapes seem to have 500 or more layers. What would be the easiest way to apply effects to the fern points? It is not easy to work with 500 mask shapes.

2)Do you maintain a web site where you post examples of your scripts work or post to any English language sites? I am having some difficulty getting a full translation of the thread in the repaire forum, even after trying some of the French>English web translators?

Thank you for your courtesy in responding and for these beautiful scripts.

--Jim Sphar
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

Hi Jim,

if I find enough time, I'll probably translate my website...but I have tons of things to do before that :oops:

In the script you experiment (about the fern) the masks are 1-pixel horizontal segments (formed by two points). You can use for example the Stroke effect to 'reveal' all the shapes.
In some other related scripts, I've choosen different representation such as a simple 1-pixel square and added a parameter on the palette to adjust the maskFeather property. In that way you can obtain "real dots" without any additional effects since your masks are closed and then visible on the layer.
Post Reply