Skip to main content
12-Amethyst
August 6, 2024
Question

Datum points

  • August 6, 2024
  • 1 reply
  • 3792 views

Hello all,

 

 

I am trying to import datum points from .pts file stored using Toolkit C++.

 

I am loading the pts data using WfcIntfPTS and also getting feature using GetFeaturebyId(). 

 

I am unable to find method to assign this imported pts file to the the feature.

Can anyone suggest me the method to do so? 

 

 

Or can suggest me method to import this .pts file and assign it to datum points feature.

 

 

 

1 reply

14-Alexandrite
August 6, 2024

I think there are two possibilities here:

Use the ProDatumcurveFromfileCreate() function or wfcWSolid::ImportAsFeat for OTK. It is described in the Interface: Importing Features chapter in the toolkit user guide.Personally I never used this function and I don't know how well it works.

 

The other option is to generate the datum point element tree. Look for chapter Element Trees: Datum Features section Datum Point Features / Offset Csys Datum Point section in user guide.

This will require to read the pts file line by line, filter out the comment lines and build the array of points. There is an example available: UgOffsetPointCreate.c located at <creo_toolkit_loadpoint>/protk_appls/pt_userguide/ptu_featcreat

The code is more elaborate but it has the advantage that can be used for new features or to redefine existing features and it works really well.

 

Sss459812-AmethystAuthor
12-Amethyst
August 9, 2024

Hello,

 

I am now able to read .pts file and build an array of points. But cannot find a way how can I redefine the existing datumpoints.

My concept is to get the feature by ID and which will return me ProFeature feature and then I will update this points by passing the array of points in to that feature.

 

 

Can you suggest me any way how can I retrieve feature ID or redefine existing points?

14-Alexandrite
August 9, 2024

I start by building the element tree of the feature.

Once the element tree is done, if I want to redefine an existing feature I get the feature handle using ProFeatureInit or ProModelitemByNameInit.

Personally I prefer ProModelitemByNameInit but that is just personal preference.

Next I call ProFeatureWithoptionsRedefine.

If I need to create a new feature I'm calling ProFeatureWithoptionsCreate.

 

Here is an example of the function I'm using in one of my projects. The arguments are the model handle, the array of points and the name of the feature that I want to modify.

In this example first I'm trying to redefine the feature. If the call to ProModelitemByNameInit returns PRO_TK_E_NOT_FOUND it will create a new feature.

 

