Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
I am new to Creo Object toolkit. I had some experience using Creo customization using VBA, that too few years back.
Problem: I want to create a section in assembly by picking a face of one part and want to know section of other part which is intersecting first part. I used sample example available in OTKXCrossSection.cxx
Issue:
1. When I run the program and select the face of part as reference for PlanarXSection , it gives error as 'XToolkitBadInputs'
2. If I select the datum from the part, it creates section without any output. If I edit, it shows menu manager-Feature fail.
Can someone please help me understanding what is wrong with below code.
Below is the code I am using:
void CreatePlanarXSection()
{
pfcSelection_ptr refSelection;
pfcSession_ptr Session = pfcGetProESession();
wfcWSession_ptr wSession = wfcWSession::cast(pfcGetProESession());
try
{
if (refSelection == 0)
{
pfcSelectionOptions_ptr refSelopts = pfcSelectionOptions::Create("datum,surface");
refSelopts->SetMaxNumSels(1);
wSession->UIDisplayMessage("xsection_example_msg.txt", "USER Plane Selection", NULL);
pfcSelections_ptr refSels = wSession->Select(refSelopts);
refSelection = refSels->get(0);
}
pfcXSecCutobjType cutObjtype = pfcXSecCutobjType_nil;
xint quiltID = -1;
xintsequence_ptr memberIdTable = 0;
xint planeId = refSelection->GetSelItem()->GetId();
wfcXSectionComponents_ptr compExcl = 0;
pfcParent_ptr owner = refSelection->GetSelItem()->GetDBParent();
wfcWSolid_ptr solidOwner = wfcWSolid::cast(owner);
if (wSession->GetCurrentModel()->GetType() == pfcMDL_ASSEMBLY)
{
wSession->UIDisplayMessage("xsection_example_msg.txt", "USER Part Selection", NULL);
pfcSelectionOptions_ptr partSelopts = pfcSelectionOptions::Create("part");
partSelopts->SetMaxNumSels(1);
pfcSelections_ptr partSels = wSession->Select(partSelopts);
pfcSelection_ptr selCutobj = partSels->get(0);
pfcComponentPath_ptr compPath = selCutobj->GetPath();
if (compPath != 0)
memberIdTable = compPath->GetComponentIds();
cutObjtype = pfcXSECTYPE_ONEPART;
}
wSession->UIDisplayMessage("xsection_example_msg.txt", "USER Section Name", NULL);
xstring sectionName = wSession->UIReadStringMessage(false);
/*
NOTE 6: Finally creates planar section with inputs received so far.
Keeping Flip as xtrue (i.e. Clip model in the direction of positive normal to xsection plane )
*/
solidOwner->CreatePlanarXSection(sectionName, planeId, cutObjtype, memberIdTable, quiltID, xtrue, compExcl);
solidOwner->RefreshMdlTree();
}
xcatchbegin
xcatchcip(Ex)
logFile << "Exception:\n" << Ex << endl;
xcatchend
}
Solved! Go to Solution.
The code uses quite a number of pointers to object instances created in scope. In case an object gets destroyed when scope ends - pointers are pointing to undefined values, in case an object is not destroyed upon scope end the memory is leaked - not good either.
I would suggest to use Pro/Toolkit - the code would be much clearer and it is easier to see problems right away.
HIH.
this is not correct.
C++ will not automatically initialize a variable to NULL value after variable's declaration.
Hi,
Many thanks for your reply.
You are correct about variable initialization. I changed code but issue is still there.
I think, that is not root cause of the issue I am facing. I am able to select face which is asked by ->select() command. but application fails at
solidOwner->CreatePlanarXSection(sectionName, planeId, cutObjtype, memberIdTable, quiltID, xtrue, compExcl);
Do you find something wrong about solidOwner.
Your assistance will help me in long way.
Thanks
The code uses quite a number of pointers to object instances created in scope. In case an object gets destroyed when scope ends - pointers are pointing to undefined values, in case an object is not destroyed upon scope end the memory is leaked - not good either.
I would suggest to use Pro/Toolkit - the code would be much clearer and it is easier to see problems right away.
HIH.