My Lua Console Output:
Code: Select all
Style Name: BG_Skin_Tone_DEF
No Fill Color Defined
No Line Color Defined
-----
Style Name: BG_Skin_Acct_DEF
No Fill Color Defined
No Line Color Defined
-----
Style Name: BG_Skin_ToneSec_DEF
No Fill Color Defined
No Line Color Defined
-----
Style Name: BG_Skin_Tone_1
No Fill Color Defined
No Line Color Defined
-----
Style Name: BG_Skin_Acct_1
No Fill Color Defined
No Line Color Defined
-----
Style Name: BG_Skin_ToneSec_1
No Fill Color Defined
No Line Color Defined
-----
Style extraction completed.
My Script:
Code: Select all
ScriptName = "ExtractStylesInfoFromStyles"
ExtractStylesInfoFromStyles = {}
function ExtractStylesInfoFromStyles:Name()
return "Extract Styles Info"
end
function ExtractStylesInfoFromStyles:Version()
return "1.2"
end
function ExtractStylesInfoFromStyles:Description()
return "Extracts and outputs fill and line colors of all styles in the current document."
end
function ExtractStylesInfoFromStyles:UILabel()
return "Extract Styles Info"
end
function ExtractStylesInfoFromStyles:Run(moho)
local doc = moho.document
-- Check if a document is loaded
if not doc then
print("No document is loaded.")
return
end
print("Starting style extraction...")
local styleCount = doc:CountStyles()
print("Number of styles: " .. styleCount)
if styleCount == 0 then
print("No styles found in the document.")
return
end
-- Iterate through all styles
for i = 0, styleCount - 1 do
local style = doc:StyleByID(i)
if style then
-- Access the style name safely
local styleName = style.fName:Buffer()
print("Style Name: " .. styleName)
-- Check and print the fill color
if style.fDefineFillCol then
local fillColor = style.fFillCol
print(string.format(" Fill Color (RGB): R:%d G:%d B:%d", fillColor.r, fillColor.g, fillColor.b))
print(string.format(" Fill Color (Hex): #%06X", fillColor.value))
else
print(" No Fill Color Defined")
end
-- Check and print the line color
if style.fDefineLineCol then
local lineColor = style.fLineCol
print(string.format(" Line Color (RGB): R:%d G:%d B:%d", lineColor.r, lineColor.g, lineColor.b))
print(string.format(" Line Color (Hex): #%06X", lineColor.value))
else
print(" No Line Color Defined")
end
else
print(string.format("Style at index %d could not be accessed.", i))
end
print("-----")
end
print("Style extraction completed.")
end
function ExtractStylesInfoFromStyles:Init(moho)
if moho then
moho:NewScriptMenu(self:Name(), self)
end
end
local function Main()
if Moho then
ExtractStylesInfoFromStyles:Init(Moho)
end
end
Main()
Thoughts Ideas, all would be appreciated!