ProError PointsFromArray(ProMdl model, ProVector* pointList, ProName featname)
{
	ProError status;
	int k;
	int nrPoints;
	ProSelection p_select;

	ProErrorlist errors;
	ProModelitem model_item, ref_datum;
	ProSelection model_sel;
	ProFeature feature;
	ProFeatureCreateOptions* opts;
	ProReference reference;

	ProElement pro_e_feature_tree;
	ProElement pro_e_feature_type;
	ProElement pro_e_feature_name;
	ProElement pro_e_dpoint_type;
	ProElement pro_e_dpoint_ofst_csys_type;
	ProElement pro_e_dpoint_ofst_csys_ref;
	ProElement pro_e_dpoint_ofst_csys_with_dims;
	ProElement pro_e_dpoint_ofst_csys_pnts_array;
	ProElement pro_e_dpoint_ofst_csys_pnt;
	ProElement pro_e_dpoint_ofst_csys_pnt_name;
	ProElement pro_e_dpoint_ofst_csys_dir1_val;
	ProElement pro_e_dpoint_ofst_csys_dir2_val;
	ProElement pro_e_dpoint_ofst_csys_dir3_val;

	// Begin creation of datum point feature element tree
	// Populating root element PRO_E_FEATURE_TREE
	status = ProElementAlloc(PRO_E_FEATURE_TREE, &pro_e_feature_tree);

	// Populating element PRO_E_FEATURE_TYPE
	status = ProElementAlloc(PRO_E_FEATURE_TYPE, &pro_e_feature_type);
	status = ProElementIntegerSet(pro_e_feature_type, PRO_FEAT_DATUM_POINT);
	status = ProElemtreeElementAdd(pro_e_feature_tree, NULL, pro_e_feature_type);

	// Populating element PRO_E_DPOINT_TYPE
	status = ProElementAlloc(PRO_E_DPOINT_TYPE, &pro_e_dpoint_type);
	status = ProElementIntegerSet(pro_e_dpoint_type, PRO_DPOINT_TYPE_OFFSET_CSYS);
	status = ProElemtreeElementAdd(pro_e_feature_tree, NULL, pro_e_dpoint_type);

	// Populating element PRO_E_DPOINT_OFST_CSYS_TYPE
	status = ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_TYPE, &pro_e_dpoint_ofst_csys_type);
	status = ProElementIntegerSet(pro_e_dpoint_ofst_csys_type, PRO_VALUE_TYPE_INT);
	status = ProElemtreeElementAdd(pro_e_feature_tree, NULL, pro_e_dpoint_ofst_csys_type);

	// Populating element PRO_E_DPOINT_OFST_CSYS_REF
	status = ProModelitemByNameInit(model, PRO_CSYS, L"CS0", &ref_datum);
	status = ProSelectionAlloc(NULL, &ref_datum, &p_select);

	status = ProSelectionToReference(p_select, &reference);
	status = ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_REF, &pro_e_dpoint_ofst_csys_ref);
	status = ProElementReferenceSet(pro_e_dpoint_ofst_csys_ref, reference);
	status = ProElemtreeElementAdd(pro_e_feature_tree, NULL, pro_e_dpoint_ofst_csys_ref);

	// Populating element PRO_E_DPOINT_OFST_CSYS_WITH_DIMS
	status = ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_WITH_DIMS, &pro_e_dpoint_ofst_csys_with_dims);
	status = ProElementIntegerSet(pro_e_dpoint_ofst_csys_with_dims, PRO_B_TRUE);
	status = ProElemtreeElementAdd(pro_e_feature_tree, NULL, pro_e_dpoint_ofst_csys_with_dims);

	// Populating array element PRO_E_DPOINT_OFST_CSYS_PNTS_ARRAY
	status = ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_PNTS_ARRAY, &pro_e_dpoint_ofst_csys_pnts_array);

	status = ProArraySizeGet((ProArray)pointList, &nrPoints);
	for (k = 0; k < nrPoints; k++)
	{
		// Populating element PRO_E_DPOINT_OFST_CSYS_PNTS_ARRAY -> PRO_E_DPOINT_OFST_CSYS_PNT
		status = ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_PNT, &pro_e_dpoint_ofst_csys_pnt);

		status = ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_DIR1_VAL, &pro_e_dpoint_ofst_csys_dir1_val);
		status = ProElementDoubleSet(pro_e_dpoint_ofst_csys_dir1_val, pointList[k][0]);
		status = ProElemtreeElementAdd(pro_e_dpoint_ofst_csys_pnt, NULL, pro_e_dpoint_ofst_csys_dir1_val);

		status = ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_DIR2_VAL, &pro_e_dpoint_ofst_csys_dir2_val);
		status = ProElementDoubleSet(pro_e_dpoint_ofst_csys_dir2_val, pointList[k][1]);
		status = ProElemtreeElementAdd(pro_e_dpoint_ofst_csys_pnt, NULL, pro_e_dpoint_ofst_csys_dir2_val);

		status = ProElementAlloc(PRO_E_DPOINT_OFST_CSYS_DIR3_VAL, &pro_e_dpoint_ofst_csys_dir3_val);
		status = ProElementDoubleSet(pro_e_dpoint_ofst_csys_dir3_val, pointList[k][2]);
		status = ProElemtreeElementAdd(pro_e_dpoint_ofst_csys_pnt, NULL, pro_e_dpoint_ofst_csys_dir3_val);

		status = ProElemtreeElementAdd(pro_e_dpoint_ofst_csys_pnts_array, NULL, pro_e_dpoint_ofst_csys_pnt);
	}
	// End point element tree
	status = ProElemtreeElementAdd(pro_e_feature_tree, NULL, pro_e_dpoint_ofst_csys_pnts_array);

	// Redefining the feature in the current model.
	status = ProArrayAlloc(1, sizeof(ProFeatureCreateOptions), 1, (ProArray*)&opts);
	opts[0] = PRO_FEAT_CR_DEFINE_MISS_ELEMS;
	status = ProModelitemByNameInit(model, PRO_FEATURE, featname, &feature);
	if (status == PRO_TK_NO_ERROR)
	{
		status = ProFeatureWithoptionsRedefine(NULL, &feature, pro_e_feature_tree, opts, PRO_REGEN_NO_FLAGS, &errors);
	}
	else if (status == PRO_TK_E_NOT_FOUND)
	{
		status = ProElementAlloc(PRO_E_STD_FEATURE_NAME, &pro_e_feature_name);
		status = ProElementWstringSet(pro_e_feature_name, featname);
		status = ProElemtreeElementAdd(pro_e_feature_tree, NULL, pro_e_feature_name);

		status = ProMdlToModelitem(model, &model_item);
		status = ProSelectionAlloc(NULL, &model_item, &model_sel);
		opts[0] = PRO_FEAT_CR_DEFINE_MISS_ELEMS;
		status = ProFeatureWithoptionsCreate(model_sel, pro_e_feature_tree, opts, 1, &feature, &errors);
	}

	ProElementFree(&pro_e_feature_tree);
	return (status);
}