3 Replies Latest reply on May 2, 2016 12:24 PM by btempleton1982

    InvokeMenuAction on artwork on artboard

    christianbrugeron Level 1

      Hi folks

       

      I am trying to adjust the siez of my artboards to their content.

      If I invoke the menu commands by hand, it works.

      If I put these commands in my plug in, AI resets the artboard size just after execution!

       

      My code (some instructions may be redondant).

       

      for (int i = 0; i < size; i++) {
      string s = listPng[i]; // artboards names

       

       

      int idx = CherchePTparNom((char*)s.c_str()); // get the idx of the artboard

       

      // selectionner ce PT

       

       

      ASErr erreur = kNoErr;// pour le fichier log

       

       

      erreur = sAIArtboard->Init(prop);

       

       

      erreur = sAIArtboard->GetArtboardList(artboardList);
      erreur = sAIArtboard->GetArtboardProperties(artboardList, idx, prop);

       

       

      erreur = sAIArtboard->SetActive(artboardList, idx);
      erreur = sAIArtboard->Update(artboardList, idx, prop);

       

       

      // envoyer "tout selectionner du plan de travail" avant d'ajuster
      erreur = sAIArtboard->Init(prop);
      erreur = sAIArtboard->GetArtboardProperties(artboardList, idx, prop);
      erreur = sAIMenu->InvokeMenuAction(selectALL);
      erreur = sAIArtboard->Update(artboardList, idx, prop);
      // envoyer la commande de match entre PT et contenu
      erreur = sAIArtboard->Init(prop);
      erreur = sAIArtboard->GetArtboardProperties(artboardList, idx, prop);
      erreur = sAIMenu->InvokeMenuAction(fitArtboardToArtwork);
      erreur = sAIArtboard->Update(artboardList, idx, prop);

       

       

      }

       

      Any help is welcome!!

      Christian

        • 1. Re: InvokeMenuAction on artwork on artboard
          LeoTaro Level 4

          brugeron wrote:

           

          Hi folks

           

          I am trying to adjust the siez of my artboards to their content.

          If I invoke the menu commands by hand, it works.

          If I put these commands in my plug in, AI resets the artboard size just after execution!

           

          My code (some instructions may be redondant).

           

          for (int i = 0; i < size; i++) {
          string s = listPng[i]; // artboards names

           

           

          int idx = CherchePTparNom((char*)s.c_str()); // get the idx of the artboard

           

          // selectionner ce PT

           

           

          ASErr erreur = kNoErr;// pour le fichier log

           

           

          erreur = sAIArtboard->Init(prop);

           

           

          erreur = sAIArtboard->GetArtboardList(artboardList);
          erreur = sAIArtboard->GetArtboardProperties(artboardList, idx, prop);

           

           

          erreur = sAIArtboard->SetActive(artboardList, idx);
          erreur = sAIArtboard->Update(artboardList, idx, prop);

           

           

          // envoyer "tout selectionner du plan de travail" avant d'ajuster
          erreur = sAIArtboard->Init(prop);
          erreur = sAIArtboard->GetArtboardProperties(artboardList, idx, prop);
          erreur = sAIMenu->InvokeMenuAction(selectALL);
          erreur = sAIArtboard->Update(artboardList, idx, prop);
          // envoyer la commande de match entre PT et contenu
          erreur = sAIArtboard->Init(prop);
          erreur = sAIArtboard->GetArtboardProperties(artboardList, idx, prop);
          erreur = sAIMenu->InvokeMenuAction(fitArtboardToArtwork);
          erreur = sAIArtboard->Update(artboardList, idx, prop);

           

           

          You are getting the artboard properties, then you call the menu action that changes the artboard properties and then you update the artboard using the properties before you called the menu action.

           

          Try this:

           

          string s = listPng[i]; // artboards names

           

           

          int idx = CherchePTparNom((char*)s.c_str()); // get the idx of the artboard

           

          // selectionner ce PT

           

           

          ASErr erreur = kNoErr;// pour le fichier log

           

           

          erreur = sAIArtboard->GetArtboardList(artboardList);

           

          erreur = sAIArtboard->SetActive(artboardList, idx);

           

          // envoyer "tout selectionner du plan de travail" avant d'ajuster
          erreur = sAIMenu->InvokeMenuAction(selectALL);
          // envoyer la commande de match entre PT et contenu
          erreur = sAIMenu->InvokeMenuAction(fitArtboardToArtwork);

           

          • 2. Re: InvokeMenuAction on artwork on artboard
            christianbrugeron Level 1

            no amelioration, but thanks

            No artboard seems affected, but the lastone during a few seconds; then AIresets the size of teh artboard.

            There is no feed=back onthe setactive command, also.

             

            cb

            • 3. Re: InvokeMenuAction on artwork on artboard
              btempleton1982 Level 2

              I would try using the ArtSet suite functions to find the actual bounds of the artwork, then GetArtboardProperties, change the properties to the bounds you found, and call Update. It looks like you're mashing together two different ways of doing the same thing.

               

              LeoTaro's solution looks like it should work, but I'm not too sure about the peculiarities of InvokeMenuAction. I'd recommend doing it using the Artboard suite functions.