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.
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.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
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:
-- * 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