Start a new topic

Script to Copy Geometry from Db to Db

I have several flight files that I need to reconfigure. I have a template db with several empty nodes with comments. Is it possible to copy the template db geometry into these files via script? 

Yes this is fairly easy. The background information that is important to understand is that nodes are tied to their db. They cannot be moved from one db to another. You cannot for instance detach and attach to a different db. The proper way to get nodes from one db into another is using the function mgDuplicateToDb()


This functions just like mgDuplicate() but the created copy will be in the correct db. Just like when using mgDuplicate(), you still need to attach the newly created node under the desired parent node.

Do you happen to have a sample of this function, along with the attach step? 

I created an example:


# make sure to use forward slash below, or use an escaped back slash '\\'
destPath = 'd:/Scripts/TestFiles/mgDuplicateToDb/destination.flt'
sourcePath = 'd:/Scripts/TestFiles/mgDuplicateToDb/source.flt'

destDb = mgOpenDb (destPath)

#find the node to attach to in the dest Db
targetRec = mgGetRecByName(destDb, 'gunMount')

sourceDb = mgOpenDb(sourcePath)

#find the node to duplicate in the source Db
gunRec = mgGetRecByName(sourceDb, 'gun')

duplicateGunRec = mgDuplicateToDb(gunRec, destDb)

mgAttach(targetRec, duplicateGunRec)




Note: This function (mgDuplicateToDb) does not resolve palette indices between the source and destination databases.

Login to post a comment