943,616 Members | Top Members by Rank

Ad:
Jul 29th, 2006
0

Photoshop - javascript slice : error : copy command not available??

Expand Post »
Hi,

Good Morning.

I wanted to slice one image to tiles and i got a script for it. I did not had a photoshop so I got Photoshop CS2 Version 9.0. This script was working fine but it says error over a copy command.

    // We make sure our source image is the active document
    var srcDoc = activeDocument;
              
    //Select Area and Copy
    srcDoc.selection.select(Array (Array(MyXO, MyYO), Array(MyXL, MyYO), Array(MyXL, MyYL), Array(MyXO, MyYL)), SelectionType.REPLACE, 0, false);    
     srcDoc.selection.copy();
            
     //Paste to new Doc
     var pasteDoc = documents.add(PixelWidth, PixelHeight, srcDoc.resolution, "Paste Target");
     pasteDoc.paste();
     pasteDoc = null;

    //Save New Doc
    var saveMe = activeDocument;

The error shown is

Error 8800: General Photoshop error occurred.The command copy is not currently available.LIne 69 -> srcDoc.Selection.Copy();

What is the replacment command that i could use for it or what is the command that i could use over any versions....

I could not find the Scripts menu option below automate where i could browse to this script and get the slicing in version 7. I could gind the scripts option ibelow Automate in files menu in Version 9 though but this says this error.

I hope here to have photoshop experts who could help me out.

regards

Harish

