RequestDataOnSimObject returns exception

Hi, I’m trying to read the ObjectID following the creation of an object using
AICreateSimulatedObject. This is an extract from the SimConnect Debug Log.

> 1458.77925 [342, 6]AICreateSimulatedObject:szContainerTitle="Ambulance03", InitPos=1119350480, RequestID=5
< 1458.78427 [342] AssignedObjectID: RequestID=5  ObjectID=438
> 1458.78480 [342, 7]RequestDataOnSimObjectType:RequestID=5, DefineID=1, dwRadiusMeters=100000, type=5
< 1458.78553 [342] >>>>>  EXCEPTION=3, SendID=7, Index=2  <<<<<

I should add that the object is created without any problem, it just keeps
wandering off on it’s own little journey down the hill! Basically, I’m trying
to read the ObjectID to then send some waypoints. I’m using the Python
SimConnect library coupled with the Python MobiFlight WASM Module. Any help
greatly appreciated!

Hi, I think you actually got the use-case of RequestDataOnSimObjectType()
wrong. What you’d normally do in your case is listening to
SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID in your SimConnect dispatch procedure
after the SimConnect_AICreateSimulatedObject() call. Once that comes in, you
cast the SIMCONNECT_RECV* into SIMCONNECT_RECV_ASSIGNED_OBJECT_ID*. From that
you can finally match your RequestId and get an ObjectId that you can then use
in later calls…like to send a list of waypoints. Greets, Ben

Hi Ben, That’s brilliant thanks! Completely misread that bit of the SDK docs!
For those of you using Python SimConnect here is what I’ve done in a very
hacky kinda way: 1. Add a new elif clause to the my_dispatch_proc function in
SimConnect.py

elif dwID == SIMCONNECT_RECV_ID.SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID:
            pObjData = cast(
                pData, POINTER(SIMCONNECT_RECV_ASSIGNED_OBJECT_ID)
            ).contents
            objectId = pObjData.dwObjectID
            os.environ["OBJECT_ID"] = str(objectId)

2. Create a Sim Object using AICreateSimulatedObject:

def createSimulatedObject(self, name, lat, lon, rqst, hdg=0, gnd=1, alt=0, pitch=0, bank=0, speed=0):
        simInitPos = SIMCONNECT_DATA_INITPOSITION()
        simInitPos.Altitude = alt
        simInitPos.Latitude = lat
        simInitPos.Longitude = lon
        simInitPos.Pitch = pitch
        simInitPos.Bank = bank
        simInitPos.Heading = hdg
        simInitPos.OnGround = gnd
        simInitPos.Airspeed = speed
        self.dll.AICreateSimulatedObject(
            self.hSimConnect,
            name.encode(),
            simInitPos,
            rqst.value
        )

3. Sleep for 1 second and then print the os.environ[“OBJECT_ID”] Definitely
isn’t the prettiest code but works for what I need! Chris