I found an error, but the revised script runs and still does not produce any duplicated element in the destination file.
import sys from mgapilib import * # make sure to use forward slash below, or use an escaped back slash '\\' destPath = './destination.flt' sourcePath = './blip.flt' ok = mgOpenDb (destPath) if ok ==MG_FALSE: print ('Error opening destination file') mgExit() else: destDb = ok print('## opened destination OK') ok = mgSetCurrentDb(destDb) if ok ==MG_FALSE: print ('Error setting destination file') mgExit() else: print ('## able to set current dB OK') #find the node to attach to in the dest Db ok = mgGetRecByName(destDb, 'g2') if ok ==MG_FALSE: print ('Error finding node in destination') mgExit() else: targetRec = ok print ('## found target node OK') ok = mgOpenDb(sourcePath) if ok ==MG_FALSE: print ('Error opening source file!') mgExit() else: sourceDb = ok print ('## open source db OK') #find the node to duplicate in the source Db ok = mgGetRecByName(sourceDb, 'houses') if ok ==MG_FALSE: print ('Error getting node!') mgExit() else: nodeRec = ok print ('## found node OK') mgDuplicateToDb(nodeRec, destDb) mgAttach(targetRec, nodeRec) '''if ok ==MG_FALSE: print ('Error attaching node!') mgExit()''' mgWriteDb(destDb) '''if ok ==MG_FALSE: print ('Error writing destination file') mgExit()''' mgCloseDb(destDb) '''if ok ==MG_FALSE: print ('Error closing destination file!') mgExit()''' mgCloseDb(sourceDb) mgExit()
And reverting more closely to the original script posted by Chris, still doesn't duplicate the node into the destination file.
Thx
import sys from mgapilib import * # make sure to use forward slash below, or use an escaped back slash '\\' destPath = './destination.flt' sourcePath = './blip.flt' destDb = mgOpenDb (destPath) mgSetCurrentDb(destDb) #find the node to attach to in the dest Db targetRec = mgGetRecByName(destDb, 'g2') sourceDb = mgOpenDb(sourcePath) #find the node to duplicate in the source Db dupeRec = mgGetRecByName(sourceDb, 'houses') duplicateRec = mgDuplicateToDb(dupeRec, destDb) mgAttach(targetRec, duplicateRec) mgWriteDb(destDb) mgCloseDb(destDb) mgCloseDb(sourceDb) mgExit()
OK. Found some more errors.
I modified my database files to include the nodes from the original script, modified the path and used the example verbatim otherwise. It doesn't copy geometry either.
import sys from mgapilib import * # make sure to use forward slash below, or use an escaped back slash '\\' destPath = './destination.flt' sourcePath = './blip.flt' destDb = mgOpenDb (destPath) mgSetCurrentDb(destDb) #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) mgWriteDb(destDb) mgCloseDb(destDb) mgCloseDb(sourceDb) mgExit()
version: Python 3.7.6
I seem to have found the problem, but I do not have a solution. From the original script:
mgAttach(targetRec, duplicateGunRec)
After adding some error reporting to my script, I see the API says this:
E: Cannot attach node created in one database to a different database.
So if this is true, how do I attach the duplicated node to the other database??
Hoo boy. I find more errors and a missing init statement. Finally, I am getting something into the destination file, and now I see the palette index issue mentioned in the other thread.
import sys from mgapilib import * def main(): mgInit (None, None) # make sure to use forward slash below, or use an escaped back slash '\\' destPath = './destination.flt' sourcePath = './blip.flt' ok = mgOpenDb (destPath) if not ok: msgbuf = mgGetLastError() print(msgbuf, "\n") # mgExit() return else: destDb = ok print('## opened destination OK') ok = mgSetCurrentDb(destDb) if ok ==MG_FALSE: print ('Error setting destination file') else: print ('## able to set current dB OK') #find the node to attach to in the dest Db ok = mgGetRecByName(destDb, 'gunMount') if ok ==MG_FALSE: print ('Error finding node in destination') else: targetRec = ok print ('## found target node OK') ok = mgOpenDb(sourcePath) if ok ==MG_FALSE: print ('Error opening source file!') else: sourceDb = ok print ('## open source db OK') #find the node to duplicate in the source Db ok = mgGetRecByName(sourceDb, 'gun') if ok ==MG_FALSE: print ('Error getting node!') else: nodeRec = ok print ('## found node OK') duplicateGunRec = mgDuplicateToDb(nodeRec, destDb) print (targetRec,nodeRec) mgAttach(targetRec, duplicateGunRec) mgWriteDb(destDb) mgCloseDb(destDb) mgCloseDb(sourceDb) mgExit() main()
In the interests of closure, I did find it necessary to add mgInit and mgExit to the example, and when I used the (nearly) original code, it did work. I thought I posted something like this here yesterday but I don't see it today, so.
Thx
Chris! I never thought vacation, I just assumed you were swamped. Yes, standalone, and yes, I got something working thanks! I am plugging away and will not be shy about asking for help ;)
Shawn
I've added some error checking to an old script posted by Chris in another thread; my revisions broke the script attaching the node. I don't see a copy of the node I am copying ('houses') in the destination file.
here are the messages reported:
## opened destination OK
## able to set current dB OK
## found target node OK
## open source db OK
## found node OK
## duplicated node OK
And the script:
I created the destination.flt file before running this, and blip.flt exists (both attached).
Where did I go wrong??
Thx