hi.
how to detect image layer's source is missed or not!
is there some thing like:
ImageLayer:SourceIsMissed() ?
get missed images
Moderators: Víctor Paredes, Belgarath, slowtiger
- davoodice2
- Posts: 381
- Joined: Tue Jun 15, 2021 1:14 pm
get missed images
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- synthsin75
- Posts: 9975
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: get missed images
Check to see if ImageLayer:SourceImage() is a valid path, using io.open. Be sure to close the file, io.close(path), if it's valid.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Re: get missed images
An alternative file test in Lua is to use os.rename, where you try to rename a file to itself. This will do nothing to the file - but will return true if the file is renamable, and nil* if the file is missing etc.
*Note: os.rename will also return the reason if the rename fails.
Code: Select all
if os.rename(myfile, myfile) then
DoSomething
end
Code: Select all
result, reason = os.rename(myfile, myfile)
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
- synthsin75
- Posts: 9975
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: get missed images
io.open can also give error messages, but os.rename is more efficient. Good one, Sam.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- davoodice2
- Posts: 381
- Joined: Tue Jun 15, 2021 1:14 pm
Re: get missed images
thanks and excuse me for more questions.
why when we import psd as layers, scale is always equal to 1. but when we replace it, it's actual size in viewport change?(when it is into scaled group).
I wrote a script to fix that. but with change scale of layer. and I sure it is bad. can I replace psd with code without changing scale and preserve layer size?
and I noticed when I replace a layer that is into a scaled group with moho itself, when I use undo right after replacement, size of image will fixed.
why when we import psd as layers, scale is always equal to 1. but when we replace it, it's actual size in viewport change?(when it is into scaled group).
I wrote a script to fix that. but with change scale of layer. and I sure it is bad. can I replace psd with code without changing scale and preserve layer size?
and I noticed when I replace a layer that is into a scaled group with moho itself, when I use undo right after replacement, size of image will fixed.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
- synthsin75
- Posts: 9975
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: get missed images
Lukas has dealt with that more than I. Maybe he'll chime in.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Re: get missed images
Yeah, this is troublesome and I wish image Height and Width would not be related to the project Size at all but here we are. It would be nice to be able to set image Height and Width by script, but we can't.
I currently also adjust the scale of image layers, I'm not happy about messing up the files, but there's currently no other way:
I currently also adjust the scale of image layers, I'm not happy about messing up the files, but there's currently no other way:
Code: Select all
-- * Check old size:
local oldHeight = imageLayer:Height()
imageLayer:SetSourceImage(imagePath)
-- * Compare to new size:
local newHeight = imageLayer:Height()
-- * Check if difference is significant:
local heightDifference = math.abs (oldHeight - newHeight)
if heightDifference < 0.1 then
heightDifference = 0
end
-- * Change size on frame 0 and timeline:
if heightDifference ~= 0 then --newHeight ~= oldHeight then
self.changedScale = true
local heightChange = oldHeight / newHeight
local scaleChannel = imageLayer.fScale
local oldScale = scaleChannel:GetValue(0)
local newScale = oldScale * heightChange
-- * Main timeline scale channel for this image layer:
local endKey = scaleChannel:Duration()
local thisKey = 0
local keyCount = scaleChannel:CountKeys()
local keysFound = 0
local frameNum = endKey
while keysFound < keyCount do
thisKey = scaleChannel:GetClosestKeyID(frameNum)
keyFrameNum = scaleChannel:GetKeyWhen(thisKey)
keysFound = 1 + keysFound
-- * Scale it:
local oldScale = scaleChannel:GetValue(keyFrameNum)
local newScale = oldScale * heightChange
scaleChannel:SetValue(keyFrameNum, newScale)
frameNum = keyFrameNum - 1
end
-- * Do all action scale channels for this image layer too:
for i = 0, scaleChannel:CountActions()-1 do
local actionChannel = moho:ChannelAsAnimVec3(scaleChannel:Action(i))
local endKey = actionChannel:Duration()
local thisKey = 0
local keyCount = actionChannel:CountKeys()-1 -- * -1 because we don't want to modify frame 0 in actions!
local keysFound = 0
local frameNum = endKey
while keysFound < keyCount do
thisKey = actionChannel:GetClosestKeyID(frameNum)
keyFrameNum = actionChannel:GetKeyWhen(thisKey)
keysFound = 1 + keysFound
-- * Scale it:
local oldScale = actionChannel:GetValue(keyFrameNum)
local newScale = oldScale * heightChange
actionChannel:SetValue(keyFrameNum, newScale)
frameNum = keyFrameNum - 1
end
end
end