Observation: before showing the above pop-up error -> it makes the first 7 slice as set in the variables.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. /*********
  2. //**** YOU SHOULD CUSTOMIZE THE FOLLOWING VARIABLE DEPENDING ON YOUR NEED ****
  3. var ZoomLevel = 2;
  4.  
  5. var FolderPath = "/Documents and Settings/harish/Desktop/images/Zoom"+ZoomLevel+"slices/";
  6.  
  7. // We start with the coordinates, zoom, and width of an upper left corner tile and generate everything from there
  8. // We can calculate new tile values from these values for any zoom level without having to look up these details for each.
  9. var OrgX = 1204; //<-- the X value
  10. var OrgY = 1536; //<-- the Y value
  11. var OrgZoomLevel = 5; //<-- the zoom level
  12. var OrgTileWidth = 7; //<-- the number of tiles wide your full map area is
  13. var OrgTileHeight = 7; //<-- the number of tiles high your full map area is
  14.  
  15.  
  16. //**** EVERYTHING BEYOND HERE SHOULD NOT BE TOUCHED UNLESS YOU KNOW WHAT YOU ARE DOING!!!
  17.  
  18. // Exponent Function
  19. // we will need this later
  20. function PowMe(a, b){
  21.   var o = a;
  22.   for (n=1; n<b; n++){ o *= a; }
  23.   if (b==0){ o = 1; }
  24.   return o;
  25. };
  26.  
  27. var StartX = OrgX*PowMe(2,(OrgZoomLevel - ZoomLevel));
  28. var StartY = OrgY*PowMe(2,(OrgZoomLevel - ZoomLevel));
  29. var xTiles = OrgTileWidth*PowMe(2,(OrgZoomLevel - ZoomLevel));
  30. var yTiles = OrgTileHeight*PowMe(2,(OrgZoomLevel - ZoomLevel));
  31.  
  32. var PixelWidth = 256;
  33. var PixelHeight = 256;
  34.  
  35. var TotalTiles = xTiles * yTiles;
  36.  
  37.  
  38. preferences.rulerUnits = Units.PIXELS;
  39.  
  40.  
  41. var xm = 0;
  42. var ym = 0;
  43.  
  44. var TileX = StartX;
  45. var TileY = StartY;
  46.  
  47.  
  48.  
  49. for (n=1; n<TotalTiles+1; n++) {
  50.  
  51.   if (ym == yTiles){
  52.   xm += 1; //<-- Up the x value by 1, i.e. we move over to the next column
  53.   ym = 0; //<-- Reset the y value to 0 so we start back at the top of our new column
  54.   TileX += 1; //<-- Increase our Google X value for our file name
  55.   TileY = StartY; //We reset out Google Y value for out file name everytime we change columns
  56.   };
  57.  
  58.  
  59.   MyXO = xm*(PixelWidth);
  60.   MyXL = xm*(PixelWidth)+(PixelWidth);
  61.   MyYO = ym*(PixelHeight);
  62.   MyYL = ym*(PixelHeight)+(PixelHeight);
  63.  
  64.   // We make sure our source image is the active document
  65.   var srcDoc = activeDocument;
  66.  
  67.   //Select Area and Copy
  68.   srcDoc.selection.select(Array (Array(MyXO, MyYO), Array(MyXL, MyYO), Array(MyXL, MyYL), Array(MyXO, MyYL)), SelectionType.REPLACE, 0, false);
  69.   srcDoc.selection.copy();
  70.  
  71.   //Paste to new Doc
  72.   var pasteDoc = documents.add(PixelWidth, PixelHeight, srcDoc.resolution, "Paste Target");
  73.   pasteDoc.paste();
  74.   pasteDoc = null;
  75.  
  76.   //Save New Doc
  77.   var saveMe = activeDocument;
  78.  
  79.   //Flatten
  80.   saveMe.flatten();
  81.  
  82.   //Set path to file and file name
  83.   saveFile = new File(FolderPath + TileX+ "_" + TileY+ "_" + ZoomLevel + ".gif");
  84.   //Set save options
  85.   gifSaveOptions = new GIFSaveOptions();
  86.   gifSaveOptions.colors = 64;
  87.   gifSaveOptions.dither = Dither.NONE;
  88.   gifSaveOptions.matte = MatteType.NONE;
  89.   gifSaveOptions.preserveExactColors = 0;
  90.   gifSaveOptions.transparency = 0;
  91.   gifSaveOptions.interlaced = 0;
  92.  
  93.   //Save the file and close it
  94.   saveMe.saveAs(saveFile, gifSaveOptions, true,Extension.LOWERCASE);
  95.   saveMe.close(SaveOptions.DONOTSAVECHANGES);
  96.  
  97.   //Advance Y counter for next image
  98.   ym += 1;
  99.  
  100.   //Advance Google Y value for next image name
  101.   TileY += 1;
  102.  
  103. }
  104. /*****************
  105.  
Last edited by tgreer; Aug 20th, 2006 at 11:37 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
hbmarar is offline Offline
187 posts
since Apr 2005
Jul 29th, 2006
0

Re: Photoshop - javascript slice : error : copy command not available??

wouldn't be easier to use ImageReady which you have with your copy of Photoshop and manually slice image then use dodgy script?
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,653 posts
since Dec 2004
Jul 30th, 2006
0

Re: Photoshop - javascript slice : error : copy command not available??

Quote originally posted by peter_budo ...
wouldn't be easier to use ImageReady which you have with your copy of Photoshop and manually slice image then use dodgy script?
Thanks for reply. but i can't do so for the slice would be some 840 of an image and likewise i have some 28 images to do. Another concern is that the slices are called by a functional calcualtion by application and each sliced needs to be saved with x_y_value.gif... Here a layer would be having x changing values incrementally by one and each vertical layer changing y value incremented by 1.

I dont believe anyone would still approve that this could be manuaaly done for nearly 840*28 slices. Nearly impossible and this script slices and saves it in the name format also.

I would like to know would the trial versions have restriction of some commands for JSX or JS scripts. I am using the trial version and it says that copy() command is not available.

Observation : My client was able to do it using his photoshop with the same script and he before moving for vacation did one image slice for me.

Scripts works fine if i comment the line srcDoc.selection.copy(); with one image slice getting saved and goes on saving the same image.

Hope somebody would let me know what is wrong with PS CS2 version trial with copy() command or alternate command that i could use.

With regards

Harish

.
Last edited by tgreer; Aug 20th, 2006 at 11:38 am.
Reputation Points: 10
Solved Threads: 0
Junior Poster
hbmarar is offline Offline
187 posts
since Apr 2005
Jul 30th, 2006
0

Re: Photoshop - javascript slice : error : copy command not available??

didn't know that you want to slice so many images. I see only two options then, 1st to try get in touch with person who came up with this script and ask him directly or 2nd try to find forum which is more related to photoshop. I'm not saying that daniweb hasn't got one but it is rarely used and often i'm answering questions over there
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,653 posts
since Dec 2004
Aug 19th, 2006
0

Re: Photoshop - javascript slice : error : copy command not available??

Hi,

the reason was the i have to make the multiples of the slices width as total width and height. Script worked fine and sorry in replying late here.

If anyone wants any help on this or clarification just send me a email to marar.harish@gmail.com

With regards

Harish
Reputation Points: 10
Solved Threads: 0
Junior Poster
hbmarar is offline Offline
187 posts
since Apr 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Switching visible divs works in IE, not in FF or Opera
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: 2 duplicate javascriptsscripts on 1 webpage?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC