cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Create Group in assembly with Creo upper 4.0 M090

JD_2779181
9-Granite

Create Group in assembly with Creo upper 4.0 M090

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 

 

finalresultCreo.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
rghadge
15-Moonstone
(To:JD_2779181)

@JD_2779181,

 

I don't see anything wrong in your sample code except variable names are incorrectly initialized compared to what you have passed to API.

rghadge_0-1637331628463.png

 

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! 😊

View solution in original post

4 REPLIES 4
rghadge
15-Moonstone
(To:JD_2779181)

@JD_2779181 ,

 

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);

rghadge
15-Moonstone
(To:JD_2779181)

@JD_2779181,

 

I don't see anything wrong in your sample code except variable names are incorrectly initialized compared to what you have passed to API.

rghadge_0-1637331628463.png

 

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.

Top Tags