Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hello,
I have to create Group like in the picture. I have to fill it with some parts model. I tried with
ProLocalGroupCreate((ProSolid) assembly_mdl,part_mdl_id,model_number,L"COMPONENTS_TOP",&localGroup);
ProModelitemNameSet(&localGroup,L"COMPONENTS_TOP");
/* Refresh the tree tool */
ProTreetoolRefresh(asm_mdl);
but nothing was created.
Can you help me please? Thank you very much.
@MichelH @YaroslavSin @rghadge
Solved! Go to Solution.
I don't see anything wrong in your sample code except variable names are incorrectly initialized compared to what you have passed to API.
Yes, you can ignore using ProSelect() if you have array of assembly component feature Ids already. In such case refer below sample code (working at my end):
status = ProMdlCurrentGet(&currMdl);
if(status != PRO_TK_NO_ERROR)
return status;
int *p_feat_id_array;
ProArrayAlloc(0, sizeof(int), 1, (ProArray*)&p_feat_id_array);
int featIDs[] = {40, 41}; //Array of feature Ids
int nFeatIds = { sizeof(featIDs) / sizeof(featIDs[0]) };
for (int i = 0; i < nFeatIds; i++)
{
ProArrayObjectAdd((ProArray*)&p_feat_id_array, PRO_VALUE_UNUSED, 1, &featIDs[i]);
}
ProName w_name = L"COMPONENTS_TOP";
ProGroup r_group;
status = ProLocalGroupCreate((ProSolid)currMdl, p_feat_id_array, nFeatIds, w_name, &r_group);
ProArrayFree((ProArray*)&p_feat_id_array);
ProTreetoolRefresh(currMdl);
Hope this helps. Happy weekend! 😊
Please try below sample code which I just created for you. It is working fine at my end:
ProError CreateLocalGroup ()
{
ProError status = PRO_TK_GENERAL_ERROR;
ProMdl currMdl;
ProSelection *sels;
int nSels = -1;
status = ProMdlCurrentGet(&currMdl);
if(status != PRO_TK_NO_ERROR)
return status;
status = ProSelect("component", -1, NULL, NULL, NULL, NULL, &sels, &nSels);
if (status != PRO_TK_NO_ERROR)
return status;
int *p_feat_id_array;
ProModelitem component;
ProArrayAlloc(0, sizeof(int), 1, (ProArray *)&p_feat_id_array);
for (int i = 0; i < nSels; i++)
{
status = ProSelectionModelitemGet(sels[i], &component);
ProArrayObjectAdd((ProArray*)&p_feat_id_array, PRO_VALUE_UNUSED, 1, &component.id);
}
ProName w_name = L"COMPONENTS_TOP";
ProGroup r_group;
status = ProLocalGroupCreate((ProSolid)component.owner, p_feat_id_array, nSels, w_name, &r_group);
ProArrayFree((ProArray*)&p_feat_id_array);
ProTreetoolRefresh(component.owner);
return status;
}
Thank you for your help!
But I still need help. I am not comfortable using ProSelect.
Anyway, I already have list of model, modelItem and an assembly.
I tried:
ProName g_name = L"COMPONENTS_TOP";
ProGroup t_Group;
ProLocalGroupCreate((ProSolid) asm_mdl,p_feat_id_array,num_refs,w_name,&r_group);
asm_mdl: the assembly in which the group shall be created.
p_feat_id_array: modelItem Id
num_refs: number of modelitem
w_name: the group name
but still nothiing happens. Where am I doing wrong? There is no error but the group is not created after ProTreetoolRefresh(asm_mdl);
I don't see anything wrong in your sample code except variable names are incorrectly initialized compared to what you have passed to API.
Yes, you can ignore using ProSelect() if you have array of assembly component feature Ids already. In such case refer below sample code (working at my end):
status = ProMdlCurrentGet(&currMdl);
if(status != PRO_TK_NO_ERROR)
return status;
int *p_feat_id_array;
ProArrayAlloc(0, sizeof(int), 1, (ProArray*)&p_feat_id_array);
int featIDs[] = {40, 41}; //Array of feature Ids
int nFeatIds = { sizeof(featIDs) / sizeof(featIDs[0]) };
for (int i = 0; i < nFeatIds; i++)
{
ProArrayObjectAdd((ProArray*)&p_feat_id_array, PRO_VALUE_UNUSED, 1, &featIDs[i]);
}
ProName w_name = L"COMPONENTS_TOP";
ProGroup r_group;
status = ProLocalGroupCreate((ProSolid)currMdl, p_feat_id_array, nFeatIds, w_name, &r_group);
ProArrayFree((ProArray*)&p_feat_id_array);
ProTreetoolRefresh(currMdl);
Hope this helps. Happy weekend! 😊
Thank you very much!!! It helps me.