[JW Lua] Deleting a given Test/Shape Expression Def

Jari Williamsson jari.williamsson at mailbox.swipnet.se
Mon Sep 8 19:24:49 CEST 2014


Charles,

When testing the DeepDeleteData() implementing, I found a strange bug in 
Finale. I also found out that that's the reason why I have added 
DeepSaveAs() to the framework once upon a time. ;-)

When deleting text expression defs, Finale will truncate the definition 
list at the deletion point.

The work around is to manually move (by re-saving) all defs downwards 
one step above the deletion point, and then delete the very last text 
expression def.

I've written some code for this that you can use. It'll work in the next 
beta that will be available soon.

---
-- Revove a text expression def, by using a collection.
-- collection: The FCTextExpressionDefs collection
-- itemno: The ItemNo for the def to remove
function RemoveTextExpressionDef(collection, itemno)
     -- Find the ItemNo within the collection:
     local obj = collection:FindItemNo(itemno)
     if not obj then return false end
     local index = collection:GetIndexOf(obj)
     local lastitemno = collection:GetItemAt(collection.Count - 1).ItemNo
     -- Resave all defs above the deletion point at the position below:
     for i = index + 1, collection.Count - 1 do
         local exprdef = collection:GetItemAt(i)
         exprdef:DeepSaveAs(exprdef.ItemNo - 1)
     end
     -- Remove last def:
     local exprdef = finale.FCTextExpressionDef()
     exprdef:Load(lastitemno)
     return exprdef:DeepDeleteData()
end

-- Test code:
local defs = finale.FCTextExpressionDefs()
defs:LoadAll()
RemoveTextExpressionDef(defs, 69)
---

Best regards,

Jari Williamsson


On 2014-09-07 23:34, Charles O. Lawrence wrote:
> Thanks for the help.  I'll keep working on it.  Anxiously awaiting the new
> beta.
>
> Note that my goal is not to delete any expressions as placed in the
> document, but rather to delete any unused expression defs from a selected
> category that show in the selection grid.  Except for the missing
> DeepDeleteData() and the remapping, I think I have developed an algorithm
> that does the job.
>
> Charles
>
> -----Original Message-----
> From: JWLua [mailto:jwlua-bounces at jwmusic.nu] On Behalf Of Jari Williamsson
> Sent: Sunday, September 07, 2014 4:59 PM
> To: The JW Lua script plug-in.
> Subject: Re: [JW Lua] Deleting a given Test/Shape Expression Def
>
> On 2014-09-07 21:52, Charles O. Lawrence wrote:
>
>> There is no DeepDeleteData() method for either FCTextExpressionDef or
>> FCShapeExpressionDef classes, only DeleteData().  There is a
>> DeepSaveAs() for both.  Is an argument required for these methods?
>
> That's not good... I need to add DeepDeleteData() here. A new beta should
> arrive within the next 24 hours, where that will be available.
>
> DeleteData() and DeepDeleteData() don't have any argument. SaveAs() and
> DeepSaveAs() need the location where it should be saved, but you shouldn't
> need those methods for deleting defs.
>
>
>> Excuse my ignorance, but how do you remap the expressions?  I tried at
>> the end to do a SaveAll() and another LoadAll(), but that doesn't seem to
> do it.
>
> First, never use SaveAll() on a collection where you have deleted data.
> Some of the objects in the collection will now point to empty data storage
> that will most probably be resaved. Using LoadAll() again would work fine to
> refresh things, however.
>
> Please note that "expressions" are not the same as "expression defs" in this
> context. The expression is the placed object in the document, pointed to by
> FCExpression objects.
>
> The pseudo code for remapping could be something like this:
> 1. Calculate the new new expression def ItemNo number. For example if you
> delete text expression def 54, all text expression defs at 55 and above will
> be one less.
> 2. Parse through each measure in the document 3. Load all expressions for
> each measure (using
> FCMeasure:LoadAllForItem() with the measure number as argument) 4. Parse
> through all expressions loaded at step #3 with the each() iterator 5.
> Determine if the expression is shape or text and change the "ID" to reflect
> the new shape/text expression def number. Resave the expression.
>
>
> Best regards,
>
> Jari Williamsson
>
>
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
>






More information about the JWLua mailing list