In the following code, setting a break point on any line has no effect. Some code is running, but it’s not this code. The dialog, a simple winform with a datagridview (not populated) and two buttons, appears. When you press the “OK” button, the dialog disappears and the prompt to select a surface appears. When a surface is selected, the dialog reappears, even though it’s not supposed to.
This is mysterious, since at one time it was designed to do this, but that functionality has been removed. As previously noted, setting a break point to find out why this is happening is pointless.
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
frmSelectProduct form = new frmSelectProduct();
form.StartPosition = FormStartPosition.CenterParent;
string res = "OK";
DialogResult dialogResult = form.ShowDialog(RhinoApp.MainWindow());
res = dialogResult.ToString();
if (res != "Cancel")
{
Rhino.DocObjects.ObjRef obref;
Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface", true, Rhino.DocObjects.ObjectType.Surface, out obref);
if (rc != Rhino.Commands.Result.Success)
return rc;
Rhino.DocObjects.RhinoObject rhobj = obref.Object();
if (rhobj == null)
return Rhino.Commands.Result.Failure;
string name = rhobj.Attributes.Name;
AddLayer(RhinoDoc.ActiveDoc, name);
int layer_index = doc.Layers.Find(name, true);
rhobj.Attributes.LayerIndex = layer_index;
rhobj.CommitChanges();
res = "Cancel";
return Result.Success;
}
else
{
return Result.Failure;
}
}
public static Rhino.Commands.Result AddLayer(Rhino.RhinoDoc doc, string strLayerName)
{
// Is the layer name valid?
if (!Rhino.DocObjects.Layer.IsValidName(strLayerName))
{
Rhino.RhinoApp.WriteLine(strLayerName + " is not a valid layer name.");
return Rhino.Commands.Result.Cancel;
}
// Does a layer with the same name already exist?
int layer_index = doc.Layers.Find(strLayerName, true);
if (layer_index >= 0)
{
Rhino.RhinoApp.WriteLine("A layer with the name {0} already exists.", strLayerName);
return Rhino.Commands.Result.Cancel;
}
// Add a new layer to the document
layer_index = doc.Layers.Add(strLayerName, System.Drawing.Color.DarkGray);
if (layer_index < 0)
{
Rhino.RhinoApp.WriteLine("Unable to add {0} layer.", strLayerName);
return Rhino.Commands.Result.Failure;
}
return Rhino.Commands.Result.Success;
}