Showing results for 
Search instead for 
Do you mean 
Reply

Activate "Find Features" from external app (C++)

[ Edited ]

Hello,

 

NXOpen C++ - External app

I'm trying to load a PRT file and run the "Find Features..." option in it.

I recorded a journal and implemented it in my code (with some minor changes of course).

unfortunately, I got this: 

Untitled.jpg

 

 

	MainProgram::theSession = NXOpen::Session::GetSession();

	NXOpen::BasePart *basePart1;
	NXOpen::PartLoadStatus *partLoadStatus1;
	basePart1 = theSession->Parts()->OpenBaseDisplay("C:\\Tal's Stuff\\NX CAM\\part.prt", &partLoadStatus1);

	NXOpen::Part *tmp1(theSession->Parts()->Work());
	workPart = tmp1;
	NXOpen::Part *tmp2(theSession->Parts()->Display());
	displayPart = tmp2;

	bool result1;
	result1 = theSession->IsCamSessionInitialized();

	theSession->CreateCamSession();

	NXOpen::SIM::KinematicConfigurator *kinematicConfigurator1;
	kinematicConfigurator1 = workPart->CreateKinematicConfigurator();

	NXOpen::Session::UndoMarkId markId2;
	markId2 = theSession->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Start");

	NXOpen::CAM::CAMObject *nullNXOpen_CAM_CAMObject(NULL);
	NXOpen::CAM::FeatureRecognitionBuilder *featureRecognitionBuilder1;
	featureRecognitionBuilder1 = workPart->CAMSetup()->CreateFeatureRecognitionBuilder(nullNXOpen_CAM_CAMObject);

	NXOpen::CAM::ManualFeatureBuilder *manualFeatureBuilder1;
	manualFeatureBuilder1 = featureRecognitionBuilder1->CreateManualFeatureBuilder();

	featureRecognitionBuilder1->SetAssignColor(false);

	featureRecognitionBuilder1->SetAddCadFeatureAttributes(false);

	featureRecognitionBuilder1->SetMapFeatures(false);

	theSession->SetUndoMarkName(markId2, "Find Features Dialog");

	featureRecognitionBuilder1->SetRecognitionType(NXOpen::CAM::FeatureRecognitionBuilder::RecognitionEnumParametric);

	featureRecognitionBuilder1->SetUseFeatureNameAsType(true);

	featureRecognitionBuilder1->SetIgnoreWarnings(false);

	std::vector<NXOpen::Direction *> vecdirections1(0);
	featureRecognitionBuilder1->SetMachiningAccessDirection(vecdirections1, 0.0);

	std::vector<NXString> featureTypes1(78);
	featureTypes1[0] = "MAGENTA";
	featureTypes1[1] = "FACES";
	featureTypes1[2] = "BOSS_ROUND_STRAIGHT";
	featureTypes1[3] = "BOSS_ROUND_STRAIGHT_THREAD";
	featureTypes1[4] = "MAGENTA";
	featureTypes1[5] = "CORNER_NOTCH_RECTANGULAR";
	featureTypes1[6] = "CORNER_NOTCH_ROUND_CONCAVE";
	featureTypes1[7] = "CORNER_NOTCH_STRAIGHT";
	featureTypes1[8] = "CORNER_NOTCH_U_SHAPED";
	featureTypes1[9] = "GROOVE_AX_CIRCULAR_RECT";
	featureTypes1[10] = "GROOVE_INS_RAD_RECT";
	featureTypes1[11] = "HOLE_FREE_SHAPED_STRAIGHT";
	featureTypes1[12] = "HOLE_OBROUND_STRAIGHT";
	featureTypes1[13] = "HOLE_RECTANGULAR_STRAIGHT";
	featureTypes1[14] = "HOLE_ROUND_INTERRUPTED_STRAIGHT";
	featureTypes1[15] = "HOLE_ROUND_TAPERED";
	featureTypes1[16] = "POCKET_FREE_SHAPED_STRAIGHT";
	featureTypes1[17] = "POCKET_OBROUND_STRAIGHT";
	featureTypes1[18] = "POCKET_RECTANGULAR_STRAIGHT";
	featureTypes1[19] = "POCKET_ROUND_TAPERED";
	featureTypes1[20] = "SIDE_NOTCH_RECTANGULAR";
	featureTypes1[21] = "SIDE_NOTCH_ROUND_CONCAVE";
	featureTypes1[22] = "SIDE_NOTCH_U_SHAPED";
	featureTypes1[23] = "SLOT_90_DEGREE";
	featureTypes1[24] = "SLOT_DOVE_TAIL";
	featureTypes1[25] = "SLOT_OBROUND";
	featureTypes1[26] = "SLOT_PARTIAL_OBROUND";
	featureTypes1[27] = "SLOT_PARTIAL_RECTANGULAR";
	featureTypes1[28] = "SLOT_PARTIAL_ROUND";
	featureTypes1[29] = "SLOT_PARTIAL_U_SHAPED";
	featureTypes1[30] = "SLOT_RECTANGULAR";
	featureTypes1[31] = "SLOT_ROUND";
	featureTypes1[32] = "SLOT_T_SHAPED";
	featureTypes1[33] = "SLOT_U_SHAPED";
	featureTypes1[34] = "SLOT_UPSIDE_DOWN_DOVE_TAIL";
	featureTypes1[35] = "SLOT_V_SHAPED";
	featureTypes1[36] = "STEP1HOLE";
	featureTypes1[37] = "STEP1HOLE_THREAD";
	featureTypes1[38] = "STEP1POCKET";
	featureTypes1[39] = "STEP1POCKET_THREAD";
	featureTypes1[40] = "STEP2HOLE";
	featureTypes1[41] = "STEP2HOLE_THREAD";
	featureTypes1[42] = "STEP2POCKET";
	featureTypes1[43] = "STEP2POCKET_THREAD";
	featureTypes1[44] = "STEP3HOLE";
	featureTypes1[45] = "STEP3HOLE_THREAD";
	featureTypes1[46] = "STEP3HOLE1";
	featureTypes1[47] = "STEP3HOLE1_THREAD";
	featureTypes1[48] = "STEP3POCKET";
	featureTypes1[49] = "STEP3POCKET_THREAD";
	featureTypes1[50] = "STEP4HOLE";
	featureTypes1[51] = "STEP4HOLE_THREAD";
	featureTypes1[52] = "STEP4HOLE1";
	featureTypes1[53] = "STEP4HOLE1_THREAD";
	featureTypes1[54] = "STEP4POCKET";
	featureTypes1[55] = "STEP4POCKET_THREAD";
	featureTypes1[56] = "STEP5HOLE";
	featureTypes1[57] = "STEP5HOLE_THREAD";
	featureTypes1[58] = "STEP5HOLE1";
	featureTypes1[59] = "STEP5HOLE1_THREAD";
	featureTypes1[60] = "STEP5HOLE2";
	featureTypes1[61] = "STEP5HOLE2_THREAD";
	featureTypes1[62] = "STEP5POCKET";
	featureTypes1[63] = "STEP5POCKET_THREAD";
	featureTypes1[64] = "STEP6HOLE";
	featureTypes1[65] = "STEP6HOLE_THREAD";
	featureTypes1[66] = "STEP6HOLE1";
	featureTypes1[67] = "STEP6HOLE1_THREAD";
	featureTypes1[68] = "STEP6HOLE2";
	featureTypes1[69] = "STEP6HOLE2_THREAD";
	featureTypes1[70] = "STEP6POCKET";
	featureTypes1[71] = "STEP6POCKET_THREAD";
	featureTypes1[72] = "SURFACE_PLANAR";
	featureTypes1[73] = "SURFACE_PLANAR_RECTANGULAR";
	featureTypes1[74] = "SURFACE_PLANAR_ROUND";
	featureTypes1[75] = "TURNING_GROOVE_FACE";
	featureTypes1[76] = "TURNING_GROOVE_ID";
	featureTypes1[77] = "TURNING_GROOVE_OD";
	featureRecognitionBuilder1->SetFeatureTypes(featureTypes1);

	featureRecognitionBuilder1->SetGeometrySearchType(NXOpen::CAM::FeatureRecognitionBuilder::GeometrySearchSelected);
	std::vector<NXOpen::DisplayableObject *> objects1(1);
	NXOpen::Body *body1(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->begin().operator*()));
	objects1[0] = body1;
	featureRecognitionBuilder1->SetSearchGeometry(objects1);

	std::vector<NXOpen::CAM::CAMFeature *> features1;
	features1 = featureRecognitionBuilder1->FindFeatures();

	NXOpen::Session::UndoMarkId markId3;
	markId3 = theSession->SetUndoMark(NXOpen::Session::MarkVisibilityInvisible, "Find Features");

	theSession->DeleteUndoMark(markId3, NULL);

	NXOpen::Session::UndoMarkId markId4;
	markId4 = theSession->SetUndoMark(NXOpen::Session::MarkVisibilityInvisible, "Find Features");

	NXOpen::NXObject *nXObject1;
	nXObject1 = featureRecognitionBuilder1->Commit();

	theSession->DeleteUndoMark(markId4, NULL);

	theSession->SetUndoMarkName(markId2, "Find Features");

	featureRecognitionBuilder1->Destroy();

	manualFeatureBuilder1->Destroy();

 

 

 

