2 Replies Latest reply: Sep 26, 2013 3:48 PM by Another Andrew RSS

    How to Place an image onto a document?

    Another Andrew Community Member

      I've been trying to build a plugin for placing images onto Photoshop document using a Mac that is based on the current "Dissolve" project provided in the CC SDK.


      I'm at the stage of trying to place an image on a document. To figure out the code for this I've built the Listener plugin and ran through the steps of using Photoshop's "File:Place..." menu item to place an image (I've so far tried gifs and EPSes) onto a document. I then looked at the code generated and tried to build a function to do what I wanted from that.


      However, when I try to run it I hit the following error message: "Could not complete the Dissolve command because of a program error."


      I'll append the current form of my code to the end to avoid cluttering my comments.


      If I comment out the line with "sPSActionControl->Play(" then the error goes away. (Of course nothing then happens.)


      Some notes:


      1) I didn't retain the exact layout of the output of the Listener plugin. The compiler complained about the goto methods that Listener added.


      2) I'm running this in a objective-C++ class (that's triggered through a file with a .mm postfix).


      3) There's NSLog statements to help me figure out the problem. I see number 7 but I never see the final error code. Looks like an exception.


      4) I've retained older code that I tried, by commenting it out, so you'll see some of my thinking as I struggled with this.


      Any ideas or suggestions?





      - (SPErr)photoshopPlayeventPlace:(char *)cPath


      NSLog(@"photoshopPlayeventPlace %d", 0, NULL);


      PIActionDescriptor result = NULL;


      // PIActionDescriptor desc0x100 = NULL;

      // PIActionDescriptor desc0x108 = NULL;


      Auto_Desc descriptor;

      Auto_Desc offsetDetails;


      SPErr error = kSPNoError;


      Handle aliasValue = NULL;

      FullPathToAlias(cPath, aliasValue);




      // error = sPSActionDescriptor->Make(&desc0x100);

      // if (error) break;


      NSLog(@"photoshopPlayeventPlace %d", 1, NULL);


      // error = sPSActionDescriptor->PutAlias(desc0x100, keyNull, aliasValue);

      error = sPSActionDescriptor->PutAlias(descriptor.get(), keyNull, aliasValue);

      if (error) break;


      NSLog(@"photoshopPlayeventPlace %d", 2, NULL);


      // error = sPSActionDescriptor->PutEnumerated(desc0x100, keyFreeTransformCenterState, typeQuadCenterState, enumQCSAverage);

      error = sPSActionDescriptor->PutEnumerated(descriptor.get(), keyFreeTransformCenterState, typeQuadCenterState, enumQCSAverage);

      if (error) break;


      NSLog(@"photoshopPlayeventPlace %d", 3, NULL);


      // error = sPSActionDescriptor->Make(&desc0x108);

      // if (error) break;


      NSLog(@"photoshopPlayeventPlace %d", 4, NULL);


      // error = sPSActionDescriptor->PutUnitFloat(desc0x108, keyHorizontal, unitDistance, 0);

      error = sPSActionDescriptor->PutUnitFloat(offsetDetails.get(), keyHorizontal, unitDistance, 0);

      if (error) break;


      NSLog(@"photoshopPlayeventPlace %d", 5, NULL);


      // error = sPSActionDescriptor->PutUnitFloat(desc0x108, keyVertical, unitDistance, 0);

      error = sPSActionDescriptor->PutUnitFloat(offsetDetails.get(), keyVertical, unitDistance, 0);

      if (error) break;


      NSLog(@"photoshopPlayeventPlace %d", 6, NULL);


      // error = sPSActionDescriptor->PutObject(desc0x100, keyOffset, classOffset, desc0x108);

      error = sPSActionDescriptor->PutObject(descriptor.get(), keyOffset, classOffset, offsetDetails.get());

      if (error) break;


      NSLog(@"photoshopPlayeventPlace %d", 7, NULL);


      // error = sPSActionControl->Play(&result, eventPlace, desc0x100, plugInDialogSilent);

      error = sPSActionControl->Play(&result, eventPlace, descriptor.get(), plugInDialogSilent);

      if (error) break;


      NSLog(@"photoshopPlayeventPlace %d", 8, NULL);


      while (false);


      if (result != NULL) sPSActionDescriptor->Free(result);

      // if (desc0x100 != NULL) sPSActionDescriptor->Free(desc0x100);

      if (aliasValue != NULL) sPSHandle->Dispose(aliasValue);

      // if (desc0x108 != NULL) sPSActionDescriptor->Free(desc0x108);


      NSLog(@"photoshopPlayeventPlace error:%d", error, NULL);


      return error;