Start a new topic

renaming g1 the model name issue

yes, im all over the place. Got put on some clean up work and figured I could kill a step or two..


this issue i am running into, when i run this script, the return modName is pulling a name from a file that is not in the folder anymore.

(i pulled out a few files and put them in a test folder by themselves). I put this together from a few threads in here. 

it works but it is renaming all the g1 beads to the filename of the mentioned file(not in the folder)


I also have to figure out getting rid of the.flt aswell.


outs = mgPromptDialogFile ( None, MPFM_OPEN, MPFA_FLAGS,

MPFF_FILEMUSTEXIST|MPFF_MULTISELECT,

MPFA_PATTERN, "OpenFlight Files|*.flt",

MPFA_DIRECTORY, "D:/"


status = outs[0]


if (MSTAT_ISOK(status)):

numFiles = outs[1]

fileNames = outs[2]

for fileName in fileNames:

print fileName


db = mgOpenDb (fileName)

MakeFltName(db)

g1 = mgGetChild(db)

mgSetName(g1,modName)

print " Processing ", modName

mgWriteDb(db)

mgCloseDb(db)



def MakeFltName(fileName):

fileName = mgGetRec2FileName(db)

split = fileName.split("/")

index = len(split) -1

modName_index = len(splitNamePath) -1

modName = splitNamePath[modName_index]

return modName




so i think I got it...


outs = mgPromptDialogFile ( None, MPFM_OPEN, MPFA_FLAGS,

MPFF_FILEMUSTEXIST|MPFF_MULTISELECT,

MPFA_PATTERN, "OpenFlight Files|*.flt",

MPFA_DIRECTORY, "D:/"


status = outs[0]


if (MSTAT_ISOK(status)):

numFiles = outs[1]

fileNames = outs[2]

for fileName in fileNames:

print fileName


db = mgOpenDb (fileName)

path = mgRec2Filename(db)

split = path.split("/")

index = len(split)-1

g1 = mgGetChild(db)

mgSetName(g1,split[index])

print " Processing ", split[index]

mgWriteDb(db)

mgCloseDb(db)




crap, this isnt it either. It changed the first file in the folder to the correct group name from the filename. but its still grabbing and inserting the model name(mentioned earlier(not in the folder) and applying it to the group name in following files..


maybe the script isnt touching the files after the first one?

hahaha


indents ..


outs = mgPromptDialogFile ( None, MPFM_OPEN, MPFA_FLAGS,

MPFF_FILEMUSTEXIST|MPFF_MULTISELECT,

MPFA_PATTERN, "OpenFlight Files|*.flt",

MPFA_DIRECTORY, "D:/"


status = outs[0]


if (MSTAT_ISOK(status)):

numFiles = outs[1]

fileNames = outs[2]

for fileName in fileNames:

print fileName


db = mgOpenDb (fileName)

path = mgRec2Filename(db)

split = path.split("/")

index = len(split)-1

g1 = mgGetChild(db)

mgSetName(g1,split[index])

print " Processing ", split[index]

mgWriteDb(db)

mgCloseDb(db)

Looks like you might need 1 more level of indent. I'm assuming you want to open each file found in fileNames. The way it looks right now, the for loop runs through all the filenames, then db = mgOpenDb is called only on the last file. Indenting so that the last block of lines is at the same indent level as 'print fileName' looks like what you want to do.


yup, the last post of mine was just a copy and paste from the previous. on my workstation i had already indented over once more.


final...rename group node  to model name - flt extension


outs = mgPromptDialogFile ( None, MPFM_OPEN, MPFA_FLAGS,

MPFF_FILEMUSTEXIST|MPFF_MULTISELECT,

MPFA_PATTERN, "OpenFlight Files|*.flt",

MPFA_DIRECTORY, "D:/"


status = outs[0]


if (MSTAT_ISOK(status)):

numFiles = outs[1]

fileNames = outs[2]

for fileName in fileNames:

print fileName


db = mgOpenDb (fileName)

path = mgRec2Filename(db)

split = path.split("/")

index = len(split)-1

split[index] = split[index][:-4]

g1 = mgGetChild(db)

mgSetName(g1,split[index])

print " Processing ", split[index]

mgWriteDb(db)

mgCloseDb(db)

Login to post a comment