3 Replies Latest reply on Mar 23, 2015 11:35 AM by bballarin

    ImportExport Show/Hide settings?

    bballarin

      Hello,

       

      I have just tested the ImportExportVariables which is going to be very usefull for large books where we want to make a selective import of the variables (on a given file of the book, only import the variables that are useful for this particular file).

       

      I would like to do the same thing for the condition tags Show/hide settings. Be able to import only the Condition Tags (and their show/hide settings) that are usefull for a particular file of a book instead of propagating all the condition tags to all the files.

       

      Is there a Extend script for that or could you give indications for modifying the ImportExport variable to make it support condition tags as well?

       

      Cheers,

       

      Bruno

       

      [Thread moved to scripting section by moderator]

        • 1. Re: ImportExport Show/Hide settings?
          bballarin Level 1

          I found a solution to my above need (see sample code below).

           

          One problem I still have is to allow the script to QUICKLY detect that I only have a few opened files within a book and therefore the script should only update the already opened files.

          Currently the only solution I found to detect that a file is already opened it to actually open it with the Open() method and check the status of Constants.FV_FileAlreadyOpen and then closing it back if I do not need to update it.

          I have not found a solution to be able to detect within the list of book files, which one is already open and which one not, without actually opening all files (which takes time with 40+ fm files in the book if only a couple of them need an update).

           

          Cheers,

           

          Bruno

           

                                  CondFmtId = currDoc.GetNamedCondFmt (condFmtName);

                                   if (!CondFmtId.ObjectValid())

                                      {

                                           if(condFmtName == "")

                                          {

                                              alert("Found an empty condition tag name, aborting the import process.\nCheck the attribute file!");

                                              abort = true;

                                              return;

                                          }

                                          else

                                          {

                                              alert("Condition tag " + condFmtName + " is not valid, aborting the import process.\nCheck the attribute file!" );

                                              abort = true;

                                              return;

                                          }

                                      }

                                  if(CondFmtId.CondFmtIsShown == 0 && condFmtDef == "SHOW")

                                  {

                                      CondFmtId.CondFmtIsShown = 1;

                                      if(!currDocModified)

                                              Console("Modified document \'"+currDoc.Name +"\' ");

                                      Console("Changed condition tag \'" +condFmtName+  "\' from \'HIDE\' to \'SHOW\'");

                                      currDocModified = true;

                                      modifiedCount++;

                                  }

                                  else if(CondFmtId.CondFmtIsShown == 1 && condFmtDef == "HIDE")

                                  {

                                      CondFmtId.CondFmtIsShown = 0;

                                      if(!currDocModified)

                                          Console("Modified document \'"+currDoc.Name +"\' ");

                                      Console("Changed condition tag \'" +condFmtName+  "\' from \'SHOW\' to \'HIDE\'");

                                      currDocModified = true;

                                      modifiedCount++;

                                  }

          • 2. Re: ImportExport Show/Hide settings?
            frameexpert Level 4

            Here is a function I use to see if a document is already open:

             

            function docIsOpen (filename) {

               

                // Make a File object from the file name.
                var oFile = File (filename);
                // Uppercase the filename for easy comparison.
                var sFile = oFile.fullName.toUpperCase ();
                // Make an object to return.
                var oDoc = {doc: 0, docIsOpen: false};
            
                // Loop through the open documents in the session.
                var doc = app.FirstOpenDoc;
                while (doc.id) {
                    // Compare the document’s name with the one we are looking for.
                    if (File (doc.Name).fullName.toUpperCase () === sFile) {
                        // The document we are looking for is open.
                        // Add it to the object and return it.
                        oDoc.doc = doc;
                        oDoc.docIsOpen = true;
                        return oDoc;
                    }
                    doc = doc.NextOpenDocInSession;
                }
                return oDoc; // Document is not open; return the “empty” object.
            }
            

             

            You can call it by passing in a book components name:

             

            var oDoc = docIsOpen (bookComp.Name);
            

             

            It returns a JavaScript object with two members: doc is the document object it if open, or 0 if it is not; docIsOpen is 1 if the document is open and 0 if it is not. If you use the function alone, you don't really need to do it this way, but I will usually use it in with another function that opens the document if it isn't already open. As a result, I need to keep track of whether the document was already open, or if I opened it with the script. Please let me know if you have any questions or comments. -Rick

            • 3. Re: ImportExport Show/Hide settings?
              bballarin Level 1

              Thank you very much Rick. That is exactly what I needed, and makes the script so much faster when only a subset of the book needs an update.

               

              Cheers,

               

              Bruno