Start a new topic

mgHasAtt() bug

Original Post by: bcunnin Tue Sep 22 15:06:33 2009

I found a bug in mgHasAtt() in the python API

When I tried to see if a coord3d node has its usual attribute the mgHasAtt said it didnt have it,

but then I use the mgGetAttList on all three of the attributes and it gets them just fine

Attached is a pic of code I used to reproduce the bug

The only thing the OpenFightUtil.collectNodes() does is go through a .flt file and checks the code on the record and if it matches what is passed in adds the node to a list

This also worked on the b52.flt sample data

1 Comment

Original Post by: SteveThompson Tue Sep 22 16:33:50 2009

First, mgHasAtt is intended to be called to ask if one record contains another record (not field). You are using it to see if a record contains a field. fltCoord3dX, fltCoord3dY and fltCoord3dZ are "fields" of record fltCoord3d, not records.

Attached is a screen shot of the help docs for mgHasAtt to clarify.

Second, you should rarely have to use mgGetAttRec. In your case you DO NOT have to get the fltCoord3d record from the vertex before accessing the nested fields in the fltCoord3d record. Instead (and much simpler) you can simply get the nested fields directly from the root record. In other words mgGetAttList will look for the field you ask for first in the root record, then in all nested records (recursively). Again, this makes your code much simpler.

For example, in your code, you write (paraphrased a bit):

aCoord = mgGetAttRec(vtx)

returnVals = mgGetAttList(aCoord, fltCoord3dX, fltCoord3dY, fltCoord3dZ)

Instead, you can simply write:

returnVals = mgGetAttList(vtx, fltCoord3dX, fltCoord3dY, fltCoord3dZ)

As noted above, mgGetAttList will look in all nested records of vtx for fields fltCoord3dX, fltCoord3dY, fltCoord3dZ.

Also, there is another (and IMO simpler) way to use mgGetAttList in python:

num,code,x,code,y,code,z = mgGetAttList(vtx, 

fltCoord3dX, fltCoord3dY, fltCoord3dZ)

# num = number of attributes retrieved

# code = fltCoord3dX returned to caller (fltCoord3dY and fltCoord3dZ too)

# x = value of fltCoord3dX

# y = value of fltCoord3dY

# z = value of fltCoord3dZ

Finally, to take this one step further (in the case of extracting a vertex position) you can (even more simply) call:

b,x,y,z = mgGetVtxCoord (vtx)

# b = MG_TRUE if successful, MG_FALSE otherwise

# x = value of fltCoord3dX

# y = value of fltCoord3dY

# z = value of fltCoord3dZ

Login to post a comment