Three months ago, I asked a question about How to build a function object like the built-ins?
Today, I used a solution proposed by István Zachar
Options[CAGDBSplineFunction] = {SplineDegree -> 3, SplineKnots -> Automatic};
CAGDBSplineFunction::invdeg =
"Value of option SplineDegree \[Rule] `1` should be a machine integer
or a symbol Automatic.";
CAGDBSplineFunction::invknots =
"Value of option SplineKnots \[Rule] `1` should be a valid knots sequence
or a symbol Automatic.";
CAGDBSplineFunction /:
MakeBoxes[obj_CAGDBSplineFunction,
form : (StandardForm | TraditionalForm)] :=
Module[{o = List @@ obj, n, crtlpts, shown, hidden, opts, options,
icon = Graphics[{Blue, Circle[]}, ImageSize -> 35], sd, sk},
ctrlpts = First@o;
n = Length@crtlpts - 1;
opts = Rest[o];
options = Options[CAGDBSplineFunction];
sd = SplineDegree /. opts /. options;
sk = SplineKnots /. opts /. options;
(*check the validness of SplineDegree*)
If[! IntegerQ[sd],
Message[CAGDBSplineFunction::invdeg, sd];
Return[$Failed]
];
(*check the validness of SplineKnots*)
If[sk === Automatic,
sk =
Join[
ConstantArray[0.0, sd + 1],
Range[n - sd]/(n - sd + 1), ConstantArray[1.0, sd + 1]],
If[n + 1 + sd != Length[sk] - 1 || ! OrderedQ[sk],
Message[CAGDBSplineFunction::invknots, sk, n + 2 + sd];
Return[$Failed]
]
];
shown =
{{BoxForm`MakeSummaryItem[{"Argument count: ", 1}, form], SpanFromLeft},
{BoxForm`MakeSummaryItem[{"Output dimention: ", 2}, form]}};
hidden =
{{BoxForm`MakeSummaryItem[{"Degree: ", sd}, form]},
{BoxForm`MakeSummaryItem[{"Knots: ", sk}, form]},
{BoxForm`MakeSummaryItem[{"Control points: ", ctrlpts}, form]}};
BoxForm`ArrangeSummaryBox[
CAGDBSplineFunction, o, icon, shown, hidden, form,
"Interpretable" -> False]
]
Test
pts = {{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}};
CAGDBSplineFunction[pts, SplineDegree -> 4]

However, when the option value of SplineDegree is invaid, Mathematcia will throw the following error:
CAGDBSplineFunction[pts, SplineDegree -> 2.3]

An unknown box name (Return) was sent as the BoxForm for the expression. Check the format rules for the expression.

Return[$Failed, Module]instead of justReturn[$Failed]. – Kuba Jan 12 '16 at 13:19MakeBoxesisHoldAllComplete, and boxes are for display only. Therefore it is incumbent on you to ensure you pass fully-formed, correct expressions toMakeBoxes, so that within the generated boxes there is no Mathematica code. – Oleksandr R. Jan 12 '16 at 13:20