Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Hi there,
is there a way to create a coordinate system with weblink?
I tried it with an UDF, but for some reason I have to select its reference everytime. Another disadvantage I see with UDFs is, that I have to administer two different data-sources for one function.
function create_csys_from_udf(reference_name, name_def, trans_x, trans_y, trans_z, rot_x, rot_y, rot_z){
var udf_instructions = pfcCreate ("pfcUDFCustomCreateInstructions").Create ("wl_add_cs_w_dtms");
udf_instructions.DimDisplayType = pfcCreate ("pfcUDFDimensionDisplayType").UDFDISPLAY_BLANK;
var origin_of_csys = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_COORD_SYS, reference_name);
var selected_origin_of_csys = pfcCreate("MpfcSelect").CreateModelItemSelection(origin_of_csys, void null);
var origin_ref = pfcCreate("pfcUDFReference").Create("Ursprung", selected_origin_of_csys );
var udf_references = pfcCreate("pfcUDFReferences");
udf_references.Append(origin_ref);
udf_instructions.References = udf_references; --> this is ignored by creo
// move and rotate csys
var udf_dimensions = pfcCreate ("pfcUDFVariantValues");
var translation_x = pfcCreate ("pfcUDFVariantDimension").Create ("trans_x", trans_x);
udf_dimensions.Append(translation_x);
udf_instructions.VariantValues = udf_dimensions;
var udf_group = CurModel.CreateUDFGroup(udf_instructions);
// rename udf-components
var udf_csys = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_COORD_SYS, "CS_UDF_TEMP");
udf_csys.SetName("CS_" + name_def);
return (udf_group);
}
Any idea?
Cheers
Mat
Solved! Go to Solution.
Hey Jun,
I solved this problem by using UDFs.
To my application:
I am using a raytrace program for creating and simulating of optical systems (www.zemax.com).
All positions of interesting optical surfaces are exported in a text file, which looks like this:
! 20.06.2013 automatically generated by Zemax
! Generated from Zemax-file: lens.zmx
SRF_0_object,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000
SRF_1_lens1,0.0000000000,-6.2330778704,5.7267826174,30.0000000000,0.0000000000,0.0000000000
...
Creo reads this text file and creates named CS and datum planes for each element.
It is definitely faster than using UI with "create CS from file".
Here is the javascript, that creates the CS:
function create_csys_from_file(reference_name, name_def, trans_x, trans_y, trans_z, rot_x, rot_y, rot_z){
// convert text to numbers
trans_x = parseFloat(trans_x);
trans_y = parseFloat(trans_y);
trans_z = parseFloat(trans_z);
rot_x = parseFloat(rot_x);
rot_y = parseFloat(rot_y);
rot_z = parseFloat(rot_z);
// crop angles greater than 360 degrees
rot_x = rot_x % 360;
rot_y = rot_y % 360;
rot_z = rot_z % 360;
// crop long names
name_def = name_def.slice(0, 20);
reference_name = reference_name.slice(0, 20);
// save user's current config setting
var udf_path_temp = oSession.GetConfigOptionValues("pro_group_dir");
oSession.SetConfigOption("pro_group_dir", <path, where your UDFs are. Like "z:\\libraries\\UDFs\\"> );
var udf_instructions = pfcCreate ("pfcUDFCustomCreateInstructions").Create ("wl_add_cs_w_dtms"); // name of UDF is wl_add_cs_w_dtms
udf_instructions.DimDisplayType = pfcCreate ("pfcUDFDimensionDisplayType").UDFDISPLAY_BLANK;
try {
var origin_of_csys = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_COORD_SYS, reference_name);
var selected_origin_of_csys = pfcCreate("MpfcSelect").CreateModelItemSelection(origin_of_csys, void null);
var origin_ref = pfcCreate("pfcUDFReference").Create("UDF_REF_SYS", selected_origin_of_csys );
var udf_references = pfcCreate("pfcUDFReferences");
udf_references.Append(origin_ref);
udf_instructions.References = udf_references;
}
catch(er)
{
alert("An error occured:\n" + "reference_name: " + reference_name + "\n" + er);
return;
}
// move and rotate coordinate system
var udf_dimensions = pfcCreate ("pfcUDFVariantValues");
var translation_x = pfcCreate ("pfcUDFVariantDimension").Create ("trans_x", trans_x);
udf_dimensions.Append(translation_x);
var translation_y = pfcCreate ("pfcUDFVariantDimension").Create ("trans_y", trans_y);
udf_dimensions.Append(translation_y);
var translation_z = pfcCreate ("pfcUDFVariantDimension").Create ("trans_z", trans_z);
udf_dimensions.Append(translation_z);
var rotation_x = pfcCreate ("pfcUDFVariantDimension").Create ("rot_x", rot_x);
udf_dimensions.Append(rotation_x);
var rotation_y = pfcCreate ("pfcUDFVariantDimension").Create ("rot_y", rot_y);
udf_dimensions.Append(rotation_y);
var rotation_z = pfcCreate ("pfcUDFVariantDimension").Create ("rot_z", rot_z);
udf_dimensions.Append(rotation_z);
udf_instructions.VariantValues = udf_dimensions;
var udf_group = CurModel.CreateUDFGroup(udf_instructions);
// rename UDF - components
try{
var udf_csys = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_COORD_SYS, "CS_UDF_TEMP");
udf_csys.SetName("CS_" + name_def);
var udf_dtm_xy = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_FEATURE, "DTM_UDF_TEMP_XY");
udf_dtm_xy.SetName("DTM_" + name_def + "_XY");
var udf_dtm_yz = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_FEATURE, "DTM_UDF_TEMP_YZ");
udf_dtm_yz.SetName("DTM_" + name_def + "_YZ");
var udf_dtm_zx = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_FEATURE, "DTM_UDF_TEMP_ZX");
udf_dtm_zx.SetName("DTM_" + name_def + "_ZX");
var udf_group_feat = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_FEATURE, "WL_ADD_CS_W_DTMS" );
udf_group_feat.SetName(name_def);
}
catch(er){
alert("name collision with " + name_def + "\n" +er);
}
// regenerate
proe_regenerate();
// restore user's config setting
oSession.SetConfigOption("pro_group_dir", udf_path_temp.Item(0) );
return (udf_group);
}
Bye Matthias
In the meantime, I tried to create that coordinate system directly.
But I did not come too far:
function create_csys(reference_name, name_def, trans_x, trans_y, trans_z, rot_x, rot_y, rot_z){
var feat_type = pfcCreate("pfcFeatureType").FEATTYPE_COORD_SYS;
var features = new pfcCreate("pfcFeatures");
// var new_feat = pfcCreate("pfcFeatureCreateInstructions").GetType(feat_type);
var csys_dimensioncontraints = new pfcCreate("pfcDatumCsysDimensionConstraints");
var csys_offset_type = new pfcCreate("pfcDatumCsysOffsetType").DTMCSYS_OFFSET_CARTESIAN;
var csys_origin_contraints = new pfcCreate("pfcDatumCsysOriginConstraints");
var csys_origin = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_COORD_SYS, reference_name);
var select_csys_origin = pfcCreate("MpfcSelect").CreateModelItemSelection(csys_origin, void null);
var csys_origin_contraint = pfcCreate("pfcDatumCsysOriginConstraint").Create(select_csys_origin);
csys_origin_contraints.Append(csys_origin_contraint);
}
Still looking for a method like solid.CreateFeature(instructions).
Hello, Mat again
Have you already solve this problem?
I applied the code you wrote to my Creo, then it works.
(dont have to select its reference)
which version of Creo/ProE do you use?
weblink can't insert feature directly.
API reference says "pfcSolid.CreateFeature is Not implemented in the current release".
and unfortunately, PTC won't enhance pfcAPI including weblink any more.
So the only way you can insert the feature is UDF(or using macro)
Hey Jun,
I solved this problem by using UDFs.
To my application:
I am using a raytrace program for creating and simulating of optical systems (www.zemax.com).
All positions of interesting optical surfaces are exported in a text file, which looks like this:
! 20.06.2013 automatically generated by Zemax
! Generated from Zemax-file: lens.zmx
SRF_0_object,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000
SRF_1_lens1,0.0000000000,-6.2330778704,5.7267826174,30.0000000000,0.0000000000,0.0000000000
...
Creo reads this text file and creates named CS and datum planes for each element.
It is definitely faster than using UI with "create CS from file".
Here is the javascript, that creates the CS:
function create_csys_from_file(reference_name, name_def, trans_x, trans_y, trans_z, rot_x, rot_y, rot_z){
// convert text to numbers
trans_x = parseFloat(trans_x);
trans_y = parseFloat(trans_y);
trans_z = parseFloat(trans_z);
rot_x = parseFloat(rot_x);
rot_y = parseFloat(rot_y);
rot_z = parseFloat(rot_z);
// crop angles greater than 360 degrees
rot_x = rot_x % 360;
rot_y = rot_y % 360;
rot_z = rot_z % 360;
// crop long names
name_def = name_def.slice(0, 20);
reference_name = reference_name.slice(0, 20);
// save user's current config setting
var udf_path_temp = oSession.GetConfigOptionValues("pro_group_dir");
oSession.SetConfigOption("pro_group_dir", <path, where your UDFs are. Like "z:\\libraries\\UDFs\\"> );
var udf_instructions = pfcCreate ("pfcUDFCustomCreateInstructions").Create ("wl_add_cs_w_dtms"); // name of UDF is wl_add_cs_w_dtms
udf_instructions.DimDisplayType = pfcCreate ("pfcUDFDimensionDisplayType").UDFDISPLAY_BLANK;
try {
var origin_of_csys = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_COORD_SYS, reference_name);
var selected_origin_of_csys = pfcCreate("MpfcSelect").CreateModelItemSelection(origin_of_csys, void null);
var origin_ref = pfcCreate("pfcUDFReference").Create("UDF_REF_SYS", selected_origin_of_csys );
var udf_references = pfcCreate("pfcUDFReferences");
udf_references.Append(origin_ref);
udf_instructions.References = udf_references;
}
catch(er)
{
alert("An error occured:\n" + "reference_name: " + reference_name + "\n" + er);
return;
}
// move and rotate coordinate system
var udf_dimensions = pfcCreate ("pfcUDFVariantValues");
var translation_x = pfcCreate ("pfcUDFVariantDimension").Create ("trans_x", trans_x);
udf_dimensions.Append(translation_x);
var translation_y = pfcCreate ("pfcUDFVariantDimension").Create ("trans_y", trans_y);
udf_dimensions.Append(translation_y);
var translation_z = pfcCreate ("pfcUDFVariantDimension").Create ("trans_z", trans_z);
udf_dimensions.Append(translation_z);
var rotation_x = pfcCreate ("pfcUDFVariantDimension").Create ("rot_x", rot_x);
udf_dimensions.Append(rotation_x);
var rotation_y = pfcCreate ("pfcUDFVariantDimension").Create ("rot_y", rot_y);
udf_dimensions.Append(rotation_y);
var rotation_z = pfcCreate ("pfcUDFVariantDimension").Create ("rot_z", rot_z);
udf_dimensions.Append(rotation_z);
udf_instructions.VariantValues = udf_dimensions;
var udf_group = CurModel.CreateUDFGroup(udf_instructions);
// rename UDF - components
try{
var udf_csys = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_COORD_SYS, "CS_UDF_TEMP");
udf_csys.SetName("CS_" + name_def);
var udf_dtm_xy = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_FEATURE, "DTM_UDF_TEMP_XY");
udf_dtm_xy.SetName("DTM_" + name_def + "_XY");
var udf_dtm_yz = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_FEATURE, "DTM_UDF_TEMP_YZ");
udf_dtm_yz.SetName("DTM_" + name_def + "_YZ");
var udf_dtm_zx = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_FEATURE, "DTM_UDF_TEMP_ZX");
udf_dtm_zx.SetName("DTM_" + name_def + "_ZX");
var udf_group_feat = CurModel.GetItemByName(pfcCreate("pfcModelItemType").ITEM_FEATURE, "WL_ADD_CS_W_DTMS" );
udf_group_feat.SetName(name_def);
}
catch(er){
alert("name collision with " + name_def + "\n" +er);
}
// regenerate
proe_regenerate();
// restore user's config setting
oSession.SetConfigOption("pro_group_dir", udf_path_temp.Item(0) );
return (udf_group);
}
Bye Matthias