This is the API reference:
# create the external reference node xRef = mgNewRec (fltXref)) # associate an OpenFlight file to the new external reference mgSetAttList (xRef, "c:/MyDatabases/xRef.flt") # attach the new node mgAttach (parentNode, xRef)
3rd time's the charm this AM? Having issues with file upload, so that will follow in a separate post shortly.
I'm trying to create a fltXref. My code runs but does nothing to the flt database.
Also the API example:
mgSetAttList (xRef, "c:/MyDatabases/xRef.flt")
fails for me with this error:
Traceback (most recent call last): File "my_newB.py", line 143, in <module> main() File "my_newB.py", line 125, in main mgSetAttList(xRef, "./res_90.flt") TypeError: in method 'mgSetAttList', argument attrCode of type 'int'
Here's my script:
## ## ## Sample file: egnew1.py ## ## Objective:Shows how to create a new OpenFlight database and add simple ## geometry. ## ## Program functions: Creates new database given on command line. ## Creates a simple hierarchy with groups, an object and a polygon. ## Sets the comment fields of each. ## Writes the new database to disk. ## ## API functions used: ## mgInit(), mgExit(), mgSetNewOverwriteFlag(), mgGetLastError(), ## mgNewRec(), mgSetComment(), mgGetComment(), ## mgAttach(), mgInsert(), mgDeleteComment(), ## mgSetVtxCoord(), mgFree(), ## mgOpenDb(), mgWriteDb(), mgCloseDb(). ## ## import sys # import OpenFlight API module from mgapilib import * def main (): ic0 = 0.0, 0.0, 0.0 ic1 = 100.0, 0.0, 0.0 ic2 = 100.0, 100.0, 0.0 ic3 = 0.0, 100.0, 0.0 ## note: throughout this sample, many function return values are ignored. ## specifically: mgNewRec, mgAttach, mgInsert, mgSetVtxCoord, mgSetComment, ## mgDeleteComment, etc ## normally, you should pay attention to these values and consider appropriate ## action upon function failures. ## # check for proper arguments if len(sys.argv) < 2: print("\nUsage: %s <create_db_filename>\n" % (sys.argv[0])) print(" Creates database: <create_db_filename>\n") print(" Creates a simple hierarchy with groups, an object and a polygon\n") print(" Sets the comment fields of each\n") print("\n") return # initialize the OpenFlight API # always call mgInit BEFORE any other OpenFlight API calls # mgInit (None, None) # start a new OpenFlight database, overwrite if exists mgSetNewOverwriteFlag (MG_TRUE) print("\nCreating database: %s\n" % (sys.argv[1])) db = mgNewDb (sys.argv[1]) if db == None: msgbuf = mgGetLastError() print(msgbuf, "\n") mgExit() return # create simple hierarchy group = mgNewRec (fltGroup) ok = mgAttach (db, group) object = mgNewRec (fltObject) ok = mgAttach (group, object) # add group comment ok = mgSetComment (group, "This is the group comment") comment = mgGetComment (group) print("Group Comment: <%s>\n" % (comment)) # add object comment ok = mgSetComment (object, "This is the object comment") comment = mgGetComment (object) print("Object Comment: <%s>\n" % (comment)) # create polygon, add comment polygon = mgNewRec (fltPolygon) ok = mgAttach (object, polygon) ok = mgSetComment (polygon, "This is the polygon comment") comment = mgGetComment (polygon) print("Polygon Comment: <%s>\n" % (comment)) # remove polygon comment ok = mgDeleteComment (polygon) comment = mgGetComment (polygon) print("Polygon Comment after delete: <%s>\n" % (comment)) # create vertices, add comment to first vertex vertex = mgNewRec (fltVertex) ok = mgAttach (polygon, vertex) ok = mgSetVtxCoord (vertex, ic0[0], ic0[1], ic0[2]) ok = mgSetComment (vertex, "This is the first vertex comment") afterVertex = vertex vertex = mgNewRec (fltVertex) ok = mgInsert (afterVertex, vertex) ok = mgSetVtxCoord (vertex, ic1[0], ic1[1], ic1[2]) afterVertex = vertex vertex = mgNewRec (fltVertex) ok = mgInsert (afterVertex, vertex) ok = mgSetVtxCoord (vertex, ic2[0], ic2[1], ic2[2]) afterVertex = vertex vertex = mgNewRec (fltVertex) ok = mgInsert (afterVertex, vertex) ok = mgSetVtxCoord (vertex, ic3[0], ic3[1], ic3[2]) # create Xref print ('try to do something here') group2 = mgNewRec (fltGroup) mgSetName(group2, "my_new_group") ok = mgAttach (group2, db) if ok == MG_FALSE: print(mgGetLastError (), "\n") xRef = mgNewRec (fltXref) #mgSetAttList(xRef, "./res_90.flt") ok = mgAttach(group2, xRef) if ok == MG_FALSE: print(mgGetLastError (), "\n") # write and close the database ok = mgWriteDb (db) if ok == MG_FALSE: print("Error writing database\n") ok = mgCloseDb (db) if ok == MG_FALSE: print("Error closing database\n") # always call mgExit() AFTER all OpenFlight API calls mgExit () main()
Please help, I am stuck without this after all. Thx.
Adding a note to this that it's been resolved ;)
Shawn
I've borrowed the sample file egnew1.py to make a new script to create a new group inside an existing flt file, then create/add a transform record to assign an offset (x,y) and attach that to my group, and then I want the group to reference an external record.
I've done it wrong, because I get this error:
abblip.py: mgSetAttList (xRef, "./blip.flt")
Here's the code:
Where did I go wrong? Thx