Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Thousands of paths take a huge time to treat !

New Here ,
Jan 05, 2009 Jan 05, 2009
Hello,

I tried this wonderfull way of scripting called ExtendScript by using an autocad file. I counted 220 000 paths. I wanted to try a small script to change the width of some paths, but this little script :

var doc = app.activeDocument;
var lengthPI = doc.pathItems.length;
for (var i = 0; i < lengthPI ; i++ ) {

   if( doc.pathItems.editable ) {}
//add this line in order to see the speed of this script
if ( i % 100 == 0) $.writeln( i );
}

takes a very very very long time. It takes almost 1 minute for 1000 paths.
If I delete some paths, I can manage to have 30000 paths. The script becomes much faster, but it takes about 15s for 1000 paths, which is still very slow.

On the other hand, if I select a path, and make a selection with Selection > Same > Stroke weight, and treat it as a script, it can select 100 000 paths in 1s.

So my question is : how can I write the same script with ExtendScript to make it work in 1s ?

Thank you very much !
TOPICS
Scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jan 05, 2009 Jan 05, 2009
Your method is measuring how much time it takes your script to run is very strange and is probably making your script run much slower.
If you want a real measurement, use JavaScript's Time object. Make one reading in the begining and one at the end of the script, and then deduce the former from the latter. That way you will have the real run-time of your script.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 05, 2009 Jan 05, 2009
Yes I know, but I didn't think there was a time function implemented for illustrator, even though I knew there was one in Javascript.

By the way, thanks to your reply, I found it, and now, I can give you some more precise results :
If I have 220 000 paths, the function takes 38s every 1000 paths.
For 100 000 paths, it takes 22s every 1000 paths.
For 30 000 paths, it takes 7s every 1000 paths.
And I have a powerfull computer.

So how can I optimize this function to have the same results than the scripts in Illustrator ? And why is the speed increasing with the number of paths ?

Thanks !
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2009 Jan 05, 2009
When there are more paths, the file is probably larger and requires more CPU power and memory to process, which means it will take more time.
You say you have a powerful computer. How powerful? Give us some details. Also, you crucially failed to mention which version of Illustrator you are using. All of these data are very important when analyzing such an issue.

Also, Could you please post your entire script?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 05, 2009 Jan 05, 2009
Alesclandre,

I'm not saying your script can't be optimized for better speed; but you are aware, aren't you, that Javascript is a scripting language? As I understand it, it's a general principle that scripts don't run as fast as actual compiled programs would.

JET
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 05, 2009 Jan 05, 2009
Thanks for your replies !
Yes I know that a script can't be as fast as a compiled program, but I was wondering which kind of script were used inside Illustrator (the scripts in Window > script). Maybe it is in Javascript. Maybe it is a kind of XML used to point the compiled functions of Illustrator. If you have an answer it would be great. If you tell me that I will never manage to treat 200000 in less than 10s, that's ok. Just need to know...

And to answer try67 : I'm using Illustrator CS3, I have a Mac Pro 2x2,8 GHz Quad Core with 6M RAM, under Mac Os 10.5.6.

