7 Replies Latest reply on Jun 14, 2016 4:33 AM by ralphmce

    GoFileformat Linked Art

    ralphmce Level 1

      Hoping someone can help. I am trying to create a file format plugin that loads a custom file type, but the file must remain linked and not embedded.

       

      Firstly we tried creating a raster art item :

      error = sAIArt->NewArt(kRasterArt, kPlaceAboveAll, nullptr, &art);

      ...

      error = sAIRaster->SetRasterInfo(art, &info);

      .... fill AITile with the data....

      error = sAIRaster->SetRasterTile(art, &artSlice, &dstTile, &dstSlice);

      ....Now the important part, set it as linked.

      error = sAIRaster->SetRasterLink(art, link);

       

      This worked fine, near perfect in fact, but we kept getting a dialog ever 15 or so seconds :

      Message.png

      No matter how often you hit no or yes it keeps coming back. There is no message being sent to the plugin about this, so we are not missing an event response.

      After some digging we found this thread :

       

      'Problem Programmatically Placing Images with Placed or Raster Suites'

      https://forums.adobe.com/message/1264484#1264484

       

      So we tried following that system, after all SetRasterLink is deprecated, so we wanted to avoid using it  :

      First we send the place request when we receive the  kFileFormatImportArt message from inside GofileFormat.

       

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_lPlaceMode = kVanillaPlace; // places the file and returns new art handle

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_disableTemplate = false; // disable Template placement

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_filemethod = 1; // NOTE! - 0 = place the file, 1 = link the file

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_hNewArt = nullptr; // new art handle

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_hOldArt = nullptr; // art to be replaced

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_lParam = kPlacedArt; // type of art to create

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_pFilePath = NULL; // if NULL, shows File Place dialog

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_pFilePath = &message->GetFilePath(); // place the given file (prompt for file to be placed otherwise)

        message->m_pExtData->m_unExt.m_pPlaceRequestData->m_PlaceTransformType = kAIPlaceTransformTypeNone;

        error = sAIPlaced->ExecPlaceRequest(*(message->m_pExtData->m_unExt.m_pPlaceRequestData));

       

      That then calls our Gofileformat with kFileFormatLinkArt (which is good!) and m_lPlaceMode==kVanillaPlace (which is also good!).

      So following on the thread we then create the place art :

       

      error = sAIArt->NewArt(kPlacedArt, kPlaceAboveAll, nullptr, &art);

      .....

      error = sAIPlaced->SetPlacedFileSpecification(art, filePath); //gives the expected 'not EPS' error, but required to se the file path on the art

      .....

      error = sAIPlaced->SetPlacedObject(art, &group);

      .....

      error = sAIArt->UpdateArtworkLink(art, true, &updated); // Should we be passing the group here? Tried, but did not help. Something from the group?

      This call to UpdateArtworkLink then calls GoFileFormat again, with m_lPlaceMode==kForceReplace (which seems a bit dramatic!).

       

      What bothers me here is the handle we created and passed to UpdateArtworkLink is different to the one passed into the next call in m_hOldArt, in all the other steps the NewArt created matched the m_hOldArt in the subsequent call, so something is not right there - most likely.

       

      Regardless, we then renderer our file and create a raster art object to put it into :

      error = sAIArt->NewArt(kRasterArt, kPlaceAboveAll, nullptr, &art);

      ...

      error = sAIRaster->SetRasterInfo(art, &info);

      .... fill AITile with the data....

      error = sAIRaster->SetRasterTile(art, &artSlice, &dstTile, &dstSlice);

       

      And then Ai reports an error before coming back from UpdateArtworkLink, it says there was an error in reading the linked file.

       

      We are quite possibly doing this completely wrong but have spent several days on this now and come to an end of all ideas and google hints.

      Help / guidance / hints would be greatly appreciated.

       

      Thanks in advance,

      R

        • 1. Re: GoFileformat Linked Art
          LeoTaro Level 4

          ralphmce wrote:

           

          Hoping someone can help. I am trying to create a file format plugin that loads a custom file type, but the file must remain linked and not embedded.

          Are you adding a new file format X so that when an X file is opened it adds a link to a file of format Y, or are you just adding a file format X that can only be placed?

           

          Either way, how are you going to stop the user from converting the linked file to embedded?

           

          Without understanding what you are trying to achieve, I can't help you.

          • 2. Re: GoFileformat Linked Art
            ralphmce Level 1

            Hi Leo,

            thanks for the swift reply.

             

            Sorry, didn't mean to cause confusion.

             

            I am adding a new file format X, when X is opened we will render and display it - there are no links to other file types. I want it to default to 'Link' and not Embedded. If the user wishes to change to embedded later that is up to them.

            Hence the first version I detailed was just fine, but for the fact that SetRasterLink is marked as deprecated , but more importantly we also we get the modal dialog box about re-linking all the time. If we can stop that dialog coming up I'll go with the deprecated functionality and move on.

             

            So in short, i'm trying to add file format X (it will create rastered art not a path), which should default to linked. That's it. I feel suitably foolish asking about this as no doubt its terribly simple and I am missing something terribly obvious.

             

            Thanks

            R

            • 3. Re: GoFileformat Linked Art
              LeoTaro Level 4

              So when the user opens a file of format X it opens normally. When they chose to place a file of format X, it is added as a linked file rather than embedded?

               

              What options are you using in AIFileFormat::AddFileFormat(Ex)? kFileFormatRead and kFileFormatLinkArt only?

              • 4. Re: GoFileformat Linked Art
                ralphmce Level 1

                Exactly.

                 

                Actually no, I have the options like so :

                kFileFormatRead | kFileFormatImportArt | kFileFormatPlaceArt | kFileFormatLinkArt | kFileFormatHasExtendedData,

                 

                For completeness here is the code in AddFileFormat :

                 

                PlatformAddFileFormatData affd;

                char pstrAll[kMaxStringLength] = "My format";

                this->CStrToPStr(pstrAll, kMaxStringLength);

                affd.title = (unsigned char*)pstrAll;

                affd.titleOrder = 0;

                affd.extension = "myf";

                affd.type = 'MYF';

                 

                error = sAIFileFormat->AddFileFormat( message->d.self, "My format",

                  &affd, kFileFormatRead | kFileFormatImportArt | kFileFormatPlaceArt | kFileFormatLinkArt | kFileFormatHasExtendedData,

                  &this->fFileFormatAll, kNoExtendedOptions );

                 

                By the way thanks so much for the help!

                R

                • 5. Re: GoFileformat Linked Art
                  LeoTaro Level 4

                  What happens if you remove kFileFormatImportArt | kFileFormatPlaceArt? Reading the doc (header comments), I think that should stop Illustrator trying to embed your file, but Illustrator doesn't always do what you expect!

                  • 6. Re: GoFileformat Linked Art
                    ralphmce Level 1

                    Well that was a bit strange, it shows a message saying the file is not a type that can be placed, but then shows the rasterized result. Then I start getting the annoying message about wanting to relink again.

                     

                    For the test just run I created the art like so :

                     

                    // Create the new art as raster

                    error = sAIArt->NewArt(kRasterArt, kPlaceAboveAll, nullptr, &art);

                    // Then flushed the result to the out by :

                    error = sAIRaster->SetRasterTile(art, &artSlice, &dstTile, &dstSlice);

                     

                    and did not call SetRasterLink.

                     

                    thought I should be as clear as possible.

                    Thanks

                    R

                    • 7. Re: GoFileformat Linked Art
                      ralphmce Level 1

                      Fixed it with the kind help of some of the good folks at Adobe!

                       

                      The key issue is to use :

                      kPlaceInsideOnTop not kPlaceAboveAll

                      in NewArt.

                       

                      //Create the new art

                      error = sAIArt->NewArt(kPlacedArt, kPlaceAboveAll, nullptr, &parentArt);

                       

                      // Set the place object

                      AIArtHandle group = nullptr;

                      error = sAIPlaced->SetPlacedObject(parentArt, &group);

                       

                      //And now the raster art - NOTE passing in the group as the prepositional art object

                      AIArtHandle rasterArt = nullptr;

                      error = sAIArt->NewArt(kRasterArt, kPlaceInsideOnTop, group, &rasterArt);

                       

                      .... then go and populate the art with the rastered artwork.

                      Later on you will get passed the art handle to the parent, so use GetArtFirstChild and GetArtSibling to locate the raster art beneath the parent handle.

                       

                      As expected, easy when you know how.

                      Hopefully this is of use to others.

                      R