Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
I have a problem placing a UDF with a reference that is not contained in the parent part.
Let's have a look at the following code, which is working as expected:
pfcAssembly_ptr assembly = pfcAssembly::cast(session->GetActiveModel());
logFile << "assembly: " << assembly->GetFullName() << endl;
pfcSolid_ptr skeleton = assembly->GetSkeleton();
logFile << "skeleton: " << skeleton->GetFullName() << endl;
pfcFeature_ptr partItem = assembly->ListFeaturesByType(false, pfcFEATTYPE_COMPONENT)->get(1);
pfcModelDescriptor_ptr desc = pfcComponentFeat::cast(partItem)->GetModelDescr();
pfcPart_ptr part = pfcPart::cast(session->GetModelFromDescr(desc));
logFile << "part: " << part->GetFullName() << endl;
pfcModelItem_ptr sketchItem = part->GetItemByName(pfcITEM_FEATURE, "SKETCH");
logFile << "sketchItem: " << sketchItem << endl;
pfcSelection_ptr selection = pfcCreateModelItemSelection(sketchItem);
logFile << "selection: " << selection << endl;
pfcUDFReference_ptr reference = pfcUDFReference::Create("udf_sketch", selection);
pfcUDFReferences_ptr references = pfcUDFReferences::create();
references->append(reference);
logFile << "references: " << references << endl;
pfcUDFCustomCreateInstructions_ptr instructions = pfcUDFCustomCreateInstructions::Create("C:\\path\\to\\ufd.gph");
instructions->SetDimDisplayType(pfcUDFDISPLAY_BLANK);
instructions->SetReferences(references);
logFile << "instructions: " << instructions << endl;
pfcFeatureGroup_ptr udf = part->CreateUDFGroup(pfcUDFCustomCreateInstructions::cast(instructions));
logFile << "success!" << endl;
It places a UDF inside the part, with a sketch of the part as reference.
Now let's try the same again, but with a sketch of the skeleton as reference (changing only this one line):
pfcModelItem_ptr sketchItem = skeleton->GetItemByName(pfcITEM_FEATURE, "SKETCH"); // instead of part->GetItemByName
The sketch gets found and selected (according to logging output). But part->CreateUDFGroup causes an error:
pfcExceptions::XToolkitGeneralError
{
Message : "pfcExceptions::XToolkitGeneralError"
MethodName : "ProUdfCreate"
ToolkitFunctionName : "pfcSolid::Solid::CreateUDFGroup"
}
Creo then tells me to correct an invalid reference to a sketch.
It's possible to reference the UDF to this sketch via Creo UI. So, what's wrong with the code?
Any help or working code (regardless of the programming language) would be highly appreciated.
Solved! Go to Solution.
although the later post questioning
pfcFeatureGroup_ptr udf = part->CreateUDFGroup(pfcUDFCustomCreateInstructions::cast(instructions));
the most likely is the reason for the problem, it makes sense to review steps.
I'll use Pro/Toolkit, IMHO OTK just creates lots of syntax noise and obscures code intent...
I would make a learn-test.
given: a top level assembly ( ProMdl assembly;) , a skeleton component ( int id1 = 2;) , a component with a sketch feature ( int id2 = 4; int sketch_feat_id = 10; ), a UDF with the prompt 'UDF_SKETCH', and filesystem path (ProName udf_name = L"something";), substitute id's for real ones. I'm using C++, declarations are at use points.
//build ProAsmcomppath
ProAsmcomppath skel_cpath, part_cpath;
ProAsmcomppathInit( assembly, 0, NULL, &skel_cpath);
skel_cpath.table_num = 1;
skel_cpath.comp_id_table[0] = id1;
ProAsmcomppathInit( assembly, 0, NULL, &part_cpath);
part_cpath.table_num = 1;
part_cpath.comp_id_table[0] = id2;
//build selection
ProFeature sketch_feat = {0,0,0};
sketch_feature.id = sketch_feat_id;
sketch_feature.type = PRO_FEATURE;
ProAsmcomppathMdlGet( &part_cpath, &sketch_feature.owner);
ProSelection sketch_sel = NULL;
ProSelectionAlloc( &part_cpath, &sketch_feature, &sketch_sel);
//make a function to check if ProAsmcomppath are equal
// this function will be used quite often...
ProBoolean external_flag = PRO_B_TRUE;
if( _comppath_equal( &part_cpath, &skel_cpath)) { external_flag = PRO_B_FALSE;}
//allocate UDF data, set up properties ...
ProUdfdata udf_data = NULL;
//...
//allocate and add udf references
ProLine w_prompt = L"UDF_SKETCH";
ProUdfreference udf_ref1 = NULL;
ProUdfreferenceAlloc( w_prompt, sketch_sel, external_flag, &udf_ref1);
ProUdfdataReferenceAdd( udf_data, udf_ref1);
//...
//create UDF in skeleton model
ProMdl skel_mdl = NULL;
ProAsmcomppathMdlGet( &skel_cpath, &skel_mdl);
ProUdfCreate( skel_mdl, udf_data, &skel_cpath, ...);
looks like the portion of the code which should set ProAsmcomppath for ProSelection structure is missing. try to use two argument form of pfcCreateModelItemSelection(...).
although the later post questioning
pfcFeatureGroup_ptr udf = part->CreateUDFGroup(pfcUDFCustomCreateInstructions::cast(instructions));
the most likely is the reason for the problem, it makes sense to review steps.
I'll use Pro/Toolkit, IMHO OTK just creates lots of syntax noise and obscures code intent...
I would make a learn-test.
given: a top level assembly ( ProMdl assembly;) , a skeleton component ( int id1 = 2;) , a component with a sketch feature ( int id2 = 4; int sketch_feat_id = 10; ), a UDF with the prompt 'UDF_SKETCH', and filesystem path (ProName udf_name = L"something";), substitute id's for real ones. I'm using C++, declarations are at use points.
//build ProAsmcomppath
ProAsmcomppath skel_cpath, part_cpath;
ProAsmcomppathInit( assembly, 0, NULL, &skel_cpath);
skel_cpath.table_num = 1;
skel_cpath.comp_id_table[0] = id1;
ProAsmcomppathInit( assembly, 0, NULL, &part_cpath);
part_cpath.table_num = 1;
part_cpath.comp_id_table[0] = id2;
//build selection
ProFeature sketch_feat = {0,0,0};
sketch_feature.id = sketch_feat_id;
sketch_feature.type = PRO_FEATURE;
ProAsmcomppathMdlGet( &part_cpath, &sketch_feature.owner);
ProSelection sketch_sel = NULL;
ProSelectionAlloc( &part_cpath, &sketch_feature, &sketch_sel);
//make a function to check if ProAsmcomppath are equal
// this function will be used quite often...
ProBoolean external_flag = PRO_B_TRUE;
if( _comppath_equal( &part_cpath, &skel_cpath)) { external_flag = PRO_B_FALSE;}
//allocate UDF data, set up properties ...
ProUdfdata udf_data = NULL;
//...
//allocate and add udf references
ProLine w_prompt = L"UDF_SKETCH";
ProUdfreference udf_ref1 = NULL;
ProUdfreferenceAlloc( w_prompt, sketch_sel, external_flag, &udf_ref1);
ProUdfdataReferenceAdd( udf_data, udf_ref1);
//...
//create UDF in skeleton model
ProMdl skel_mdl = NULL;
ProAsmcomppathMdlGet( &skel_cpath, &skel_mdl);
ProUdfCreate( skel_mdl, udf_data, &skel_cpath, ...);
Thank you very much for your advice.
Now it works.
It places a UDF inside the part, with a sketch of the part as reference.
What does this mean? Usually, the items inside the sketch (arc, line, axis) used as the reference.
Please, explain how you use whole sketch.
I use the whole sketch as a reference, because the UDF just need a sketch for full definition.
This process works inside creo fine. I am able to select a sketch that is not located inside the target model.
Just take a look at attached screenshot "udf_sketch.png"
With toolkit I am able to place the UDF on a sketch inside the target model, but not outside like from the skeleton or another part.
I hope that helps for clarification.
pfcFeatureGroup_ptr udf = part->CreateUDFGroup(pfcUDFCustomCreateInstructions::cast(instructions));
Did you change in this line from a part to skeleton?