And here is the entire script (it doesn't do anything, it is just to see how fast it is) :

var doc = app.activeDocument;
var lengthPI = doc.pathItems.length;
var date = new Date();
var start = date.getTime();

for (var i = 0; i < lengthPI ; i++ ) {

pathRef = doc.pathItems;
if( pathRef.editable ) {}

if ( i % 1000 == 0) {

var date2 = new Date();
var stop = date2.getTime() - start;
$.writeln( "for 1000 path : "+ stop+" ms");
date = new Date();
start = date.getTime();
}

}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2009 Jan 05, 2009
You're overloading your script with unnecessary checks and commands.
Try this:

var doc = app.activeDocument;
var lengthPI = doc.pathItems.length;
var date = new Date();
var start = date.getTime();

for (var i = 0; i < lengthPI ; i++ ) {
pathRef = doc.pathItems;
if( pathRef.editable ) {

// Do what you want to do

}
}

var date = new Date();
var finish = date.getTime();
alert("For " + lengthPI + " paths, it took " + (finish-start)/1000 + " seconds");
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 05, 2009 Jan 05, 2009
Thanks, but I think you didn't get it : lengthPI = 200 000, which is the number of paths.
What I want to show here is the speed. With your method, I'll have to wait for the end of the 200 000 paths, which will be, with the speed I found, about 38s * 200000/1000 = 2 hours !
That's exactly what I want to avoid : wait for 2 hours everytime I want to change some paths.
So if you have an idea...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2009 Jan 05, 2009
Then I really don't get it. Your script does, at the moment, nothing.
All it does is scans all the paths and reports how much time it took to do so. What is it you want to achieve here?

A large file will take a long time to scan. There's nothing you can do to avoid it except for writing a more efficient scanning method using a plug-in, perhaps.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009
Yes, the script does absolutely nothing. But for the simplest condition I can write, it takes hours to do it. So if this simple condition takes hours, I won't try more complicated functions...

So this is it : how can I write a more efficient scanning ? A script inside illustrator is way faster than ExtendScript. So, as you said it, maybe the solution is a plug-in ? How can I do that ?
Thanks !
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2009 Jan 06, 2009
How do you mean "A script inside illustrator is way faster than ExtendScript"? Are you talking about a script placed in the Scripts folder of Illustrator? If that is much faster, then why not use it?

As for a plugin, you need to look for the Illustration SDK. There's also a separate forum here about this sort of development.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 06, 2009 Jan 06, 2009
Alesclandre,

Where do you get the notion that functions selectable in the UI are merely high level scripts, and not compiled code?

JET
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009
Actually, I don't really know. I guess this is the case because it is much faster.

To be more precise about what I want to do, I have this autocad file. When I open it in illustrator, the paths are very thin (some are 0.001 cm). So what I wanted to do is to force all the paths that were thinner than 0.25 to 0.25.
I think I can't do it inside Illustrator. But maybe I'm wrong ?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2009 Jan 06, 2009
Of course it's much faster. It's written in the native language used to create Illustrator itself, not in an external scripting language.

However, what you want to do is probably possible. It might take a long time, but that doesn't mean it's not possible...

Also, you can have the script do only a part of the paths each time, to conserve memory. Let's say you have 10,000 paths. Run it once on paths 0-1000, save the file, close Illustrator, and then re-open the file, run the script on paths 1001-2000, etc.
It might actually work faster than running the script on all paths in one go, and has less chance of crashing in the middle.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009
Alesclandre, i think it will be much more efficiently to make a script
in AutoCad, because, maybe, 220 000 paths in file is not very "heavy" for AutoCad engine.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009
try67 > The problem is that even if I hide some path or if I lock some path, I cannot improve the speed. One of the weird things, is that the speed (and not the time used to complete the whole document) depends on the total number of paths, even if there are hidden or locked ones...
So your trick prevents me from crashing, but is not really a time saver, which is what I need (for other documents, for example).

borisboev > Maybe you're right. The problem is that I don't have Autocad. Only the dwg file.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2009 Jan 06, 2009
I didn't suggest you hide or lock any of the paths, but that you changed the upper-limit of the FOR loop, from this:

for (var i = 0; i < lengthPI ; i++ ) { ...

To something like this:

for (var i = 0; i < 10000; i++ ) { ...

And then again to:

for (var i = 10001; i < 20000 ; i++ ) { ...

etc.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 06, 2009 Jan 06, 2009
> So what I wanted to do is to force all the paths that were thinner than 0.25 to 0.25. I think I can't do it inside Illustrator. But maybe I'm wrong ?

1. Line Tool: Draw a line. Give it a stroke of .01 pt.
2. Magic Wand Palette: Set Stroke Weight Tolerance to ".24 pt"
3. Magic Wand Tool: Click the line you drew in step 1.

Paths with stroke weight of .25 pt or less should be selected.

JET
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009
Yeah, that's it ! Thank you very much !

Ok, so I give up with the scripts... But it is a pity these scripts don't work for thousands of paths. I could have done a lot of things with them !
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 07, 2009 Jan 07, 2009
LATEST
Alesclandre,

I do stuff from CAD to Illustrator all the time. One thing I've found to get around having to add weight to all your lines is to print a pdf from AutoCAD with the correct pen table used. Then open that in Illustrator. All of your lines are already at the proper weight and you will have to do nothing at all. Try it, it seems much faster than restroking all the paths.

Stan
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines