These examples are a little esoteric for newcomers,Like how do you create a new managed instance.
Can you tell me directly that How to convert a line into Spline Shape .
This article finally discussed also did not have a result, very regrettable
It is funny, but I just found my own thread with same exact question.
And it turns out that you have to add an edit spline modifier to the line object to convert it to splineshape
make a line object, select it and run
(
format "-> %\n" (classof $.baseobject)
-- uncomment and check if it works now ;)
-- if classof $.baseobject == line do
-- (
-- addModifier $ (edit_spline())
-- )
g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
inode = g.coreinterface7.getselnode 0
os = inode.evalworldstate g.coreinterface7.time true
obj = os.obj
cid = g.class_id.create splineshape.classid[1] splineshape.classid[2]
convertible_to_splineshape = (obj.CanConvertToType cid) != 0
if convertible_to_splineshape do
(
converted = obj.ConvertToType currenttime.ticks cid
inode.ObjectRef = converted
)
format "-> %\n" (classof $.baseobject)
)
Your code will work for any shape(Shape Object) but line.Like you said,Casting to some other type is a dead end.
The only way to do that is to add the Edit_Spline modifier.But when it is refreshed, it disappears again. Whether to put it to Managed.If there are other modifier on the line, it is also a very tricky problem.
IInterface core = g.COREInterface;
int t = core.Time;
int modstyle = core.CommandPanelTaskMode;
IClass_ID EDITABLESPLINE_CLASS_ID = g.Class_ID.Create(96,0);
object objMod = core.CreateInstance(SClass_ID.Osm, EDITABLESPLINE_CLASS_ID);
IModifier mod = (IModifier)objMod;
IIDerivedObject dobj = g.CreateDerivedObject(obj);
dobj.AddModifier(mod, null, 0); // top of stack
oldNode.ObjectRef = dobj;
core.CollapseNode(oldNode, false);
When I used OutlineMove in ISplineShape state.It goes back to a line.Miracle!!Do I have to update it, or there is an important step missing
ISplineShape spl = (ISplineShape)sobj;
spl.OutlineMove(t,10);
just a quick dirty test code
static public ISplineShape GetSplineShape(uint handle)
{
IGlobal global = GlobalInterface.Instance;
var node = global.COREInterface7.GetINodeByHandle(handle);
IObject obj = node.EvalWorldState(global.COREInterface.Time, true).Obj;
if (obj.CanConvertToType(global.SplineShapeClassID) > 0)
{
IInterface core = global.COREInterface;
int t = core.Time;
int modstyle = core.CommandPanelTaskMode;
IClass_ID EDITABLESPLINE_CLASS_ID = global.Class_ID.Create(96, 0);
object objMod = core.CreateInstance(SClass_ID.Osm, EDITABLESPLINE_CLASS_ID);
IModifier mod = (IModifier)objMod;
IIDerivedObject dobj = global.CreateDerivedObject(obj);
dobj.AddModifier(mod, null, 0); // top of stack
node.ObjectRef = dobj;
core.CollapseNode(node, false);
ISplineShape ss = (ISplineShape)node.ObjectRef.ConvertToType(global.COREInterface.Time, global.SplineShapeClassID);
return ss;
}
return null;
}
mxs test code
classof $
x = getsplineshape $.inode.handle -- c# method
setSplineSelection $ #(1)
max modify mode
x.BeginOutlineMove currenttime.ticks;
x.outlinemove currenttime.ticks 10.0
x.EndOutlineMove currenttime.ticks true
redrawViews()
classof $
using Autodesk.Max;
namespace SRYShapeTools
{
public class SRYSplineShape
{
static public ISplineShape GetSplineShape(uint handle)
{
IGlobal global = GlobalInterface.Instance;
var node = global.COREInterface7.GetINodeByHandle(handle);
IObject obj = node.EvalWorldState(global.COREInterface.Time, true).Obj;
if (obj.CanConvertToType(global.SplineShapeClassID) > 0)
{
IInterface core = global.COREInterface;
int t = core.Time;
int modstyle = core.CommandPanelTaskMode;
IClass_ID EDITABLESPLINE_CLASS_ID = global.Class_ID.Create(96, 0);
object objMod = core.CreateInstance(SClass_ID.Osm, EDITABLESPLINE_CLASS_ID);
IModifier mod = (IModifier)objMod;
IIDerivedObject dobj = global.CreateDerivedObject(obj);
dobj.AddModifier(mod, null, 0); // top of stack
node.ObjectRef = dobj;
core.CollapseNode(node, false);
ISplineShape ss = (ISplineShape)node.ObjectRef.ConvertToType(global.COREInterface.Time, global.SplineShapeClassID);
return ss;
}
return null;
}
}
}
mxs code
dotNet.loadAssembly @"c:\SRYShapeTools.dll"
SRYgroupClass = dotNetObject "SRYShapeTools.SRYSplineShape"
classof $
x = SRYgroupClass.GetSplineShape $.inode.handle -- c# method
setSplineSelection $ #(1)
max modify mode
x.BeginOutlineMove currenttime.ticks;
x.outlinemove currenttime.ticks 10.0
x.EndOutlineMove currenttime.ticks true
>RedrawViews()
classof $
Same code, different results, very strange
x.BeginOutlineMove currenttime.ticks;
x.outlinemove currenttime.ticks 10.0
x.EndOutlineMove currenttime.ticks true
These three lines run, and it goes back to line.
maybe it is something undo related? it is worth checking with undo off
try it with different max versions and different line objects to ensure that it isn’t a bug
That’s exactly what you said, I add “with undo on” in mxs code.If I don’t have to undo the function, it’s not Complete function.Do you have any good suggestions?
It looks like you need two separate undo records, one for the conversion operation, second for the operation on spline like outline or similar