Cancel
Showing results for 
Search instead for 
Did you mean: 

Error

Creator
Creator

Capture.PNG

How to resolve this error?

I am using builder pattern for creating sphere?

 

using System;
using NXOpen;
using NXOpenUI;
using NXOpen.UF;
using NXOpen.Utilities;
using System.Windows.Forms;

namespace sphere_builderMethod
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
/*Session theSession = Session.GetSession();
Part workPart = theSession.Parts.Work;
Part displayPart = theSession.Parts.Display;
UI theui = UI.GetUI();*/
}

private void button1_Click(object sender, EventArgs e)
{
try
{
this.Hide();

Session theSession = Session.GetSession();
Part workPart = theSession.Parts.Work;
Part displayPart = theSession.Parts.Display;
UI theui = UI.GetUI();

NXOpen.Features.SphereBuilder builder = workPart.Features.CreateSphereBuilder(null);
// define the sphere type
builder.Type = NXOpen.Features.SphereBuilder.Types.CenterPointAndDiameter;
//' Define the sphere center
Point3d center= new Point3d(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text), Convert.ToDouble(textBox3.Text));
NXOpen.Point centerPoint = workPart.Points.CreatePoint(center);
builder.CenterPoint = centerPoint;
// Define the sphere diameter
String dia ="Convert.ToDouble(textBox4.Text)";
builder.Diameter.RightHandSide = dia;
Expression ex1 = builder.Diameter;
//Define the boolean option (create, unite, etc.)
builder.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create ;
//' Commit to create the feature
NXObject sphereObject;
sphereObject = builder.Commit();
//' Destroy the builder to free memory builder.Destroy
builder.Destroy();

this.Show();
}
catch (NXOpen.NXException ex)
{
UI theui = UI.GetUI();
theui.NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
}
}
}
}

1 REPLY

Betreff: Error

Legend
Legend

Hi Logan,

 

                String dia ="Convert.ToDouble(textBox4.Text)";
                builder.Diameter.RightHandSide = dia;

What do you expect to happen in the first line. I assume its a Windows Forms application and textBox4 is a widget in it.

What you do is: you set the text Convert.ToDouble(textBox4.Text) as the right hand side of the features diameter expression.  NX is not quite sure what to do with this. You probably may want to write:

builder.Diameter.RightHandSide = textBox4.Text;

(may give unexpected results if the user types something funny in your text box)

or

builder.Diameter.Value = Convert.ToDouble(textBox4.Text);

throws an exception if your user typed funny things.

 

 

Regards,

Jan

Jan Böttcher