Depends what version of Revit you are using.
For 2023 and onwards you would have to use the AnalyticalToPhysicalAssociationManager within the Structure namespace and that would only report items where the association has been made.
So if you wanted to get the analytical stick of a framing member and one didn't exist you could in theory create one and associate it before returning the stick. Although the workflow in 2023 and on currently is to periodically generate the analytical model from physical using a Dynamo script.
The analytical model isn't automatically generated and maintained in the background anymore.