MakeDeformable failed

The curve in the attached file causes MakeDeformable to fail.

To replicate,

  • Use the command defined as follows:
using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;

namespace LayupRH.Commands
{
    public class MyMakeDeformableTest : Command
    {
        public MyMakeDeformableTest()
        {
            Instance = this;
        }

        public static MyMakeDeformableTest Instance { get; private set; }

        public override string EnglishName => "MyMakeDeformableTest";

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            using GetObject go = new();
            go.SetCommandPrompt("Choose a curve");
            go.GeometryFilter = ObjectType.Curve;
            if (go.Get() == GetResult.Cancel)
            {
                return Result.Cancel;
            }
            Curve curve = go.Object(0).Curve();
            if (curve.MakeDeformable())
            {
                RhinoApp.WriteLine("Successfully made deformable");
            }
            else
            {
                RhinoApp.WriteLine("Failed to make deformable");
            }
            Curve nurbsCurve = curve.ToNurbsCurve();
            if (nurbsCurve != null)
            {
                RhinoApp.WriteLine("Successfully made into NURBS");
                if (nurbsCurve.MakeDeformable())
                {
                    RhinoApp.WriteLine("Successfully made NURBS curve deformable");
                }
                else
                {
                    RhinoApp.WriteLine("Failed to make NURBS curve deformable");
                }
            } 
            else
            {
                RhinoApp.WriteLine("Failed to make into Nurbs");
            }
            return Result.Success;
        }
    }
}

The result is that MakeDeformable fails on the original curve, but ToNurbsCurve succeeds and MakeDeformable succeeds on that NURBS curve. This is not the same problem found in RC MakeDeformable() question – the curve is internally an ArcCurve, but since the exposed type is Curve, it should be able to change the representation to something deformable without changing the type. Why does MakeDeformable fail on the curve instead of just calling ToNurbsCurve in this case? Is there an alternative to MakeDeformable that I can use more reliably?

Thanks,
- Russell

no - see example below.

In polymorphism, the most derived and overridden class member is called.

using System;

namespace PolymorphismExample
{
    // Base class with a virtual method
    public class BaseClass
    {
        // Virtual method that can be overridden by derived classes
        public virtual void Speak()
        {
            Console.WriteLine("Base Hello");
        }
    }

    // Derived class A overrides the Speak method
    public class DerivedA : BaseClass
    {
        public override void Speak()
        {
            Console.WriteLine("A Hello");
        }
    }

    // Derived class B overrides the Speak method
    public class DerivedB : BaseClass
    {
        public override void Speak()
        {
            Console.WriteLine("B Hello");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // Instantiate objects of DerivedA and BaseClass
            DerivedA myA = new DerivedA();
            BaseClass baseObj = myA;  // BaseClass reference to DerivedA object

            // Call the Speak method on DerivedA object using base class reference
            baseObj.Speak();  // This will call DerivedA's Speak() due to polymorphism

            // Instantiate an object of DerivedB
            DerivedB myB = new DerivedB();
            baseObj = myB;  // BaseClass reference to DerivedB object

            // Call the Speak method on DerivedB object using base class reference
            baseObj.Speak();  // This will call DerivedB's Speak() due to polymorphism

            // Wait for user input before exiting
            //Console.ReadLine();
        }
    }
}

test here online

this means, you are calling the ArcCurves implementation (return false) of the MakeDeformable Function - even if you assign it to a reference typed as Curve. baseObj in above example.

the ToNurbsCurve() approach is the correct way to do it as far is i understand it.

hope this explains it.

kind regards - tom

Yep, seems like I misunderstood how polymorphism would behave in this case. I’ve already written a simple function to call ToNurbsCurve as a backup, and it seems that that’s what I’ll have to use in my code.

Curve curve = GetSomeCurve();
...
if (!curve.MakeDeformable())
{
  NurbsCurve nurb = curve.ToNurbsCurve();
  if (null != nurb)
    curve = nurb;
}

– Dale