Some functions in the Microstation CONNECT API require an argument of type DgnModelCR. I usually have access to the DgnModelRefP of a model. How do I convert this to DgnModelCR?
Here is my code:
// find sheet named boundaries DgnModelRefP activeModelRefP = mdlModelRef_getActive(); DgnModelCR activeModelCR = *activeModelRefP->AsDgnModelCP(); NamedBoundaryCollectionPtr collection = NamedBoundaryCollection::Create(activeModelCR); boundaryCount = collection->GetCount(); for (NamedBoundaryCollection::const_iterator iter = collection->begin(); iter != collection->end(); ++iter) { WString name = (*iter)->GetName(); ElementHandle elemHandle = (*iter)->GetGraphicalElement(); MSElementCP elemCP = elemHandle.GetElementCP(); }
It compiles with no errors but I get a 0 for boundaryCount during runtime even though the model contains a drawing boundary. I think the activeModelCR is incorrectly defined.
Any suggestions?
Benzi Papo said: I think the activeModelCR is incorrectly defined
This article discusses the typedefs in the MicroStationAPI.
DgnModelCR is an alias of typedef of DgnModel generated by a macro in DgnPlatform.h. Once you dispense with the noise, you will see something like this:
DgnModelCR
DgnModel
DgnPlatform.h
typedef DgnModel& DgnModelR; typedef DgnModel const& DgnModelCR;
NamedBoundaryCollection::Create takes a DgnModel by const reference. What that tells you is the the function will not attempt to modify the DgnModel.
NamedBoundaryCollection::Create
const
Benzi Papo said:I'm not sure the casting is done correctly
You're declaring a variable of type const reference to the type you receive from a function. If the compiler is satisified then look to NamedBoundaryCollection::Create(). Unfortunately there is no example for named boundaries.
NamedBoundaryCollection::Create()
Regards, Jon Summers LA Solutions
I seem to have confused Named Boundary with Drawing Boundary. The following code actually runs as expected:
// find named boundaries DgnModelRefP activeModelRefP = mdlModelRef_getActive(); DgnModelCR activeModelCR = *activeModelRefP->GetDgnModelP(); NamedBoundaryCollectionPtr collection = NamedBoundaryCollection::Create(activeModelCR); boundaryCount = collection->GetCount(); for (NamedBoundaryCollection::const_iterator iter = collection->begin(); iter != collection->end(); ++iter) { WString name = (*iter)->GetName(); ElementHandle elemHandle = (*iter)->GetGraphicalElement(); MSElementCP elemCP = elemHandle.GetElementCP(); }
I was trying to access the Drawing Boundaries contained in a sheet model which requires different coding.
Thanks for helping me figure that out.