I get an exception in:

features1 = featureRecognitionBuilder1->FindFeatures();

 

I'll be glad to get some help.

Thank you!

9 REPLIES

Re: Activate "Find Features" from external app (C++)

I think the problem is in the creation of the FeatureRecognitionBuilder.

The fileds are NULL

Untitled.png

What did I miss?

Re: Activate "Find Features" from external app (C++)

[ Edited ]

I use the following in VB.NET, which seems to be similar to the one in C++.

Dim theFeatures As CAM.CAMFeature() = Nothing

        Dim theFeatureRecognitionBuilder As CAM.FeatureRecognitionBuilder = _
            theWorkPart.CAMSetup.CreateFeatureRecognitionBuilder(Nothing)

            theFeatureRecognitionBuilder.RecognitionType = _
                CAM.FeatureRecognitionBuilder.RecognitionEnum.Parametric
            theFeatureRecognitionBuilder.GeometrySearchType = _
                CAM.FeatureRecognitionBuilder.GeometrySearch.Workpiece
            
            Dim theFeatureTypes(1) As String
            theFeatureTypes(0) = "STEP1HOLE"
            theFeatureTypes(1) = "STEP1HOLE_THREAD"
            theFeatureRecognitionBuilder.SetFeatureTypes(theFeatureTypes)
            
            theFeatures = theFeatureRecognitionBuilder.FindFeatures()
            
            Dim theDummyObject As NXObject = theFeatureRecognitionBuilder.Commit()

            theFeatureRecognitionBuilder.Destroy()
Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Activate "Find Features" from external app (C++)

