Quark: check if box exists

I am trying to check whether or not a picture box exists. If it does
it will be pasted into text, if it does not, then a text box was created
and the text box will be pasted into text.

This is the line I get hung up on,

if not picture box theFile of page thisPage exists then

–make text box
end if

It says it can not make class pbox into a boolean. (Or something like that.)
Is there a way to test if a box exists? I have named the box with
the file name.

I can attach my script if this is confusing.

OS 9.2.2
AS 1.6
Quark 4.11

Thank you,

Steven.

Hi :slight_smile:
Here one suggestion (no tested):

tell page thisPage of ducument thisFile
if (count (every picture box)) = 0 then
--do something
else
--do something else
end if

:slight_smile:

Unfortunately, the document has several text and picture boxes on every page. I need to test specifically for one picture or text box with a particular name. I can not get the box to accept the file name.

Thank you for the suggestion, though.

Steven.

Hi :slight_smile:
Ok… try this one (tested with QXP 3.32):

tell page thisPage
  if (count (every picture box whose name is theFile)) > 0 then
    display dialog "Ok"
    --do something
  else
    display dialog "No"
    --do something else
  end if
end tell

:slight_smile:

This an interesting approach. I actually like it better than the way I did. But, here is the problem to all of this. I can’t make this part work:

tell text box 1
set name to fileName
end tell

By itself this works and in another script I have (which I copied this from) it works, but under this script it won’t take the name. I even have ScriptMaster to check the box names but it never takes the name? I am really confused because in my other scripts this is very simple.

Any ideas why it will not work in this example?

Thank you for your help thus far,

Steven.

Hi :slight_smile:
Try this syntax :

set name of text box 1 to (fileName as text)

:slight_smile:

In a script by itself that worked but I can not get this series to work in my script. I am incredibly frustrated right now but I very much appreciate all the suggestions from this forum.

Here is what I can not get to work.

	tell page thisPage
				try
					tell picture box 1
						set image 1 to (hiresFileNamePath & theFile) as string
						set bounds of image 1 to exact fit
						--select
						--set name of picture box 1 to (theFile as text)
					end tell
				on error
					tell picture box 1
						delete
					end tell
					my makeTextBox(theFile, thisBox, thisPage)  --this is a subroutine that works
				end try
				--THIS PART WILLNOT WORK
				try
					select picture box theFile
				on error
					select text box theFile
				end try
			end tell

If the picture box was created with the file it will be anchored in text, if the image is not available yet then a text box will be created with the filename in the textbox and that will be anchored in text.

This works in two other scripts I have and I can not figure out why it won’t work here.

Please, any help would be greatly accepted. (And thank you again for the help so far.)

Steven.

Hi :slight_smile:
Here one suggestion (tested with QXP 3.32):

tell application "Finder"
  --The image file to insert
  set DocImage to (choose file)
  --The name of image file
  set DocImageName to name of DocImage
end tell

tell application "QuarkXPress™ 3.32"
  activate
  set thisDoc to 1
  tell document thisDoc
    set thisPage to 1
    tell page thisPage
      try
        tell picture box 1
          set image 1 to (DocImage as text)
          set bounds of image 1 to exact fit
          set name to DocImageName
        end tell
      on error MsgErr
        display dialog MsgErr with icon 0
        my makeTextBox(theFile, thisBox, thisPage) --this is a subroutine that works 
      end try
      try
        --Use this syntax to select the picture box
        set selected of picture box DocImageName to true
      on error MsgErr
        display dialog MsgErr with icon 0
      end try
    end tell
  end tell
end tell

If this does not help you to find a solution with your problem, can you reproduce the code in entirety, because with small ends it is very difficult to see the place where there is a problem.
So long… :slight_smile:

O.K., my last attempt. I should have done this in the first place. My fault.

This script will examine a Quark document, pull paragraph content with specific style sheet, use that as file name, create a picture box and anchor it back into text at the point of the styled text. If the file name is wrong or the image doesn’t exist yet, it will create a text box, place the file name in the text box, and anchor that into text.

If the new text or picture box will take the file name it will work.

Here is the code:

--I DON'T KNOW IF I NEED THESE GLOBAL

global thisPara
global thePara
global theFile

