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

Is there any creo toolkit API to create default coordinate system (global coordinate system)?

Highlighted

Is there any creo toolkit API to create default coordinate system (global coordinate system)?

Hi All,

 

I have a model in which no default coordinate system present.

Is there any way to get or create default coordinate system(global coordinate system) using toolkit API?

7 REPLIES 7

Re: Is there any creo toolkit API to create default coordinate system (global coordinate system)?

There is not direct API / function to create a CSYS with Toolkit.

 

When you search create CSYS toolkit in the knowledge one can find this article :

https://www.ptc.com/en/support/article?n=CS221868 

 

Basically the methodology relies on Element Tree. 

Highlighted

Re: Is there any creo toolkit API to create default coordinate system (global coordinate system)?

in case lots of low level code is not your thing here are some options:

 

ProMacroLoad( L"~ Command `ProCmdDefDatumCsys`");
ProMacroExecute(); 

 would get you default coordinate systems...

 

Otherwise making a UDF from default csys feature and using ProUdfCreate(...) would require less code...

 

Another option is to make an XML out of a default csys elemtree and to use it with ProElemtreeFromXMLCreate(...) - still less typing and code maintenance...

 

HIH.

FV.

Highlighted

Re: Is there any creo toolkit API to create default coordinate system (global coordinate system)?

To top your valid suggestions and help the questioner ponder:

  • using mapkey is safe with a synchronous application and may be hazardous with asynchronous application (window control handling)
  • ProUdfCreate and ProElemtreeFromXMLCreate and need to be fed with an external file (gph on one hand and xml on the other). The security and access to those files is critical. This offers on one hand some flexibility but is a quick'n dirty solution. Imagine the gph file is altered by another user or the xml gets corrupted or that the path is not accessible anymore.
  • Finally the Element Tree method is indeed the most demanding code wise but the most powerful and portable.

Up to you to pick the appropriate solution.

Highlighted

Re: Is there any creo toolkit API to create default coordinate system (global coordinate system)?

An Example for the Element Tree Method:

 

int createACoordinateSystem_first_try = 1;

void createACoordinateSystem(ProFeature * feat) {
	ProElement pro_e_feature_tree, pro_e_feature_type, pro_e_csys_method, pro_e_std_feature_name;
	ProErrorlist errs;
	ProError tkerr;
	ProValueData value_data;
	ProValue value;
	ProFeatureCreateOptions opts[1];
	ProName wide_string = L"";
	ProModelitem p_mdl_itm;
	ProSelection sel;

	wcscpy_s(wide_string, PRO_NAME_SIZE, L"NAME");

	ProElementAlloc(PRO_E_FEATURE_TREE, &pro_e_feature_tree);

	ProElementAlloc(PRO_E_FEATURE_TYPE, &pro_e_feature_type);
	value_data.type = PRO_VALUE_TYPE_INT;
	value_data.v.i = PRO_FEAT_CSYS; /* 979 */ 
	ProValueAlloc(&value);
	ProValueDataSet ( value, &value_data );
	ProElementValueSet ( pro_e_feature_type, value );
	ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feature_type );

	ProElementAlloc ( PRO_E_STD_FEATURE_NAME, &pro_e_std_feature_name ); 
	value_data.type = PRO_VALUE_TYPE_WSTRING;
	value_data.v.w = wide_string;
	ProValueAlloc ( &value );
	ProValueDataSet ( value, &value_data );
	ProElementValueSet ( pro_e_std_feature_name, value );
	ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_std_feature_name );

	ProElementAlloc(PRO_E_CSYS_METHOD, &pro_e_csys_method);
	value_data.type = PRO_VALUE_TYPE_INT;
	value_data.v.i = PRO_CSYS_DEFAULT;
	ProValueAlloc(&value);
	ProValueDataSet ( value, &value_data );
	ProElementValueSet ( pro_e_csys_method, value );
	ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_csys_method );
	
	opts[0] = PRO_FEAT_CR_DEFINE_MISS_ELEMS;

	tkerr = ProMdlToModelitem(addFirstKEsFeatureVisitModel, &p_mdl_itm);
	tkerr = ProSelectionAlloc(NULL, &p_mdl_itm, &sel);
	tkerr = ProFeatureCreate(sel, pro_e_feature_tree, opts, 1, feat, &errs);
	if (tkerr != PRO_TK_NO_ERROR) {
		if (createACoordinateSystem_first_try == 1) {
			// Can't create the coordinate system at first
			createACoordinateSystem_first_try --;
		} else {
			// Can't create the coordinate system
		}
	}
	ProSelectionFree(&sel);
	ProElementFree(&pro_e_feature_tree);
}

 

Br,

Eike

Highlighted

Re: Is there any creo toolkit API to create default coordinate system (global coordinate system)?

Eike,

Are you sure this code is valid for wildfire and creo releases?

PRO_E_CSYS_METHOD element had been obsolete for quite some time now...

Below is a feature tree for default csys (creo variety).

😀FV.

Element tree
============

FEATURE_TREE   (COMPOUND) 
 |---FEATURE_TYPE  VALUE (INT)       = 979
 |---STD_FEATURE_NAME  VALUE (WSTRING)   = CS1
 |---CSYS_ORIGIN_CONSTRS   (ARRAY) 
 |---CSYS_OFFSET_TYPE  VALUE (INT)       = 0
 |---CSYS_ONSURF_TYPE  VALUE (INT)       = 0
 |---CSYS_DIM_CONSTRS   (ARRAY) 
 |---CSYS_ORIENTMOVES   (ARRAY) 
 |---CSYS_NORMAL_TO_SCREEN  VALUE (INT)       = 0
 |---CSYS_ORIENT_BY_METHOD  VALUE (INT)       = 0
 |---CSYS_ORIENTSELAXIS1_REF  VALUE (SELECTION) = 

 |---CSYS_ORIENTSELAXIS1_REF_OPT  VALUE (INT)       = 0
 |---CSYS_ORIENTSELAXIS1_OPT  VALUE (INT)       = 0
 |---CSYS_ORIENTSELAXIS1_FLIP  VALUE (INT)       = 0
 |---CSYS_ORIENTSELAXIS2_REF  VALUE (SELECTION) = 

 |---CSYS_ORIENTSELAXIS2_REF_OPT  VALUE (INT)       = 0
 |---CSYS_ORIENTSELAXIS2_OPT  VALUE (INT)       = 0
 |---CSYS_ORIENTSELAXIS2_FLIP  VALUE (INT)       = 0
 |---CSYS_ORIENTSELAXIS2_ROT_OPT  VALUE (INT)       = 0
 |---CSYS_ORIENTSELAXIS2_ROT  VALUE (DOUBLE)    = 0.000000
 |---CSYS_TYPE_MECH  VALUE (INT)       = 0
 |---CSYS_FOLLOW_SRF_OPT  VALUE (INT)       = 0
 |---CSYS_NAME_DISPLAY_OPT  VALUE (INT)       = 1
 |---CSYS_DISPLAY_ZOOM_DEP_OPT  VALUE (INT)       = 0
 |---CSYS_AXIS_LENGTH  VALUE (DOUBLE)    = 0.000000

 

Highlighted

Re: Is there any creo toolkit API to create default coordinate system (global coordinate system)?

Just copied it from some old code, tested it with a new Creo-Version but didn't update it ^.^ It works for my case but isn't secure to run.

 

Thanks Felkis.

 

Br,

Eike

Highlighted

Re: Is there any creo toolkit API to create default coordinate system (global coordinate system)?

Might be easier to fire off a Mapkey to get that done.

Announcements