Start a new topic

need help with an (almost) working script

Credit the original script written by Chris R.  This script processes files but it doesn't do what I want it to.

what I need:

push a texture palette from one flt file to several others.

what I did:

from a source file, I am writing the first child of every switch to unique files.  

what goes wrong:

each of the child files keeps a texture pattern index but their palette is empty.  I have to process these files (convert to another format) and it they are not textured, neither is my converted file.

Even though the child files contain patterns, the converted files have no texture.

When I found this script I thought I had a solution, but the files processed by the script look and work very much like a non-processed file.  That is, they contain a pattern but no texture palette.  If I save the parent texture palette, then read that texture palette file into the child file, all is well.

But that is way too much work.

I have 145 flt parents to process, generating 1400+ children.

I am OK with running the script from creator (my install currently has a problem using the OF API, I have a ticket open to support on it).  Ideally of course I would love to run the script from a shell, but given the above.. I am coping.

Here's the code that doesn't work for me; I would appreciate direction to get it to do what I want.  Yes, I assume it is possible :).



# Use the currently open db in Creator as the texture palette we want to match

sourcedb = mgGetCurrentDb ()

# Ask the user to select multiple flt files to modify

outs = mgPromptDialogFile (    None, MPFM_OPEN,    MPFA_FLAGS, MPFF_FILEMUSTEXIST|MPFF_MULTISELECT,    MPFA_PATTERN, "OpenFlight Files|*.flt",    MPFA_TITLE, "Select Files to Modify")
status = outs[0]
if (MSTAT_ISOK (status)):
    fileNames = outs[2:len(outs)]
for fileName in fileNames:
    destdb = mgOpenDb (fileName)
    # First Check for patterns that exist in the destination and not in the source
    # if we find any we need to remove them.
    ret,index,name = mgGetFirstTexture (destdb)
while (ret):
    name = mgGetTextureName (sourcedb, index)
    if (name):
        print ("Pattern", index, "will be replaced")
        print ("Removing pattern:", index)
        mgDeleteTexture (destdb, index)
    ret,index,name = mgGetNextTexture (destdb)
# Next loop over every pattern in the source and put them in the dest
ret,index,name = mgGetFirstTexture (sourcedb)

while (ret):
    name = mgGetTextureName (sourcedb, index)
    ok, x,y = mgGetTexturePosition (sourcedb, index)
    mgReadTexture (destdb, name, index, x, y)
    ret,index,name = mgGetNextTexture (sourcedb)
# Save the dest and close it
mgCloseDb (destdb)


It looks like the script shown has an indent issue. Lines 16 through 34 should all have one more indent level. This indent will make those lines part of the for loop on line 11. Without those lines, the for loop will complete without executing the needed code to add textures. Most likely only the last selected file will have any changes, and only the last selected file will be closed as well.


Thanks very much!


Login to post a comment