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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Datum points

Sss4598
12-Amethyst

Datum points

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.

 

 

 

17 REPLIES 17
GabrielZaha
13-Aquamarine
(To:Sss4598)

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.

 

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?

GabrielZaha
13-Aquamarine
(To:Sss4598)

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

 

Hi,

Thank you for the code.

 

I am facing issue in providing assembly component path in ProSelectionAlloc. I have a skeleton and I have a datum feature in it. Can you please help me how should I mention this ProAsmComppath?

 

TIA

RPN
17-Peridot
17-Peridot
(To:Sss4598)

I guess this could be helpful 

 

extern ProError ProSelectionPoint3dSet( ProPoint3d point,
ProSelection *p_prosel);
/*
Purpose: Uses user-provided ProPoint3d to set the selected-point of the ProSelection.

Input Arguments:
point - User-provided ProPoint3d.
p_prosel - Pointer to user-provided ProSelection.

Output Arguments:
none

Return Values:
PRO_TK_NO_ERROR - The function successfully set the selected-point
of the ProSelection.
PRO_TK_BAD_INPUTS - One of the arguments is NULL.

*/

Sss4598
12-Amethyst
(To:RPN)

My code is working when I try it on a part but when I try it on assembly it shows error. And the error is when I have part I enter the ProAsmComppath as NULL but when it's assembly it will fail. So I am just trying to provide comppath of this skeleton. But I am unable to find correct way to provide this path in ProSelectionAlloc. 

RPN
17-Peridot
17-Peridot
(To:Sss4598)

For the Skelton the size of the path is 1 and the id is the component feature ID within the assembly. 

Sss4598
12-Amethyst
(To:RPN)

Is there a method to retrieve this comppath and assign it to a ProAsmComppath variable. Then this variable I will pass it into ProSelectionAlloc. If I just give it a array in ProSelectionAlloc it shows error. Type int variable not suitable.

 

How do I provide path in ProSelectionAlloc?

RPN
17-Peridot
17-Peridot
(To:Sss4598)

ProSelectionAlloc Is just a helper function,

see ProSelectionSet. It is a struct,  containing a model item and optionally a path (okay for other fields they have other, not frequently used, getter and setter functions). 

 I guess internally it is still ProDevolp style. But as a developer you do not have longer access to each field. See old ProDevelop documentation for the list of values 

Again ProSelectionAlloc tells you only if your input is valid. 

GabrielZaha
13-Aquamarine
(To:Sss4598)

Please have a look at ProAsmcomppathInit function.

As RPN already mentioned, the memb_id_tab argument(2nd argument) is an array of integers containing the feature id of the skeleton and the size of the table(3rd argument) is 1.


@RPN wrote:

For the Skelton the size of the path is 1 and the id is the component feature ID within the assembly.


 

The issue I am facing is that my coordinate system is in another skeleton and my datum point is in another feature. I provide componnet path for the first skeleton to get the coordinate system .

 ProAsmCompathInit((ProSolid)assembly, (comp Id of firstskel), 1, comppath).

Then I pass this comppath to ProSelectionAlloc but it fails. What should I do when I have coordinate system in other skeleton and feature in another skeleton?

RPN
17-Peridot
17-Peridot
(To:Sss4598)

Your comp path must match the model item. And I don't understand your requirement. Because all the transformations are handled in the Assembly, Can you shed more lights on what you try to accomplish?

Sss4598
12-Amethyst
(To:RPN)

I have two different skeletons in my assembly, say Skeleton A and Skeleton B. I have my coordinate system in Skeleton A which is used for datum point feature in skeleton B. So while providing CS in PR0_E_DPOINT_OFT_CSYS_REF I provide path of first skeleton and in ProFeaturewithOptionRedefine I provide path of another skeleton by its ID. My application fails on ProSelectionAlloc in PR0_E_DPOINT_OFT_CSYS_REF section.

RPN
17-Peridot
17-Peridot
(To:Sss4598)

Maybe I still misunderstand your request, but the FEATURE is created in B, and your reference is in A. So your selection referee only to A for the feature in B 🙂

SS4598
14-Alexandrite
(To:RPN)

