Page 1 of 1
GetParent
Posted: Fri Feb 22, 2019 10:07 am
by Jonny
Hello dear.
Why there is no method GetParent for IEntity_DG?
In 5.2 this method was present for ISection.
Thanks.
Re: GetParent
Posted: Mon Feb 25, 2019 2:44 am
by Prashant Kande
In DGK entities can be shared between models, so an entity can have more than one parent. But the assumption is that within a model an entity is unique. I am not sure this is enforced throughout, but I would not recommend adding the an entity to different parents within one model. It does not make sense anyway as visually and geometrically it will be the same object. A standalone (not in a model) copy of an entity can be created with IEntity_DG.Clone()
If you specify a model then yes an entity can have only one parent. To get this parent use IModel_DG.BuildChildToParentMap()
http://www.dynoinsight.com/Help/V6_0/In ... oParentMap or similar method for IEntity_DG.
Re: GetParent
Posted: Fri Mar 01, 2019 2:22 am
by Prashant Kande
This is how we test BuildChildToParentMap():
Code: Select all
void TestBuildChildToParentMap()
{
....
IModel_DGPtr iModel_DG;
model.QueryInterface(__uuidof(IModel_DG), (void**)&iModel_DG);
IMapUnkn_DGPtr map;
iModel_DG->BuildChildToParentMap(&map);
// Get flat array of all independently of child/parent
IEntityArray_DGPtr entities;
iModel_DG->GetEntityArray(VARIANT_TRUE, &entities);
int n = 0;
entities->GetCount(&n);
for (int i = 0; i < n; i++)
{
IEntity_DGPtr iEntity;
entities->GetAt(i, &iEntity);
IObject_DG* iObject = nullptr;
iEntity->QueryInterface(__uuidof(IObject_DG), (void**)&iObject);
__int64 hash = 0;
iObject->GetHash(&hash);
int nChildren = 0;
iEntity->GetChildCount(&nChildren);
for (int k = 0; k < nChildren; k++)
{
IEntity_DGPtr iEntityChild;
iEntity->GetChildAt(k, &iEntityChild);
IUnknown* iResult = nullptr;
map->GetAt(iEntityChild, &iResult);
IEntity_DGPtr iEntityResult;
iResult->QueryInterface(__uuidof(IEntity_DG), (void**)&iEntityResult);
Entity* pEntInv = nullptr;
iEntityResult->QueryInterface(IID_IInverse, (void**)&pEntInv);
IObject_DG* iObjectChild = nullptr;
iEntityResult->QueryInterface(__uuidof(IObject_DG), (void**)&iObjectChild);
VARIANT_BOOL same = VARIANT_FALSE;
iObjectChild->IsSameInstance(iObject, &same);
assert(same == VARIANT_TRUE);
// Hash must be the same also (testing hash):
__int64 hashChild = 0;
iObjectChild->GetHash(&hashChild);
assert(hashChild == hash);
RELEASE(iObjectChild); RELEASE(iEntityResult); RELEASE(iEntityChild);
}
RELEASE(iObject); RELEASE(iEntity);
}
RELEASE(entities); RELEASE(map);
}