[JW Lua] Reading the FontInfo from FCShapeDef - solved

Chris marcel.denio at gmail.com
Wed May 6 07:58:12 CEST 2015


Jan

I realized this script to merge 2 shapes(Missing tags)
Maybe here can help.


--------------------------------------------------------------
local ind1 = finenv.UI():DisplayShapeDialog(1)  -- shape à copier
if ind1 == 0 then return end
local ind2 = finenv.UI():DisplayShapeDialog(1)  -- shape destination
if ind2 == 0 then return end

local sd1 = finale.FCShapeDef()
local sd2 = finale.FCShapeDef()

function parasInstruction(ins)
-- retourne tous les paras de l'instruction dans une table
     local paras = {}

     for ind = 0, ins.Count - 1 do
         local bytes = ins:GetFourbyteData(ind)
         table.insert(paras,bytes)
     end

     return paras
end

function copie(instructions,tag,paras)
     -- ajoute l'instruction (tag) avec ses paras dans "instructions"

     if tag == 29551 then    -- startobject
         local origin =finale.FCPoint(paras[1],paras[2])
         local lefttop =finale.FCPoint(paras[3],paras[4])
         local rightbottom =finale.FCPoint(paras[5],paras[6])
instructions:AddStartObject(origin,lefttop,rightbottom,paras[7],paras[8],paras[9])
    elseif tag == 29554 then    -- startgroup
         local origin =finale.FCPoint(paras[1],paras[2])
         local lefttop =finale.FCPoint(paras[3],paras[4])
         local rightbottom =finale.FCPoint(paras[5],paras[6])
instructions:AddStartGroup(origin,lefttop,rightbottom,paras[7],paras[8],paras[9])
     elseif tag == 25970 then    -- endgroup
         instructions:AddEndGroup()
     elseif tag == 27767 then    -- linewidth
         instructions:AddLineWidth(paras[1])
     elseif tag == 29543 then    -- setgrey
         instructions:AddSetGrey(paras[1])
     elseif tag == 26227 then    -- fillsolid
         instructions:AddFillSolid()
     elseif tag == 25456 then    -- closepath
         instructions:AddClosePath()
     elseif tag == 25964 then    -- ellipse
         instructions:AddEllipse(paras[1],paras[2])
     elseif tag == 29285 then    --  rectangle
         instructions:AddRectangle(paras[1],paras[2])
     elseif tag == 25462 then    --  curveto
         instructions:AddCurveTo(paras[1])
     elseif tag == 29548 then    --  slur
         instructions:AddSlur(paras[1])
     elseif tag == 29556 then    -- stroke
         instructions:AddStroke()
     elseif tag == 29540 then    -- setdash
         instructions:AddSetDash(paras[1],paras[2])
     elseif tag == 29292 then    -- rlineto
         instructions:AddRLineTo(paras[1],paras[2])
     elseif tag == 25202 then    --  bracket
         instructions:AddBracket(paras[1])
     elseif tag == 29293 then    -- rmoveto
         instructions:AddRMoveTo(paras[1],paras[2])
     elseif tag == 29542 then    -- setfont
         local fontinfo = finale.FCFontInfo()
         fontinfo:SetNameByID(paras[1])
         fontinfo.Size = paras[2]
         fontinfo.EnigmaStyles = paras[3]
         instructions:AddSetFont(fontinfo)
     elseif tag == 25699 then    --  drawchar
         instructions:AddDrawChar(paras[1])
     elseif tag == 0 then    -- Null
         instructions:AddNull()
     else
         print("tag non défini",tag)
     end
end


-- ********* DEBUT DU PROGRAMME ****************
if sd1:Load(ind1) and sd2:Load(ind2) then
     local instructions1 = sd1:CreateInstructions()
     local instructions2 = sd2:CreateInstructions()

     -- créer une nouvelle shape
     local sdNew = finale.FCShapeDef()
     local newInstructions =  sdNew:CreateInstructions()

     -- copier la 1° (sauf la dernière : Null)
     for ins in each(instructions1) do
         if ins.Tag ~= 0 then    -- Null
             copie(newInstructions,ins.Tag,parasInstruction(ins))
         end
     end

     -- copier la 2°
     for ins in each(instructions2) do
           copie(newInstructions,ins.Tag,parasInstruction(ins))
     end

     -- sauvegarder la nouvelle shape
     sdNew:RebuildInstructions(newInstructions)
     sdNew:SaveNew()
end

------------------------------------------------------------------------



Best regards


Chris




More information about the JWLua mailing list