NXopen C++ 分割成两段,我怎么得到两条线段的tag
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了std::vector<NXObject *> objects1;
objects1 = divideCurveBuilder1->GetCommittedObjects();
完整代码如下:
// NX 7.5.0.32
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
//
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/Direction.hxx>
#include <NXOpen/Expression.hxx>
#include <NXOpen/ExpressionCollection.hxx>
#include <NXOpen/Features_BaseFeatureCollection.hxx>
#include <NXOpen/Features_DivideCurveBuilder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/Features_PointFeature.hxx>
#include <NXOpen/ModelingView.hxx>
#include <NXOpen/ModelingViewCollection.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Plane.hxx>
#include <NXOpen/PlaneCollection.hxx>
#include <NXOpen/Point.hxx>
#include <NXOpen/PointCollection.hxx>
#include <NXOpen/Preferences_PartModeling.hxx>
#include <NXOpen/Preferences_PartPreferences.hxx>
#include <NXOpen/Section.hxx>
#include <NXOpen/SectionCollection.hxx>
#include <NXOpen/SelectCurve.hxx>
#include <NXOpen/SelectObject.hxx>
#include <NXOpen/SelectPointList.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Spline.hxx>
#include <NXOpen/SplineCollection.hxx>
#include <NXOpen/TaggedObject.hxx>
#include <NXOpen/Unit.hxx>
#include <NXOpen/UnitCollection.hxx>
#include <NXOpen/Update.hxx>
using namespace NXOpen;
extern "C" DllExport int ufusr_ask_unload()
{
return (int)Session::LibraryUnloadOptionImmediately;
}
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
{
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
// ----------------------------------------------
// Menu: Edit->Curve->Divide...
// ----------------------------------------------
Session::UndoMarkId markId1;
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
Features::Feature *nullFeatures_Feature(NULL);
if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
{
throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
}
Features::DivideCurveBuilder *divideCurveBuilder1;
divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
Point3d origin1(0.0, 0.0, 0.0);
Vector3d normal1(0.0, 0.0, 1.0);
Plane *plane1;
plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
divideCurveBuilder1->SetBoundingPlane(plane1);
Section *section1;
section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
Expression *expression1;
expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
Section *section2;
section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
Expression *expression2;
expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
divideCurveBuilder1->SetEqualParameterSegments(5);
divideCurveBuilder1->SetEqualArcLengthSegments(5);
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);
divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);
Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
Xform *nullXform(NULL);
Point *point3;
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
divideCurveBuilder1->SetBoundingProjectPoint(point3);
Session::UndoMarkId markId2;
markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");
NXObject *nXObject1;
nXObject1 = divideCurveBuilder1->Commit();
std::vector<NXObject *> objects1;
objects1 = divideCurveBuilder1->GetCommittedObjects();
theSession->DeleteUndoMark(markId2, NULL);
theSession->SetUndoMarkName(markId1, "Divide Curve");
divideCurveBuilder1->Destroy();
try
{
// 表达式仍然在使用中。
workPart->Expressions()->Delete(expression2);
}
catch (const NXException &ex)
{
ex.AssertErrorCode(1050029);
}
section2->Destroy();
try
{
// 表达式仍然在使用中。
workPart->Expressions()->Delete(expression1);
}
catch (const NXException &ex)
{
ex.AssertErrorCode(1050029);
}
section1->Destroy();
plane1->DestroyPlane();
int nErrs1;
nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
// ----------------------------------------------
// Menu: Tools->Journal->Stop Recording
// ----------------------------------------------
}
希望大神指点
objects1 = divideCurveBuilder1->GetCommittedObjects()这个是空吗? 如果不是通常情况下,就是在这里,你可以打印看下。
另外一种方式就是生成的feature,通过feature去找对应的子对象 C:\Users\99112\Desktop
objects1 = divideCurveBuilder1->GetCommittedObjects() 的值一直是两个0,这段是录制jounal生成的,源代码就是这么获取的
我用
Features::Feature *feat1;
feat1 = divideCurveBuilder1->CommitFeature();
代替
NXObject *nXObject1;
nXObject1 = cylinderBuilder1->Commit();
也可以分割一条曲线成两条 但是我想用这两条线怎么获取他们的tag??
希望指点一下?
页:
[1]