[GastForen Programmierung/Entwicklung AppleScript Need Script!!

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Themen
Beiträge
Moderatoren
Letzter Beitrag

Need Script!!

Anonym
Beiträge gesamt: 22827

9. Jun 2005, 07:31
Beitrag # 1 von 16
Bewertung:
(3645 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello,
I'm new to applescript. I have a quark file with 100s of images along with their captions grouped. There are also some unnumbered images. I want to extract these images  in sequential order (i.e. to extract images page by page). For example: If page 1 contains 4 images with names "Figure 1, Figure 2, unnumbered figure, Figure 3, Figure 4. Then it should be placed in  a new quark document in the same sequential manner. one Image in one page with the grouped captions.

thanks in advace,
sunny
X

Need Script!!

Hans Haesler
  
Beiträge gesamt: 5826

9. Jun 2005, 08:41
Beitrag # 2 von 16
Beitrag ID: #419720
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello sunny,

welcome to the dtpro forum! :-)

What version of QuarkXPress are you using? Under what Mac OS?

Could you, please, send me a sample document? Not the entire file.
Just three or four pages. I'll gladly try to develop a script.
But I guess it wouldn't be easy. While it will be hard to determine
the sequential order of the picture boxes, it will be harder, still,
to get the corresponding caption boxes.

Cheers, Hans


als Antwort auf: [#419719]

Need Script!!

Anonym
Beiträge gesamt: 22827

9. Jun 2005, 09:42
Beitrag # 3 von 16
Beitrag ID: #419721
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
hi Hans,

Thanks,

I am using OS 9.2 and QuarkXpress 4.11

i am attaching the file to your mail  hsa@ringier.ch


Danke


als Antwort auf: [#419719]

Need Script!!

Anonym
Beiträge gesamt: 22827

9. Jun 2005, 09:53
Beitrag # 4 von 16
Beitrag ID: #419722
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hi Hans,

It would be fine if i would get the name of the picture at the bottom.


als Antwort auf: [#419719]

Need Script!!

Hans Haesler
  
Beiträge gesamt: 5826

9. Jun 2005, 10:30
Beitrag # 5 von 16
Beitrag ID: #419723
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello sunny,

thanks for sending the file. I'll try to find a solution.

Cheers, Hans


als Antwort auf: [#419719]

Need Script!!

Hans Haesler
  
Beiträge gesamt: 5826

12. Jun 2005, 20:38
Beitrag # 6 von 16
Beitrag ID: #419724
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello sunny,

okay, here is a working script. But it only works when the pages hold only one (or zero) picture box.
---
tell application "QuarkXPress 4.11"
    activate
    tell document 1
        set item spread coords to true
        set tool mode to drag mode
        set pageWidth to page width
        set pageHeight to page height
        set docName1 to name
        set nPics to count of picture boxes
    end tell
    if nPics is greater than 0 then
        tell default document 1
            set properties to {page width:pageWidth, page height, facing pages:false}
        end tell
        make document at beginning
    end if
    tell document 1
        repeat with i from 2 to nPics
            make page at end
        end repeat
    end tell
    repeat with i from 1 to nPics
        show document docName1
        show picture box i of document docName1
        tell picture box i of document docName1
            set selected to true
        end tell
        copy
        show document 2
        tell document 1
            show page i
        end tell
        paste
        tell document 1
            tell spread i
                tell picture box 1
                    set origin of bounds to {"3.6p", "5.6p"}
                end tell
                tell text box 1
                    set origin of bounds to {"24p9.614", "5p7.2"}
                end tell
            end tell
        end tell
    end repeat
    display dialog "Done." buttons "OK" default button 1 with icon 1 giving up after 1
end tell

---
Please try this with the dummy document you've sent me. And, please, send me a real life document
with more than one picture box on a page. Then I'll try to adapt the script.

Cheers, Hans


als Antwort auf: [#419719]

Need Script!!

Anonym
Beiträge gesamt: 22827

13. Jun 2005, 06:35
Beitrag # 7 von 16
Beitrag ID: #419725
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hi Hans,

Thank you very much.

i will work on it.
i'll send you the real document as soon as possible.

Sunny.


als Antwort auf: [#419719]

Need Script!!

Hans Haesler
  
Beiträge gesamt: 5826

13. Jun 2005, 08:46
Beitrag # 8 von 16
Beitrag ID: #419726
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello sunny,

thanks for sending the document. It confirms what I've suspected: The picture boxes are of variable dimensions.
And there are also empty picture boxes (e.g. backgrounds) which must be ignored.

The problem with QuarkXPress 4.x: The copied group remains selected and it can be moved by addressing it as
'current box', but some groups end up off of the page. The cure would be to insert a tell block for the
current page. But this throws an error, because of 'current box'.

The solution: The picture box and the text box must be moved individually. But since the dimensions vary,
the position and dimension for both must be stored and the final position must be computed for each.

I'm not sure, yet, what will happen to the small, empty picture boxes which have been used for positioning
the caption boxes. I'll be back.

Cheers, Hans


als Antwort auf: [#419719]

Need Script!!

Anonym
Beiträge gesamt: 22827

14. Jun 2005, 15:55
Beitrag # 9 von 16
Beitrag ID: #419727
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
hi hans,

Is is poissible with Quark 5.x?

If its possible try with Quark 5.x itself.


thanks,
Sunny


als Antwort auf: [#419719]

Need Script!!

Hans Haesler
  
Beiträge gesamt: 5826

14. Jun 2005, 16:09
Beitrag # 10 von 16
Beitrag ID: #419728
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello Sunny,

I'll have to try it. I'm not sure if the group can be addressed as 'group box'.
If this fails then I guess that the conflict between 'current box' and 'current spread'
will be the same. So, we'll better stay with QXP 4.11, because the speed with QXP 5.x
is no good.

But the task to set up the code for handling several picture boxes and the respective
caption boxes on the same page and in the right order is not a small one...

Cheers, Hans


als Antwort auf: [#419719]

Need Script!!

Hans Haesler
  
Beiträge gesamt: 5826

14. Jun 2005, 16:40
Beitrag # 11 von 16
Beitrag ID: #419729
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello Sunny,

okay, with QXP 5.01 things will be easier. And, surprisingly, speed isn't too bad.

The pasted group has to be selected, again. And then it can be placed using 'current box'.
But I still have to figure out how to get the groups in the right order and how to compute
the offsets for placing them on the page. Maybe tonight...

Cheers, Hans


als Antwort auf: [#419719]

Need Script!!

Hans Haesler
  
Beiträge gesamt: 5826

14. Jun 2005, 22:02
Beitrag # 12 von 16
Beitrag ID: #419730
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello sunny,

good news: the script works! :-) At least with the second test document I've got from you. And with
QuarkXPress 5.01. The code is rather long. Therefore I didn't insert any comments.

Here is how it works: The script gets a list of the bounds of every image. Empty picture boxes
return {0, 0, 0, 0}. These are filtered out with a repeat loop. The counter 'nPics' is incremented
with each found image.

If there are any images in the document, the tool mode it set to drag mode, the dimensions of the
document and its name are stored. The properties of the default document are set and a new document
is created. Its measurement units are set temporarily to 'points', the variables for the height
and the width of the page are set accordingly. A repeat loop inserts the pages.

Then the script loops through the pages. On each page it loops through the picture boxes. If a box
contains an image then the counter of the loop and the top of bounds of the box are added to a list.
Then this list is sorted on the second element of each element.

Another repeat loop goes through the sorted list. On each iteration the name of the document,
the index of the page and the index of the picture box are passed to the handler 'copyGroup' which
selects the picture box and copies it using 'copy' and 'paste' to the corresponding page of the new
document. There it gets the heigth and the width of the group, computes the final position ans sets
the origin of bounds to these values.

And so on. The groups are centered on the page. If you'd like to align them on a certain position,
then this could be done easily by setting the vertical (= y) value to a constant.
---
global pCtr
global pageHeight
global pageWidth

tell application "QuarkXPress 5.01"
    activate
    tell document 1
        set picBounds to bounds of image 1 of every picture box
    end tell
end tell

set nPics to 0
repeat with i from 1 to count of picBounds
    if item i of my picBounds is not {0, 0, 0, 0} then
        set nPics to nPics + 1
    end if
end repeat

if nPics is greater than 0 then
    tell application "QuarkXPress 5.01"
        tell document 1
            set tool mode to drag mode
            set pageWidth to page width
            set pageHeight to page height
            set docName1 to name
        end tell
        tell default document 1
            set properties to {page width:pageWidth, page height, facing pages:false}
        end tell
        make document at beginning
        tell document 1
            set properties to {vertical measure:points, horizontal measure:points}
            set pageWidth to page width as real
            set pageHeight to page height as real
            repeat with i from 2 to nPics
                make page at end
            end repeat
        end tell
        set pCtr to 0
        tell document docName1
            repeat with i from 1 to count of pages
                tell page i
                    set imgList to {}
                    repeat with j from 1 to count of picture boxes
                        tell picture box j
                            if bounds of image 1 is not {0, 0, 0, 0} then
                                set end of imgList to {j, top of bounds as real}
                            end if
                        end tell
                    end repeat
                    if imgList is not {} then
                        set nItems to count of imgList
                        if nItems is greater than 1 then
                            my sortList(1, nItems, imgList, 2)
                        end if
                        repeat with k from 1 to nItems
                            my copyGroup(docName1, i, item 1 of (item k of my imgList))
                        end repeat
                    end if
                end tell
            end repeat
        end tell
        tell document 1
            set properties to {vertical measure:inches, horizontal measure:inches}
        end tell
        display dialog "Done." buttons "OK" default button 1 with icon 1 giving up after 1
    end tell
end if

on sortList(startWith1, itemCount, aList, elementToSortOn)
    set leftCtr to startWith1
    set rightCtr to itemCount
    set midItem to item elementToSortOn of (item ((startWith1 + itemCount) div 2) of aList)
    repeat until rightCtr is less than or equal to leftCtr
        repeat while item elementToSortOn of (item leftCtr of aList) is less than midItem
            set leftCtr to leftCtr + 1
        end repeat
        repeat while item elementToSortOn of (item rightCtr of aList) is greater than midItem
            set rightCtr to rightCtr - 1
        end repeat
        if leftCtr is less than or equal to rightCtr then
            set astore to item leftCtr of aList
            set item leftCtr of aList to item rightCtr of aList
            set item rightCtr of aList to astore
            set leftCtr to leftCtr + 1
            set rightCtr to rightCtr - 1
        end if
    end repeat
    if startWith1 is less than rightCtr then
        my sortList(startWith1, rightCtr, aList, elementToSortOn)
    end if
    if itemCount is greater than leftCtr then
        my sortList(leftCtr, itemCount, aList, elementToSortOn)
    end if
    return aList
end sortList

on copyGroup(docName1, i, j)
    tell application "QuarkXPress 5.01"
        try
            show document docName1
            set pCtr to pCtr + 1
            tell picture box j of page i of document 1
                set selected to true
            end tell
            copy
            show document 2
            tell document 1
                show page pCtr
            end tell
            paste
            tell document 1
                tell spread pCtr
                    set selected of every generic box to true
                end tell
                tell current box
                    set y to height of bounds as real
                    set x to width of bounds as real
                    set y to (pageHeight - y) / 2
                    set x to (pageWidth - x) / 2
                    set origin of bounds to {y, x}
                end tell
            end tell
        end try
    end tell
end copyGroup

---

Cheers, Hans


als Antwort auf: [#419719]

Need Script!!

Anonym
Beiträge gesamt: 22827

15. Jun 2005, 05:41
Beitrag # 13 von 16
Beitrag ID: #419731
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Thanks Hans,

i will test it, and get back to you.



sunny


als Antwort auf: [#419719]

Need Script!!

Anonym
Beiträge gesamt: 22827

15. Jun 2005, 14:19
Beitrag # 14 von 16
Beitrag ID: #419732
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hi Hans,

The Script is really great. it works perfectly.

Thanks a lot.

I'll get back to you if i need any help, mean while i’ll be checking this forum for different solutions.

Regards,
Sunny


als Antwort auf: [#419719]

Need Script!!

Hans Haesler
  
Beiträge gesamt: 5826

15. Jun 2005, 15:17
Beitrag # 15 von 16
Beitrag ID: #419733
Bewertung:
(3644 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello sunny,

I'm glad to hear that it works.

Regarding your coming back: Just be aware that—starting this Friday
at noon—I'll be away for two weeks (and no, I won't put my feet in any
Internet-Cafés ;-).

Cheers, Hans


als Antwort auf: [#419719]
X