Check if an object exists on a page

Hello

I am trying to automate the addition of elements commonly used on existing documents and I want to be able to check if an object already exists in the page so that it is not added twice. I'm pretty new to JavaScript, but confident enough in Indesign CC.

Here is the fragment of script I want to do the work:

// add address window
if(!doesObjectExist(myAddressWindow)){
    var myAddressWindow=myDocument.pages.item(0).textFrames.add();
    var myCorners=CornerOptions.ROUNDED_CORNER;
    myAddressWindow.properties={name:"myAddressWindow",geometricBounds:["33mm", "20mm", "78mm", "110mm"],strokeWeight:0.5,strokeColor:"Magenta",topLeftCornerOption:myCorners,topRightCornerOption:myCorners,bottomLeftCornerOption:myCorners,bottomRightCornerOption:myCorners};
}


function doesObjectExist(objectName){
 with(myDocument.pages.everyItem){
     if(name==objectName){
         return true;
         }
     }

the myAddressWindow always item added, even if it already exists and I can't understand why.

Thank you and best regards,

Malcolm

Hi Malcolm,.

You can use itemByName() on the pageItems in the document, if this item you are looking for is not nested (within a group or graphic image or anchored to a text frame etc.pp). :

testSomething("TheNameOfTheThing");

function testSomething(/*String*/myName){

    if( app.documents[0].pageItems.itemByName(myName).isValid ){
        //Nothing to do:
        $.writeln("Nothing to do.")
        return;
        };
    else{ doSomething() };

    };

function doSomething(){
    /* Your code for adding something should follow here: */
    $.writeln("Build something.");
    };

You could also test is not valid and do something, if it is true.

The code above is just an example not optimized in any way.

Uwe

Tags: InDesign

Similar Questions

  • Check if certain files exist

    Hi all

    I wrote a reference guide and I was wondering if I can check if certain files exist on a page.
    If it exists then I can send the user to a page.
    And if not, they will see another page.
    Grateful if someone points me to the right direction.

    Thank you
    Karen

    Hello Cognethos,

    You must use the double backslashes in your path of the file reference. Your script is OK except this line:
    If (FSO. FileExists ("C:\Program Files\Common Files\My file.txt Directory\My"))

    It should read this:
    If (FSO. FileExists ("file.txt C:\\Program Program Files\\My Directory\\My"))

    The technical reason for this is that there are special characters that you cannot use directly in a string. In this case, your path is the chain. Backslash is be one of the special characters that you cannot use directly in a string. To work around this problem, you must do what is called an escape sequence. In this case, the escape sequence for------is------.

  • HP50g: HP50g - hot to check if the object of the stack is a number?

    How to check if an object on the stack is a number or another type of data? There seems to be no any function to check on 50g.

    50 g advanced users to see, page 1-13:

    "The order TYPE ([left SHIFT] PRG-> TEST-> NXT-> TYPE) accepts any object as argument and returns the number that identifies the type of this object." For example, 'HELLO' TYPE returns 2, the value of a string object. See table of object types in Chapter 3, in the command TYPE, to find objects of calculator and corresponding type numbers.

    Generally want to DUP the object to the level of the stack 1 first of all, because likely you want to do something with it, after checking his type.  The following RPL program checks the type of the object in level 1 of the pile and adds a string to the stack indicating its type.  Only some of the possible types are checked and a generic "something else" translates to others:

    «
    TYPE OF DUP
    CASE
    DUP 0 == THEN DROP 'real number' END
    DUP 1 == THEN DROP "complex number" END
    DUP 2 == THEN DROP 'chain' END
    DUP 3 == THEN DROP "real array" END
    DUP 5 is THEN DROP 'list' END
    DROP "something else"
    END
    »

  • JS to check if a link is in the page or PB

    JS need to check if the connection object is within the page or pasteboard.

    Thank you very much.

    Hi SNAF,.

    Please try the js code below works in InDesign CS4.

    var myDoc = app.activeDocument;
    for (var i=0; i
    

    THX

    csm_phil

  • How to check if the link exists in the remote site

    Hi all:

    Guys please can you me if there is a way I can check if the link exists in the remote site? for example

    < cfif hyper link to www.mysite.com exists in www.remotesite.com >
    good... We will continue
    < cfelse >
    Please add link to www.mysite.com before continuing
    < / cfif >

    Is this possible... you have to use the spider? If yes how?

    Thanks guys,.
    A

    to develop the excellent suggestion of tclaremont:

    You can use refindnocase() to search the returned by cfhttp filecontent
    call us at:

    http://www.yourwebsite.com">
    method http://www.VisitorsPage' = 'GET' result = 'Foobar '.
    ResolveUrl = "yes" getasbinary = "auto" >

    <>
    foobar. StatusCode is "200 OK" >
    ] * href [^ >] *' & replace (myurl, '. ',' \.',)
    'all') & '[^>]*>(.*?) <\>', Foobar.filecontent) >
    link

    no link...


    ... connection error or the web page you requested does not exist...

    of course, if the www.VisitorsPage site is sneaky and has the link to
    your site code page, but hide it with css/javascript, it's going to
    be difficult to discover using regexp... better just go and watch their
    Web site...

    Azadi Saryev
    SABAI - Dee.com
    http://www.SABAI-Dee.com/

  • SQL statement to check if a file exists

    Good afternoon

    I thought I saw once a post that had a SQL statement that would check a table to check if a record exists and return true or false... He would return all records, just a Boolean... Such a function exists? I searched the forums, but I don't remember what I was ready when I found this...

    Thanks in advance for any help you can offer.

    Donald

    Hi Donald,.

    Oracle SQL is not a Boolean data type (see: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#sthref19 for types available).

    As a general rule, a custom function returns 0 or 1 or 'Y' or ' no 'TRUE' or 'FALSE' or something similar, like a number or a varchar2.

    Depending on what you need to do and where you need to do, there are other options available. For example, a validation of the page, you could do a validation EXISTS of:

    SELECT 1 FROM TableX WHERE Field1 = value
    

    This would amount to true or false and validation would be success or failure as a result.

    Within a process, you would do something like:

    DECLARE
     vCOUNT NUMBER;
    BEGIN
     SELECT COUNT(*) INTO vCOUNT FROM TableX WHERE Field1 = value;
     IF vCOUNT > 0 THEN
      do something if there is a record;
     ELSE
      do something if there isn't a record;
     END IF;
    END;
    

    Andy

  • DB tools: SELECT to check if the record exists?

    I use the database connectivity toolset.

    Our IT guy advised me that I should use the SELECT clause to check if a record exists in a table.

    When I send LabVIEW through a UDL file:

    SELECT id

    FROM [ProdTestData]. [dbo]. [TestResults]

    WHERE MONumber = 'C00322. '

    I get nothing back. See attachment.
    When the guys in IT are doing the same to their API, they receive in return a number.

    I must add a FETCH or something else to my VI?

    Try adding DB tools Fetch Recordset Data.vi between your application VI and the free VI.

  • How can I check if a file exists in the CVI real-time?

    Also, it would be nice if designated so help file functions have been supported in real time or now.

    I tried this:

    If (GetFileAttrs (DataFileName, NULL, NULL, NULL, NULL) == - 1).

    You can check if a file exists in the CVI real-time using GetFileInfo.

    CVI provides a list of the available functions in the CVI real-time here: CVI real-time functions

  • User header imported successfully, Impdp import the same user has: b getting object exists error

    Hello

    My scenario

    In our database of prod, we have user A that I recently imported A user in the Test database

    Now I need to import user A user B in the same Test database but get error object exists

    ORA-39151: Table "A.Table_Name" exists

    ORA-31684: Procedure 'A.Proc_Name' exists

    My impdp syntax is the following:

    Impdp USERID =------"/ ACE sysdba\ ' DIRECTORY = DATA_PUMP_DIR DUMPFILE = A.dmp EXCLUDE = USER LOGFILE = A_TO_B_imp.log

    REMAP_SCHEMA = A: B

    REMAP_TABLESPACE = USERS: B

    I thought that this was caused by the fact that the two user B in the database Test with same Tablespace by default, so I created a different tablespace for user B and provided remap tablespace parameter but still getting the same error.

    Please notify.

    Hello

    Seems for some reason any your part of remap_schema is not recognized.

    In the beginning of the impdp log, you should see the command it uses,

    Can you confirm the exact order impdp journal tries to run.

    Also run the impdp since the user of the system.

  • How to check if a value exists in a column

    Hello Experts,

    version: 10.1.0.5

    I am a novice in pl/sql programming. I am trying to create a procedure that checks if a value exists in a column and if it is not it inserts. Here's the procedure and errors,

    SQL > CREATE OR REPLACE PACKAGE BODY manr.audit_pkg

    2 PROCEDURE audit_proc (number of p_sessionid, p_username VARCHAR2, date of the p_date) IS

    3 BEGIN

    4 If p_sessionid not in (select manr.audit_history sessionid)

    5. can

    6 INSERT INTO manr.audit_history VALUES (p_sessionid, p_username, p_date);

    7 validation;

    8 end if;

    9 END;

    10 END audit_pkg;

    11.

    WARNING: The body of a Package created with compilation errors.

    SQL > show error

    PACKAGE BODY HÉLÈNE errors. AUDIT_PKG:

    LINE/COL ERROR

    -------- -----------------------------------------------------------------

    4/1 PL/SQL: statement ignored

    4/22 PLS-00405: subquery not allowed in this context

    Could you please tell me where I'm wrong. Thanks for your help.

    Rocky

    Hello

    If p_sessionid not in (select manr.audit_history sessionid)

    Try:

    .....

    Select count (*) in the v_sessionid of manr.audit_history

    where sessionid = p_sessionid;

    If v_sessionid > 0 then

    .....

    on the other

    ....

    end if;

    Ziut

  • How to check if a node exists in the XML file?

    I was asked to program a method to import data from xml files in our Coldfusion 8 Web site, I am new to the use of XML.

    My method worked however I encountered the following error:

    Element NETWORKORDER. SECONDARYADDRESS. CONTACTNAME is undefined in MYDOC.

    Investigation on the node in the XML file was not present.

    Is there a method I can use to resolve this error by checking if a node exists in the xml file, which works with my current code below?

    <!--> reading XML file
    < cffile action = "read" file = "D:\website\XML\#FileName#" variable = "myxml" >
    < cfset mydoc = XmlParse (myxml) >

    <!--> to extract data from the XML of NDS file
    < cfset aPrimaryContactName =(#mydoc.NetworkOrder.PrimaryAddress.ContactName#) >
    < cfset aPrimaryContactNumber =(#mydoc.NetworkOrder.PrimaryAddress.ContactNumber#) >
    < cfset aPrimaryContactNumber = tostring(#mydoc.NetworkOrder.PrimaryAddress.ContactNumber#) >
    < cfset aPrimaryContactAddressLine1 =(#mydoc.NetworkOrder.PrimaryAddress.line1#) >
    < cfset aPrimaryContactAddressLine2 =(#mydoc.NetworkOrder.PrimaryAddress.line2#) >
    < cfset aPrimaryContactAddressLine3 =(#mydoc.NetworkOrder.PrimaryAddress.line3#) >
    < cfset aPrimaryContactAddressLine4 =(#mydoc.NetworkOrder.PrimaryAddress.line4#) >
    < cfset aPrimaryContactAddressLine5 =(#mydoc.NetworkOrder.PrimaryAddress.line5#) >
    < cfset aPrimaryContactCity =(#mydoc.NetworkOrder.PrimaryAddress.City#) >
    < cfset aPrimaryContactPostcode =(#mydoc.NetworkOrder.PrimaryAddress.PostalCode#) >
    < cfset aPrimaryContactCounty =(#mydoc.NetworkOrder.PrimaryAddress.CountrySubdivision#) >
    < cfset aPrimaryContactCountryCode =(#mydoc.NetworkOrder.PrimaryAddress.CountryCode#) >
    < cfset aPrimaryContactCountry =(#mydoc.NetworkOrder.SecondaryAddress.Country#) >
    < cfset aSecondaryContactName =(#mydoc.NetworkOrder.SecondaryAddress.ContactName#) >
    < cfset aSecondaryAttentionOfName =(#mydoc.NetworkOrder.SecondaryAddress.AttentionOfName#) >
    < cfset aSecondaryContactNumber =(#mydoc.NetworkOrder.SecondaryAddress.ContactNumber#) >
    < cfset aSecondaryContactAddressLine1 =(#mydoc.NetworkOrder.SecondaryAddress.line1#) >
    < cfset aSecondaryContactAddressLine2 =(#mydoc.NetworkOrder.SecondaryAddress.line2#) >
    < cfset aSecondaryContactAddressLine3 =(#mydoc.NetworkOrder.SecondaryAddress.line3#) >
    < cfset aSecondaryContactAddressLine4 =(#mydoc.NetworkOrder.SecondaryAddress.line4#) >
    < cfset aSecondaryContactAddressLine5 =(#mydoc.NetworkOrder.SecondaryAddress.line5#) >
    < cfset aSecondaryContactCity =(#mydoc.NetworkOrder.SecondaryAddress.City#) >
    < cfset aSecondaryContactPostcode =(#mydoc.NetworkOrder.SecondaryAddress.PostalCode#) >
    < cfset aSecondaryContactCounty =(#mydoc.NetworkOrder.SecondaryAddress.CountrySubdivision#) >
    < cfset aSecondaryContactCountryCode =(#mydoc.NetworkOrder.SecondaryAddress.CountryCode#) >
    < cfset aSecondaryContactCountry =(#mydoc.NetworkOrder.SecondaryAddress.Country#) >

    Since you already have the XML parsed in a document, the easiest is to use xmlSearch(). Take a look at the doc, it is pretty easy to use. Something as simple as:

    To the most complex as:

    And in both cases:

    Read the doc and google is your friend "coldfusion xmlsearch.

  • Check if the user_id exists in the LDAP server

    Hello

    I was wandering if their whole approach to communicate with the LDAP server. I have a requirement where - in that I have a table of database users; I need an audit of validation against the LDAP server to check if the user exists in the LDAP server or not and if it is an active user. I was watching the DBMS_LDAP API; but don't know how to use it. Please help me with one possible approach. I use the Oracle 10 g R2 database.

    Any help is appreciated.

    Thank you

    Orton

    That DBMS_LDAP must be used, in three basic steps. To connect to the server. To authenticate with a username and password (assuming that anonymous access is not allowed). A query (by using a LDAP search) if the username exists.

    And that's essentially what the code example.

    My sample code uses a service account to open an LDAP session - as anonymous access does not have the code perform the research needed in my case. The code also uses a search based on the Security Accounts Manager (SAM) account name as search criteria - that is the username for a Windows (used by the user to authenticate to the domain NTLM) account. This can be changed to a different search criteria.

    One thing about LDAP is not simplistic. There is not a single LDAP command which will tell you if a username exists, or not. At least a simple search to do - after the connection to the server and authentication with the server.

    The code example shows most of these pieces, you will need to do your checking of user using LDAP name.

  • Fastest way to check if a file exists

    Hello

    I have a table with more than 100 M records. What is the fastest way to check if a record exists or not. Currently I use Oracle 11.2. Here is the SQL code I used, id is the primary key of the table_test.

    Select count (*) from existFlag
    of table_test
    where id = testID
    ;

    Yes, you could use double fusion using the clause, but a line of K + 10 k 10 inserts a line MERGE statements will be much less effective than 1 INSERTING rows 10 K + 1 MERGER of 10 K lines.

    SY.

  • How to check if a folder exists

    Hello

    I have a custom filter component:
    public class BarcodeMetadataFilter implements FilterImplementor{
    }
    I check here if the file exists in xCollectionId value, so I have two qustions:

    (1) should what service I call to check if the file exists?
    (2) how to call this service from the filter?

    Kuba

    Call a service such as COLLECTION_GET_INFO. Pass the parameter dCollectionID which must be xCollectionID. If you receive and error, it may mean that the folder does not exist. You should check the error (exception) to ensure what he wants to say to you is that the folder does not exist.

    http://docs.Oracle.com/CD/E23943_01/doc.1111/e11011/c07_folders.htm#i1082467

    The following blog post will show you how to run a service, a filter: http://jonathanhult.com/blog/2012/06/execute-a-service-from-a-java-filter/

    Jonathan
    http://jonathanhult.com

  • How to check if a string exists in varray or not

    Hi all

    How to check if a string exists in varray or not.

    Version Details 
    
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    SQL> get test
      1  DECLARE
      2     TYPE dnames_var IS VARRAY(7) OF VARCHAR2(30);
      3     dept_names dnames_var := dnames_var('Shipping','Sales','Finance','Payroll');
      4  BEGIN
      5    if dept_names.exists('Shipping')
      6    then
      7       dbms_output.put_line('Exists ................');
      8    end if ;
      9  /*   DBMS_OUTPUT.PUT_LINE('dept_names has ' || dept_names.COUNT
     10                          || ' elements now');
     11     DBMS_OUTPUT.PUT_LINE('dept_names''s type can hold a maximum of '
     12                           || dept_names.LIMIT || ' elements');
     13     DBMS_OUTPUT.PUT_LINE('The maximum number you can use with '
     14         || 'dept_names.EXTEND() is ' || (dept_names.LIMIT - dept_names.COUNT));
     15  */
     16* END;
     17  
     18  /
    DECLARE
    *
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    ORA-06512: at line 5
    
    
    SQL> 
    
    Any help in this regard is appreciated ...
    Thank you
    Prakash P

    Published by: prakash on April 29, 2012 05:42

    EXISTS checks for the existence of an element, not a value. Since you're using VARRAY (btw, it is not recommended), your only choice is a loop through:

    SQL> DECLARE
      2       TYPE dnames_var IS VARRAY(7) OF VARCHAR2(30);
      3       dept_names dnames_var := dnames_var('Shipping','Sales','Finance','Payroll');
      4  BEGIN
      5      for i in 1..dept_names.count loop
      6        if dept_names(i) = 'Shipping'
      7          then
      8            dbms_output.put_line('Exists ................');
      9            exit;
     10        end if;
     11      end loop;
     12  END;
     13  /
    Exists ................
    
    PL/SQL procedure successfully completed.
    
    SQL>  
    

    If you use the nested table, you can use MEMBER, SUMBULTISET, MULTISET EXCEPT:

    SQL> DECLARE
      2       TYPE dnames_var IS TABLE OF VARCHAR2(30);
      3       dept_names dnames_var := dnames_var('Shipping','Sales','Finance','Payroll');
      4  BEGIN
      5      if 'Shipping' member of dept_names
      6      then
      7         dbms_output.put_line('Exists ................');
      8      end if ;
      9  END;
     10  /
    Exists ................
    
    PL/SQL procedure successfully completed.
    
    SQL> DECLARE
      2       TYPE dnames_var IS TABLE OF VARCHAR2(30);
      3       dept_names dnames_var := dnames_var('Shipping','Sales','Finance','Payroll');
      4  BEGIN
      5      if dnames_var('Shipping') submultiset dept_names
      6      then
      7         dbms_output.put_line('Exists ................');
      8      end if ;
      9  END;
     10  /
    Exists ................
    
    PL/SQL procedure successfully completed.
    
    SQL> DECLARE
      2       TYPE dnames_var IS TABLE OF VARCHAR2(30);
      3       dept_names dnames_var := dnames_var('Shipping','Sales','Finance','Payroll');
      4  BEGIN
      5      if dnames_var('Shipping') multiset except dept_names = dnames_var()
      6      then
      7         dbms_output.put_line('Exists ................');
      8      end if ;
      9  END;
     10  /
    Exists ................
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

Maybe you are looking for