Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

[microstation connect update4 MDL c++] SolidUtil::Create::BodyFromLoft failed in my program, why?

$
0
0
extract boundary curves from top and bottom b-surface, and then making b-surface with the two boundary curves failed, please give me a reasion, DGN file in attachment below,  my code as follow:
 CurveVectorPtr profileVec[2];
 // 1. extract the first boundary curves from b-surface
 {
  ElementId id = 6772;
  std::vector<MSElementDescrP> elemVec;
  DgnModelRefP model = ISessionMgr::GetManager().GetActiveDgnModelRefP();
  for each (ElementHandle elem in model->GetReachableElements())
  {
   if (elem.GetElementId() == id) // bspline surface
   {
    MSElementDescrP tmp = 0;
    mdlAssoc_getElementDescr(&tmp, NULL, elem.GetElementId(), ACTIVEMODEL, FALSE);
    elemVec.push_back(tmp);
   }
  }
  if (elemVec.size() != 1)
   return ;
  MSElementDescrP edp = elemVec[0];
  ElementHandle eh(edp, true, true);
  ISolidKernelEntityPtr out;
  if (SUCCESS != SolidUtil::Convert::ElementToBody(out, eh))
  {
   WString messageInfo = L"ElementToBody failed.";
   mdlDialog_openInfoBox(messageInfo.c_str());
   return ;
  }
  ISolidKernelEntity::KernelEntityType typ = out->GetEntityType();
  if (typ != ISolidKernelEntity::KernelEntityType::EntityType_Sheet)
  {
   mdlDialog_openInfoBox(L"not EntityType_Sheet");
   return ;
  }
  SolidUtil::Debug::DumpEntity(*out, L"12");
  bvector<ISubEntityPtr> subEntities;
  size_t nEdges = SolidUtil::GetBodyEdges(&subEntities, *out);
  if (nEdges != subEntities.size())
  {
   WString messageInfo = L"GetBodyEdges failed.";
   mdlDialog_openInfoBox(messageInfo.c_str());
   return ;
  }
  profileVec[0] = CurveVector::Create(CurveVector::BOUNDARY_TYPE_Open);
  for (int i = 0; i < subEntities.size(); i++)
  {
   CurveVectorPtr cvp;
   if (SUCCESS != SolidUtil::Convert::SubEntityToCurveVector(cvp, *(subEntities[i].get())))
   {
    mdlDialog_openInfoBox(L"SubEntityToCurveVector failed.");
    return;
   }
  
   profileVec[0]->Add(cvp);
  }
 }
//
 // extract the second boundary curves from b-surface
//
 {
  ElementId id = 6713;
  std::vector<MSElementDescrP> elemVec;
  DgnModelRefP model = ISessionMgr::GetManager().GetActiveDgnModelRefP();
  for each (ElementHandle elem in model->GetReachableElements())
  {
   if (elem.GetElementId() == id) // bspline surface
   {
    MSElementDescrP tmp = 0;
    mdlAssoc_getElementDescr(&tmp, NULL, elem.GetElementId(), ACTIVEMODEL, FALSE);
    elemVec.push_back(tmp);
   }
  }
  if (elemVec.size() != 1)
   return;
  MSElementDescrP edp = elemVec[0];
  ElementHandle eh(edp, true, true);
  ISolidKernelEntityPtr out;
  if (SUCCESS != SolidUtil::Convert::ElementToBody(out, eh))
  {
   WString messageInfo = L"ElementToBody failed.";
   mdlDialog_openInfoBox(messageInfo.c_str());
   return;
  }
  ISolidKernelEntity::KernelEntityType typ = out->GetEntityType();
  if (typ != ISolidKernelEntity::KernelEntityType::EntityType_Sheet)
  {
   mdlDialog_openInfoBox(L"not EntityType_Sheet");
   return;
  }
  SolidUtil::Debug::DumpEntity(*out, L"12");
  bvector<ISubEntityPtr> subEntities;
  size_t nEdges = SolidUtil::GetBodyEdges(&subEntities, *out);
  if (nEdges != subEntities.size())
  {
   WString messageInfo = L"GetBodyEdges failed.";
   mdlDialog_openInfoBox(messageInfo.c_str());
   return;
  }
  profileVec[1] = CurveVector::Create(CurveVector::BOUNDARY_TYPE_Open);
  for (int i = 0; i < subEntities.size(); i++)
  {
   CurveVectorPtr cvp;
   if (SUCCESS != SolidUtil::Convert::SubEntityToCurveVector(cvp, *(subEntities[i].get())))
   {
    mdlDialog_openInfoBox(L"SubEntityToCurveVector failed.");
    return;
   }
   profileVec[1]->Add(cvp);
  }
 }
 //  ----- create guide line
 bvector <DPoint3d> profilePts;
 profilePts.push_back({ 53568, 398560, 237 });
 profilePts.push_back({ 53568, 398560, 306 });
 CurveVectorPtr guideVec = CurveVector::CreateLinear(profilePts, CurveVector::BOUNDARY_TYPE_Outer);

 // 3 ---- Create Solid by Loft
 ISolidKernelEntityPtr solid;
 DgnModelP             pActiveModel = ISessionMgr::GetActiveDgnModelP();
 if (SUCCESS != SolidUtil::Create::BodyFromLoft(solid, profileVec, 2, &guideVec, 1, *pActiveModel, false, true))
 {
  mdlDialog_dmsgsPrint(L"Error in BodyFromLoft");
  return;
 }
 // 4 ---- Convert Solid to EditElementHandle and add it to model
 if (solid.IsValid())
 {
  EditElementHandle eeh;
  SolidUtil::Convert::BodyToElement(eeh, *solid, nullptr, *pActiveModel);
  //DraftingElementSchema::ToElement(eeh, *solid, nullptr, *pActiveModel);
  eeh.AddToModel();
 }
(Please visit the site to view this file)

Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>