I converted it to C++, but still I get the same thing - "memory access violation"

 

	std::vector<NXOpen::CAM::CAMFeature*> theFeatures;
	NXOpen::CAM::FeatureRecognitionBuilder* theFeatureRecognitionBuilder = workPart->CAMSetup()->CreateFeatureRecognitionBuilder(NULL);

	theFeatureRecognitionBuilder->SetRecognitionType(NXOpen::CAM::FeatureRecognitionBuilder::RecognitionEnum::RecognitionEnumParametric);
	theFeatureRecognitionBuilder->SetGeometrySearchType(NXOpen::CAM::FeatureRecognitionBuilder::GeometrySearch::GeometrySearchWorkpiece);

	std::vector<NXOpen::NXString> theFeatureTypes(2);
	theFeatureTypes[0] = "EW_SPARK_AREA_FLOOR_FINISH";
	theFeatureTypes[1] = "EW_SOCKET_FINISH";
	theFeatureRecognitionBuilder->SetFeatureTypes(theFeatureTypes);

	theFeatures = theFeatureRecognitionBuilder->FindFeatures();

	NXOpen::NXObject *theDummyObject = theFeatureRecognitionBuilder->Commit();

	theFeatureRecognitionBuilder->Destroy();

Re: Activate "Find Features" from external app (C++)

I have been using this since NX 10.0.3 RTM, which NX release are you using?

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Activate "Find Features" from external app (C++)

I'm currently using NX 11.0

Re: Activate "Find Features" from external app (C++)

NX 11 is beta, so there might be a problem you need to report, but I doubt that this will be fixed for the initial release.

I would try the same code with NX 10, if you exhibit the same problem there, you can report it much easier.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Activate "Find Features" from external app (C++)

The feature types that Stefan is using in his VB example are non-standard and probably missing from your machining knowledge file; please replace them with OOTB feature types such as "STEP1HOLE" from your original example and check again.

 

Please share the NX syslog file with us if that doesn't work. Hopefully it will give some additional insight.

 

Tom van 't Erve

NX CAM Development

Re: Activate "Find Features" from external app (C++)

Tom is right, I was assuming you would change the features to the types you use.

I have changed my post to use standard types now.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Activate "Find Features" from external app (C++)

I cahnged the features types and still got the same problem.

 

The syslog file is attached to this message.