NXOpen::Curve* createCurve(NXOpen::Point* start,NXOpen::Point* end){ NXOpen::Session::UndoMarkId markId; NXOpen::Part* workPart; NXOpen::Features::AssociativeLine *nullFeatures_AssociativeLine(NULL); NXOpen::Features::AssociativeLineBuilder *associativeLineBuilder; NXOpen::Curve* curve; NXOpen::Session* theSession = NXOpen::Session::GetSession(); workPart = theSession->Parts()->Work(); markId = theSession->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "MIDCreateCurve"); if ( !workPart->Preferences()->Modeling()->GetHistoryMode() ){ throw NXOpen::NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."); } associativeLineBuilder = workPart->BaseFeatures()->CreateAssociativeLineBuilder(nullFeatures_AssociativeLine); associativeLineBuilder->Limits()->StartLimit()->SetLimitOption(NXOpen::GeometricUtilities::CurveExtendData::LimitOptionsAtPoint); associativeLineBuilder->Limits()->StartLimit()->Distance()->SetRightHandSide("0"); associativeLineBuilder->Limits()->EndLimit()->SetLimitOption(NXOpen::GeometricUtilities::CurveExtendData::LimitOptionsAtPoint); associativeLineBuilder->Limits()->EndLimit()->Distance()->SetRightHandSide("0"); associativeLineBuilder->StartAngle()->SetRightHandSide("0"); associativeLineBuilder->EndAngle()->SetRightHandSide("0"); associativeLineBuilder->SetStartPointOptions(NXOpen::Features::AssociativeLineBuilder::StartOptionPoint); associativeLineBuilder->SetEndPointOptions(NXOpen::Features::AssociativeLineBuilder::EndOptionPoint); associativeLineBuilder->StartPoint()->SetValue(start); associativeLineBuilder->EndPoint()->SetValue(end); NXOpen::NXObject* obj = associativeLineBuilder->Commit(); //Wirft die Exception NXOpen::Features::AssociativeLine* l = dynamic_cast(obj); std::vector e = l->GetEntities(); curve = dynamic_cast(e.at(0)); theSession->DeleteUndoMark(markId, NULL); associativeLineBuilder->Destroy(); return curve; } int count = 0; NXOpen::Point* createPoint(double x,double y,double z){ NXOpen::Expression* exp[3]; NXOpen::Scalar *sca[3]; std::stringstream s; NXOpen::Point *point; NXOpen::Features::Feature *nullFeature(NULL); NXOpen::Features::PointFeatureBuilder *pointFeatureBuilder; NXOpen::NXObject *nXObject; NXOpen::Part* workPart = NXOpen::Session::GetSession()->Parts()->Work(); NXOpen::Unit *unit(dynamic_cast(workPart->UnitCollection()->FindObject("MilliMeter"))); //Expressions erstellen s << "p"<< count++ <<"_x=" << x; //count ist eine globale Variable vom Typ integer exp[0] = workPart->Expressions()->CreateSystemExpressionWithUnits(s.str().c_str(), unit); s.str(""); s << "p"<< count++ <<"_y=" << y; exp[1] = workPart->Expressions()->CreateSystemExpressionWithUnits(s.str().c_str(), unit); s.str(""); s << "p"<< count++ <<"_z=" << z; exp[2] = workPart->Expressions()->CreateSystemExpressionWithUnits(s.str().c_str(), unit); //Skalare erstellen sca[0] = workPart->Scalars()->CreateScalarExpression(exp[0], NXOpen::Scalar::DimensionalityTypeNone, NXOpen::SmartObject::UpdateOptionWithinModeling); sca[1] = workPart->Scalars()->CreateScalarExpression(exp[1], NXOpen::Scalar::DimensionalityTypeNone, NXOpen::SmartObject::UpdateOptionWithinModeling); sca[2] = workPart->Scalars()->CreateScalarExpression(exp[2], NXOpen::Scalar::DimensionalityTypeNone, NXOpen::SmartObject::UpdateOptionWithinModeling); //Punkt erstellen point = workPart->Points()->CreatePoint(sca[0], sca[1], sca[2], NXOpen::SmartObject::UpdateOptionWithinModeling); point->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible); if ( !workPart->Preferences()->Modeling()->GetHistoryMode() ) throw NXOpen::NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."); pointFeatureBuilder = workPart->BaseFeatures()->CreatePointFeatureBuilder(nullFeature); pointFeatureBuilder->SetPoint(point); nXObject = pointFeatureBuilder->Commit(); pointFeatureBuilder->Destroy(); return point; } void foo (){ NXOpen::Point* p0 = createPoint(0,0,0); NXOpen::Point* p1 = createPoint(10,0,0); NXOpen::Curve* c = createCurve(p0,p1); //Exception }