set hiresFileNamePath to choose folder with prompt "Pick Hi Res folder for this title. "
set numberList to {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
set boxFileName to {}
set thePara to {}
set ppnfileNameList to {}
set PPNBoxList to {}
set x to {}
set p to {}
set j to {}
set thisSize to {}
set pageList to {}

tell application "QuarkXPress™ 4.11"
	activate
	tell document 1
		repeat with p from 1 to (count of every page)
			tell page p
				repeat with j from 1 to (count of every text box)
					tell text box j
						repeat with i from 1 to (count of every paragraph)
							try
								if name of style sheet of paragraph i is in (numberList as text) and ¬
									first character of paragraph i is not return then
									if last character of paragraph i is return then
										set x to contents of paragraph i as string
										set ppnfileNameList to (ppnfileNameList & x)
										set thisSize to name of style sheet of paragraph i as integer
										set thePara to thePara & i
										set PPNBoxList to (PPNBoxList & thisSize) as text --text or integer
										set pageList to (pageList & p)
										delete text from character 1 to character -2 of paragraph i
									end if
								end if
							end try
						end repeat --repeat of paragraph
					end tell --text box j
				end repeat --repeat of text box
			end tell -- page p
		end repeat --repeat of page
		--end tell -- document
		
		--tell document 1
		repeat with b from 1 to (count of items of ppnfileNameList)
			set thisPage to item b of pageList
			set thisBox to item b of PPNBoxList
			set theFile to (item b of ppnfileNameList) as string
			
			--CREATE THE PICTURE BOX
			try
				make new picture box at beginning of page thisPage with properties ¬
					{bounds:{"0"", "0"", thisBox, "2.167""}, color:"white", frame:{color:"black", style:solid, width:"0.25 pt"}}
			end try
			
			--SET THE IMAGE IN THE PICTURE BOX OR DELETE IT ON ERROR
			tell page thisPage
				try
					tell picture box 1
						set name to theFile
						set image 1 to (hiresFileNamePath & theFile) as text
						set bounds of image 1 to exact fit
					end tell
				on error MsgErr
					display dialog MsgErr with icon 0
					tell picture box theFile
						delete
					end tell
				end try
			end tell --end tell page
			
			-- TROUBLE WITH THIS LINE
			-- THE PICTURE BOX WON'T TAKE THE NAME
			-- THIS WAS THE ONLY WAY I COULD THINK OF TO TEST 
			--IF PICTURE OR TEXT WAS CREATED 
			if not (picture box whose name is theFile) exists then
				
				--THIS PART WORKS
				make new text box at beginning with properties ¬
					{bounds:{"0"", "0"", thisBox, "2.167""}, color:"white", frame:{color:"black", style:solid, width:"0.25 pt"}} --of page thisPage 
			end if
			
			tell page thisPage
				tell text box 1
					set name to theFile
					set story 1 to theFile as text
				end tell
			end tell
			
			--THIS SECTION WILL GRAB EITHER TEXT OR PICTURE AND ANCHOR IN TEXT
			--IT DOESN'T WORK BECAUSE THE BOX WON'T TAKE THE NAME.
			--IF I REPLAVE "THEFILE" WITH 1 IT WILL GRAB THE PICTURE BOX AND ERROR
			--ON THE TEXT BOX.
			--IF I CAN ONLY GET THE BOX TO TAKE THE NAME THIS WILL WORK.
			try
				select picture box theFile
			on error MsgErr
				display dialog MsgErr with icon 0
				select text box theFile
			end try
			
			set tool mode to drag mode
			cut
			set tool mode to contents mode
			set thisPara to (item b of thePara) as integer
			set selection to insertion point before character 1 of paragraph thisPara ¬
				of story 1 of text box j of page p --of spread z --of story 1
			paste
			set selection to null
			
		end repeat
		
	end tell
end tell

I can not see where the breakdown is.
OS 9.2.2
AS 1.6

Hi Steven :slight_smile:

I looked at your code and I carried out some changes. Here my suggestion (tested with QXP 4.0.4 and MacOs 9):


global thisPara
global thePara
global theFile

set hiresFileNamePath to choose folder with prompt "Pick Hi Res folder for this title. "
set numberList to {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
set boxFileName to {}
set thePara to {}
set ppnfileNameList to {}
set PPNBoxList to {}
set TxtBoxList to {} --List for text boxes
set x to {}
set p to {}
set j to {}
set thisSize to {}
set pageList to {}

tell application "Quark Passport? 4.04"
  try
    activate
    tell document 1
      
      repeat with p from 1 to (count of every page)
        tell page p
          repeat with j from 1 to (count of every text box)
            tell text box j
              repeat with i from 1 to (count of every paragraph)
                try
                  if ((name of paragraph style of paragraph i) is in (numberList as text)) and ¬
                    ((first character of paragraph i) is not return) then
                    if last character of paragraph i is return then
                      set pageList to (pageList & p) --Pages list
                      set TxtBoxList to (TxtBoxList & j) --Text boxes list
                      set thePara to (thePara & i) --Paragraphs list
                      set x to (contents of paragraph i) as string
                      set ppnfileNameList to (ppnfileNameList & x)
                      set thisSize to (name of paragraph style of paragraph i) as integer
                      set PPNBoxList to (PPNBoxList & thisSize) --as text --text or integer 
                    end if
                  end if
                end try
              end repeat --repeat of paragraph 
            end tell --text box j 
          end repeat --repeat of text box 
        end tell -- page p 
      end repeat --repeat of page 
      
      repeat with b from 1 to (count of items of ppnfileNameList)
        set thisPage to item b of pageList
        set thisTxtBox to item b of TxtBoxList
        set thisPara to (item b of thePara) as integer
        set thisBox to item b of PPNBoxList
        set theFile to (item b of ppnfileNameList) as string
        
        tell page thisPage
          show --Show the page
          try
            set NewBox to "" --Empty variable
            --Create a new picture box
            set NewBox to make new picture box at beginning with properties ¬
              {name:theFile, bounds:{"0"", "0"", "" & thisBox & """, "2.167""}, color:¬
                "white", frame:{color:"black", style:solid, width:"0.25 pt"}}
            set image 1 of NewBox to ("" & hiresFileNamePath & theFile)
            set bounds of image 1 of NewBox to exact fit
          on error
            --If an error and exists a new picture box then delete that last one
            if NewBox is not "" then delete NewBox
            set NewBox to "" --Empty variable
            try
              --Create a new text box
              set NewBox to make new text box at beginning with properties ¬
                {name:theFile, bounds:{"0"", "0"", "" & thisBox & """, "2.167""}, color:¬
                  "white", frame:{color:"black", style:solid, width:"0.25 pt"}} --of page thisPage 
              set story 1 of NewBox to theFile
            on error
              if NewBox is not "" then delete NewBox
              error "Error when try to create a new picture box and new text box" number 9000
            end try
          end try
        end tell --end tell page 
        
        try
          set selection to null
          set tool mode to drag mode
          select NewBox
          cut
          set tool mode to contents mode
          --Delete the name of image in the text
          delete (text from character 1 to character -2 of (paragraph thisPara of ¬
            (story 1 of (text box thisTxtBox of page thisPage))))
          set selection to (insertion point before character 1 of (paragraph thisPara of ¬
            (story 1 of (text box thisTxtBox of page thisPage))))
          paste
          set selection to null
        on error --
          error "Error when try to cut and paste the box into the text" number 9002
        end try
      end repeat
    end tell
  on error MsgErr number NroErr
    if NroErr is not -128 then ¬
      display dialog "" & NroErr & " : " & MsgErr with icon 0
  end try
end tell

I hope for that helps you… :wink:

IT WORKED!!!

THANK YOU!!!

I adjusted one small line – (name of style sheet of paragraph) instead of paragraph style but once I did that it worked!

I really appreciate all of the help with this project. But, before I move on to my next script there is one more odd thing happening when I run this. The boxes are importing with a 6 pt runaround? This is interesting because in another script I am working on I need to copy the runaround of a textbox and duplicate the settings in a new picture box. In this script, however, I need the runaround set to 1 point.

Any idea why this is happening and also how to duplicate the behavior?

Once again, thank you for all of your suggestions.

Steven.

Enjoy… :smiley:

Ho… Sorry Steven, but i do not understand very well this problem, would you have an example?
If you have some, please, send me a mail with the exemple to fredomkbfr@yahoo.fr.
Thanks… :wink:

I don’t know why it did this but I put “global newBox” at the top and also “set newBox to “””

This seems to have “reset” the runaround to 1 pt.

Again, don’t know why but it worked.

Thank you again for all your help and suggestions.

Steven.

Fredo you are by far the most kind and helpful person on this BBS, maybe even the planet? :smiley:

Seriously though you are what makes these forums what they are… kind people offering service to those who are willing to help themselves.

From me and I’m sure many others on this forums a round of applause!! clap

You helped me a while back with one of my problems and I have been indebted to you ever since … :slight_smile:

Keep well,

Dave

Hi Dave :slight_smile:

Yea !!! I know, I know (I am the best of the planet, the whole cosmos and the totality of the whole universe!!!)… 8) 8) 8) :lol: :lol: :lol: :wink:

Thank you very Very VERY MUCH for your encouragements, that pleases really to me… :smiley: :wink:

Thank you Dave, it is very touching, but you do not owe me anything the whole.
We are here to learn and, like you say, to help together. :slight_smile:

One day, perhaps (I hope), you will help me, in your turn. :wink:
And, even if this day never arrives, will know that it is not serious, because you already helped me!!!
Indeed, by putting your question, you allowed me to seek a solution and, thus, to learn from the things which I was unaware of.
That is the exchange. :wink:

Thank you again Dave for your support… :rolleyes:
Regard…