Convert Line to SplineShape (IShapeObject to ISplineShape)


#1

I’ve planned to utilize ISpline3D method SelfIntersects() to detect spline self intersections, but seems like there’s no way to convert lines to splineshapes.
convertToSplineShape seems useless in this case.
Any ideas?

ln: shape : line
ln: shape : line – still not a splineshape :frowning:
ss: shape : SplineShape
ln: dotNetObject:Autodesk.Max.Wrappers.ShapeObject
ss: dotNetObject:Autodesk.Max.Wrappers.SplineShape


(

ln = line()
addNewSpline ln
addKnot ln 1 #corner #line [1,0,0]
addKnot ln 1 #corner #line [5,0,0]
format "ln: % : %
" (superClassOf ln) (classof ln)    
convertToSplineShape ln; updateShape ln
format "ln: % : % -- still not a splineshape :(
" (superClassOf ln) (classof ln)

ss = SplineShape()
addNewSpline ss
addKnot ss 1 #corner #line [-5,0,0]
addKnot ss 1 #corner #line [-1,0,0]
format "ss: % : %
" (superClassOf ss) (classof ss)


g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance

lnObj = (
    inode = g.COREInterface7.GetINodeByHandle( ln.inode.handle )
    obj = inode.EvalWorldState g.COREInterface.Time true asdotnetobject:true    
    obj = obj.Obj
    obj.ConvertToType g.COREInterface.Time g.SplineShapeClassID -- No conversion whatsoever ;(
)

format "ln: %
" lnObj


ssObj = (
    inode = g.COREInterface7.GetINodeByHandle( ss.inode.handle )
    obj   = inode.EvalWorldState g.COREInterface.Time true asdotnetobject:true
    obj.Obj
)
format "ss: %
" ssObj
)

An old question
#2

[quote=Serejah][/quote]Ugly, but you will have the line “converted” to splineShape.


(
    ln = line()
    addNewSpline ln
    addKnot ln 1 #corner #line [1,0,0]
    addKnot ln 1 #corner #line [5,0,0]
    format "ln: % : %
" (superClassOf ln) (classof ln)
    convertToSplineShape ln; updateShape ln
    format "ln: % : % -- still not a splineshape :(
" (superClassOf ln) (classof ln)

    ss = SplineShape()
    
    addAndWeld ss ln -1
    
)

Strange, the last line should be: addAndWeld ss ln -1, not - 1.


#3

Thanks. I tried that too.
That’s ridiculous how could I forget about edit_spline modifier .


ln = line()
addNewSpline ln
addKnot ln 1 #corner #line [1,0,0]
addKnot ln 1 #corner #line [5,0,0]
format "ln: % : %
" (superClassOf ln) (classof ln)    
addModifier ln (Edit_Spline())
format "ln: % : %
" (superClassOf ln) (classof ln)


#4

Will you convert the ln to splineShape after the Edit_Spline modifier is added?


#5

It depends whether this shape has self intersections or not.
If it has no intersections and there are some other modifiers in stack then edit_spline can be removed afterwards.

upd. seems like any modifier is stack turns line into a splineshape, even EmpyModifier()


#6

I am asking because I am curious which is faster when heavy spline(hundreds of splines, knots, etc.) is used - adding a modifier or attaching to an empty splineShape.


#7

you probably have to do the same as i do using c++

so… you have:


    inode = g.COREInterface7.GetINodeByHandle( ln.inode.handle )
    obj = inode.EvalWorldState g.COREInterface.Time true asdotnetobject:true
    obj = obj.Obj

where obj is ShapeObject

after that you have to make PolyShape using [b]obj.MakePolyShape

[/b]PolyShape has lines property where every line is [b]PolyLine

[/b]which has a method SelfIntersects


#8

Thanks, Denis.
Sounds like a way to go, but MakePolyShape needs IPolyShape passed as reference and I can’t seem to find a constructor for it.


#9

shoot… there is no constructor for IPolyShape (as well as for ISpline3D). let’s continue thinking…


#10

g.PolyShape.Create()


#11

very nice!


#12

Not in 2014 unfortunately.

[quote=]g.polyshape
– Unknown property: “polyshape” in dotNetObject:Autodesk.Max.Global[/quote]


#13

That’s how I do it in pure C#:


            ISplineShape newSpline1 -- Let's says you already have the SplineShape 'newSpline1'
         
         -- To get the  ISpline3D
                IBezierShape bzs = newSpline1.Shape;    --IBezierShape got from ISplineShape newSpline1
                ISpline3D the_Path = bzs.GetSpline(numSpline);    --ISpline3D filled with numSpline spline of IBezierShape bzs
         -- To get the IPolyLine
                SClass_ID mySClass = SClass_ID.Shape;  --shape SuperClass
                IClass_ID myClass = global.Class_ID.Create((uint)BuiltInClassIDA.LINEARSHAPE_CLASS_ID, 0); --ILinearShape class

                IBezierShape bzs = newSpline1.Shape;    --IBezierShape got from ISplineShape newSpline1
                ILinearShape iln = ip.CreateInstance(mySClass, myClass) as ILinearShape;
                IPolyShape pshp = iln.Shape;    -- Creates empty IPolyShape from empty ILinearShape
                bzs.MakePolyShape(pshp, numsteps, optimize);   --Get the IPolyShape from the IBezierShape
                IPolyLine the_Path = pshp.Lines[numSpline]; --Gets the IPolyLine from the IPolyShape

Edit: to get the ISplineShape from Line, the only way I found was adding a modifier, then collapsing.


#14

i think it doesn’t create empty… it points to existing polyshape


#15

Hi, aandres!
Casting to some other type is a dead end.
createInstance
returns IntPtr which I can’t cast to linearshape.
Maybe we can directly create polyShape using createInstance, but don’t know how and if it is possible at all.
I think adding an empty modifier shouldn’t be a big deal in terms of performance.

[quote=]dotNetObject:Autodesk.Max.Global
dotNetObject:Autodesk.Max.SClass_ID
dotNetObject:Autodesk.Max.Wrappers.Class_ID
– Error occurred in anonymous codeblock; filename: ; position: 308; line: 6
– Unable to convert: dotNetObject:System.IntPtr to type: Autodesk.Max.ILinearShape
OK[/quote]


g        = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
mySClass = (dotNetClass "Autodesk.Max.SClass_ID").Shape
myClass  = g.Class_ID.Create ((dotNetClass "Autodesk.Max.BuiltInClassIDA").LINEARSHAPE_CLASS_ID).value__ 0 --ILinearShape class
iln      = dotNetObject "Autodesk.Max.ilinearshape" (g.CreateInstance mySClass myClass asdotnetobject:true) -- ILinearShape 
-- ps       = iln.Shape