What I did is in PR0_E_DPOINT_OFT_CSYS_REF. I provide refernce to skeleton A (where Coordinate system is defined) and at end where I provide feature ProModelitemByNameInit I provided skeleton B as model item. The points are updated correctly but it does not select a coordinate system.

RPN
17-Peridot
17-Peridot
(To:SS4598)

It is still not easy to understand your task. But you can dump the model tree of an existing feature to a xml file, here you can compare your model tree and adjust your selection information. If you like share the xml from a manual created feature, the one you want to programmatically create. 

And with your selection. the model item, this provides a reference to a csys feature, a coordinate system, the model item ID is probably the geom ID (I guess it is not the feature ID) of this feature, and the owner is the skeleton. For the offset you must probably provide x,y and z. during creation in your feature tree. The path uniquely identifies the skeleton only. 
The model where you create the feature, is part of the creation method. 


The code:

 

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

 Here you,specify the model,item and your path.

 

status = ProSelectionAlloc(NULL, &ref_datum, &p_select);

	status = ProSelectionToReference(p_select, &reference);

This is not enough for you!

 

I’m not sure, but you create a feature in an active assembly, maybe you must supply the path at the end as well, but I’m not sure, because you can have the model assembled in different levels. So take care here.

 

 

################################################################################
########################### OFFSET CSYS DATUM POINT ############################
################################################################################
|--PRO_E_FEATURE_TYPE
|
|--PRO_E_DPOINT_TYPE
|
|--PRO_E_STD_FEATURE_NAME
|
|--PRO_E_DPOINT_OFST_CSYS_TYPE
|
|--PRO_E_DPOINT_OFST_CSYS_REF
|
|--PRO_E_DPOINT_OFST_CSYS_WITH_DIMS
|
|--PRO_E_DPOINT_OFST_CSYS_PNTS_ARRAY (Array of points within DP feature)
|--PRO_E_DPOINT_OFST_CSYS_PNT
|--PRO_E_DPOINT_OFST_CSYS_PNT_NAME

 

 

 

================================================================================
Element Id Element Name Data Type
================================================================================
PRO_E_FEATURE_TYPE Feature Type PRO_VALUE_TYPE_INT
PRO_E_DPOINT_TYPE Datum Point Type PRO_VALUE_TYPE_INT
PRO_E_STD_FEATURE_NAME Feature Name PRO_VALUE_TYPE_WSTRING
PRO_E_DPOINT_OFST_CSYS_TYPE Reference Csys Type PRO_VALUE_TYPE_INT
PRO_E_DPOINT_OFST_CSYS_REF Reference Csys PRO_VALUE_TYPE_SELECTION
PRO_E_DPOINT_OFST_CSYS_WITH_DIMS Parametric/Explicit PRO_VALUE_TYPE_INT
with or without dims.
PRO_E_DPOINT_OFST_CSYS_PNTS_ARRAY Points List Array
PRO_E_DPOINT_OFST_CSYS_PNT One Point Compound
PRO_E_DPOINT_OFST_CSYS_PNT_NAME Point Name PRO_VALUE_TYPE_WSTRING
PRO_E_DPOINT_OFST_CSYS_DIR1_VAL X / R / RHO PRO_VALUE_TYPE_DOUBLE
PRO_E_DPOINT_OFST_CSYS_DIR2_VAL Y / THETA / PHI PRO_VALUE_TYPE_DOUBLE
PRO_E_DPOINT_OFST_CSYS_DIR3_VAL Z / Z / THETA PRO_VALUE_TYPE_DOUBL
|--PRO_E_DPOINT_OFST_CSYS_DIR1_VAL
|--PRO_E_DPOINT_OFST_CSYS_DIR2_VAL
|--PRO_E_DPOINT_OFST_CSYS_DIR3_VAL

 

 

PRO_E_DPOINT_OFST_CSYS_REF This is just the csys modelitem plus the path to this model.

RPN
17-Peridot
17-Peridot
(To:Sss4598)

As FV already mentioned use ProMdlIsSkeleton. Another simple way can be to implement your own visit filter function for feature IDs, here you check for a component, if the component is a part, check if this one is a skeleton, and return the array, or just the component ID, where your filter match. As I currently understand, you don’t need to traverse the assembly. 

Announcements


Top Tags