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

Problem with placing a UDF on a sketch as reference.

J_Sattler
4-Participant

Problem with placing a UDF on a sketch as reference.

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.

1 ACCEPTED SOLUTION

Accepted Solutions
FV
17-Peridot
17-Peridot
(To:J_Sattler)

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, ...);

 

View solution in original post

7 REPLIES 7
FV
17-Peridot
17-Peridot
(To:J_Sattler)

looks like the portion of the code which should set  ProAsmcomppath for ProSelection structure is missing. try to use two argument form of pfcCreateModelItemSelection(...).

J_Sattler
4-Participant
(To:FV)

Thank you very much for your suggestion.
I tried to follow your advice, however I couldn't get it working.
 
pfcModelItem_ptr sketchItem = skeleton->GetItemByName(pfcITEM_FEATURE, "SKETCH");
xintsequence_ptr seq = xintsequence::create();
seq->append(assembly->ListFeaturesByType(true, pfcFEATTYPE_COMPONENT)->get(0)->GetId());
seq->append(sketchItem->GetId()); // I tried it with and without this line
pfcComponentPath_ptr path = pfcCreateComponentPath(assembly, seq);
pfcSelection_ptr selection = pfcCreateModelItemSelection(sketchItem, path);
 

With the sketchItem ID in the path, I get this:
pfcExceptions::XToolkitGeneralError
{
Message : "pfcExceptions::XToolkitGeneralError"
MethodName : "pfcSelect::CreateModelItemSelection"
ToolkitFunctionName : "ProAsmcomppathMdlGet"
}
 
When I just add the skeleton ID to the path, I get the same error as before upon calling CreateUDFGroup.
The selection itself doesn't raise an error.
FV
17-Peridot
17-Peridot
(To:J_Sattler)

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, ...);

 

View solution in original post

J_Sattler
4-Participant
(To:FV)

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.

J_Sattler
4-Participant
(To:ysinitsyn)

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?
 

Announcements