TIP: New Image Checking Script v2
MisterX
b.xavier at internet.lu
Fri Jun 24 06:25:43 EDT 2005
OK after the past comments received, here the latest script to scan all your
opened
stacks for existing images and thus avoid possible conflict or patterns or
icons not
showing up correctly.
I added a template to list the images' locations too since that could be
useful to
find the conflicting images... ListImageNamelocations will thus list all
locations
of an image with a name in the long id of card form.
I changed the way the string was searched in the image search loops so it's
faster too.
Which is faster "is in" or "offset()>0"
The ImageIDExists and ImageNameExists are boolean functions and made for
speed
not for extensive search; for a listing of the container of the image name
you might
search use the ListImageNamelocations or make your own variations. It's as
simple
as it gets so you can extend with your own wrappers or within your scripts.
Other possibilities, if you want to contribute back (those wrappers might be
intersting
for many different occasions - like listing images by name or id or both in
a list and
so on. Before you decide to script them, ask if i haven't dont so already, i
might sooner
or later.
Also added 2 handlers to update the image list on a per-card or per-stack
(with
all the cards) into the image global database - this preventing a complete
rescan.
There's a "force" parameter to make sure you can resynch if you made
extensive changes.
For most cases the Force=ON should be ok and not felt.
Enjoy
Xavier
--
http://monsieurx.com/TAOO
--
Global XOS
function ImageIDExists imgID
RefreshGlobalImages true
put the keys of xos into ilist
filter ilist with "StackImages,*"
filter ilist without "*imgcount"
sort ilist
repeat for each line thisstack in ilist
if cr&imgID&comma is in cr&xos[thisstack]
then return true
end repeat
return false
end ImageIDExists
function ImageNameExists imgName
RefreshGlobalImages true
put the keys of xos into ilist
filter ilist with "StackImages,*"
filter ilist without "*imgcount"
sort ilist
repeat for each line thisstack in ilist
if comma & imgName & CR is in xos[thisstack]&CR
then return true
end repeat
return false
end ImageNameExists
function ListImageNamelocations imgName
RefreshGlobalImages true
put the keys of xos into ilist
filter ilist with "StackImages,*"
filter ilist without "*imgcount"
sort ilist
put empty into response
repeat for each line thisstack in ilist
if comma & imgName & CR is in xos[thisstack] & CR
then put "card id" && item 3 of thisstack && "of stack" && quoteit(item
2 of thisstack) & cr after response
end repeat
if response is not empty then delete last char of response
return response
end ListImageNamelocations
on RefreshCardImages thisstack,cdid
put the number of images in cd id cdid of stack thisstack into imgcount
if imgcount is not xos["StackImages",thisstack,cdid,"imgcount"] then
put imgcount into xos["StackImages",thisstack,cdid,"imgcount"]
repeat with x = 1 to imgcount
put the properties of img x of cd id cdid of stack thisstack into
imgprops
put imgprops["id"],imgprops["name"] into line x of
xos["StackImages",thisstack,cdid]
end repeat
end if
end RefreshCardImages
on RefreshStackImages thisstack, force
put the number of cds in stack thisstack into cdcount
repeat with c = 1 to cdcount
set cursor to busy
put the short id of cd c of stack thisstack into cdid
put the number of images in cd id cdid of stack thisstack into imgcount
if cdcount>1000 then put "scanning stack:"&&thisstack & ", card" && c
&"/"&cdcount&" - "&imgcount && "images found"
if force is true or imgcount is not
xos["StackImages",thisstack,cdid,"imgcount"] then
put imgcount into xos["StackImages",thisstack,cdid,"imgcount"]
repeat with x = 1 to imgcount
put the properties of img x of cd id cdid of stack thisstack into
imgprops
put imgprops["id"],imgprops["name"] into line x of
xos["StackImages",thisstack,cdid]
end repeat
end if
end repeat
end RefreshStackImages
on RefreshGlobalImages force
put the windows into wlist
repeat for each line thisstack in the windows
RefreshStackImages thisstack, force
end repeat
end RefreshGlobalImages
More information about the use-livecode
mailing list