Unable to access instance: Length_unit

22 views
Skip to first unread message

Pravin Bhat

unread,
Jun 16, 2021, 5:58:34 PM6/16/21
to STEPcode - Developers Mailing List
I'm using latest build of StepCode with ap242 schemas. My input STEP file defines an instance of LENGTH_UNIT. In my code the following returns a non-null pointer as expected:
auto instance = stepInstances.GetApplication_instance("Length_unit");

However, the following returns a null pointer:
auto instance = dynamic_cast<SdaiLength_unit_ptr_c>(stepInstances.GetApplication_instance("Length_unit"));

Question #1: What should type should I be using while casting this instance to gain access to the underlying length unit representation?

To help find the instance type name I tried calling the function GetInstanceTypeName(...) defined in SDAI_DAObject_SDAI. However, it looks like this function in not implemented anywhere in the StepCode library, which causes the linker to raise "unresolved externals" error. 

Question #2:   How do I access the GetInstanceTypeName(...) function in StepCode library?

Thanks.

Christopher Sean Morrison

unread,
Jun 16, 2021, 8:34:22 PM6/16/21
to scl...@googlegroups.com


> On Jun 16, 2021, at 4:43 PM, Pravin Bhat <pro....@gmail.com> wrote:
>
> I'm using latest build of StepCode with ap242 schemas. My input STEP file defines an instance of LENGTH_UNIT. In my code the following returns a non-null pointer as expected:
> auto instance = stepInstances.GetApplication_instance("Length_unit");

It returns a SDAI_Application_instance*

> However, the following returns a null pointer:
> auto instance = dynamic_cast<SdaiLength_unit_ptr_c>(stepInstances.GetApplication_instance("Length_unit"));
>
> Question #1: What should type should I be using while casting this instance to gain access to the underlying length unit representation?

I’m not sure you can cast directly through from SDAI_Application_instance without some machinery in place, but you can introspect some things and construct off of it. We use a factory pattern in an AP203 converter, for example, where we map entities to Create() functions by name.

std::cout << "Name:" << sse->EntityName() << " ID:" << sse->STEPfile_id << std::endl;
if (sse->IsA(SCHEMA_NAMESPACE::e_length_unit)) ...

> To help find the instance type name I tried calling the function GetInstanceTypeName(...) defined in SDAI_DAObject_SDAI. However, it looks like this function in not implemented anywhere in the StepCode library, which causes the linker to raise "unresolved externals" error.
>
> Question #2: How do I access the GetInstanceTypeName(...) function in StepCode library?

That’s one of a handful of functions related to dynamic binding that are unimplemented. Relevant: https://github.com/stepcode/stepcode/issues/387
Maybe someone can chime in with better knowledge, but I think they’re a dynamic binding interface from ISO 10303-23 (SDAI C++) that was stubbed in but remains incomplete. I’d have to dig up my copy of AP 22 and 23 to be certain.

The related code API wraps them in SDAI_CPP_LATE_BINDING, but GetInstanceTypeName() curiously has ifndef and that’s probably a typo in the header.

Cheers!
Sean

Pravin Bhat

unread,
Jun 17, 2021, 5:59:01 PM6/17/21
to STEPcode - Developers Mailing List
Thanks Sean for your help. I have a couple of following up questions:

Following your advice I tried using introspection as follows:

    const auto lengthUnit = stepInstances.GetApplication_instance("Length_unit");
    if (lengthUnit->IsA(ap242_managed_model_based_3d_engineering_mim_lf::e_length_unit))
    {

    }

which results in the following linker error:
error LNK2001: unresolved external symbol "class EntityDescriptor * ap242_managed_model_based_3d_engineering_mim_lf::e_length_unit" (?e_length_unit@ap242_managed_model_based_3d_engineering_mim_lf@@3PEAVEntityDescriptor@@EA)
I haven't been able to figure out what I'm doing wrong yet. 


> We use a factory pattern in an AP203 converter, for example, where we map entities to Create() functions by name.
I could use an example of this factory pattern. Thanks.

Reply all
Reply to author
Forward
0 new messages