I'm trying to get the vertices of a spline in python with out success. this spline can have several subsplines.
for example here is a maxscript that does the same but have been unable to port that to maxplus.
fn getVertex splines = ( thePoints = #() -- array of vertex positions theShapes = for o in splines where superclassof o == Shape collect o for o = 1 to theShapes.count do ( local subLineCount = numSplines theShapes[o] -- number of splines in the current spline for s = 1 to subLineCount do ( local numOfPoints = (numknots theShapes[o] s) for i = 1 to numOfPoints do ( tmpNod = [0,0,0] tmp = (getknotpoint theShapes[o] s i) tmpNod.x = tmp.x tmpNod.y = tmp.y tmpNod.z = tmp.z append thePoints tmpNod ) ) ) return thePoints )
and here is one of my attempts in python. which returns some 3dpoints but the positions are all wrong, can some one help out?
def readShapes(node): points = [] # check if its a spline if node.Object.GetClassName() == "SplineShape": Shp = MaxPlus.SplineShape__CastFrom(node.GetObject()) numVerts = Shp.GetNumberOfVertices() for v in range(numVerts): p = Shp.GetPoint(v) print p points.append(p) return points n = MaxPlus.SelectionManager.GetNode(0) eadShapes(n)
Thanks,
Guillermo Leal
Solved! Go to Solution.
Solved by Swordslayer. Go to Solution.
GetPoint is not the same as GetKnotPoint, more like GetPointPos in maxscript. It will return positions of both the tangents and the knots, i.e. in, knot, out etc. Also the returned points are in the object space, you have to multiply them by the node transformation matrix:
def readShapes(node): points = [] # check if its a spline if node.Object.GetClassName() == "SplineShape": TM = node.GetObjectTM(MaxPlus.Core.GetCurrentTime()) Shp = MaxPlus.SplineShape__CastFrom(node.GetObject()) numVerts = Shp.GetNumberOfVertices() for v in range(1, 3*numVerts, 3): p = TM.PointTransform(Shp.GetPoint(v)) print p points.append(p) return points
thanks for you answer.
i whish the max python documentation was better and we had more samples..
one more question, do you know of a way to go trough several subsplines in a spline? like the maxscript code above
Guillermo Leal.
Hi Swordslayer,
Could you please update the code without MAXPlus and just used Pymxs? because the MAXPlus is not supported for python in 3dmax 2023
Thanks in advance,
I'd tell you to use the original maxscript snippet but since that one is needlessly complex, here you go:
from pymxs import runtime as rt
def getShapePoints(node):
return [rt.getPointPos(node, p) for p in range(2, rt.numPoints(node), 3)]
And the same thing in maxscript:
fn getShapePoints node =
for p in 2 to numPoints node by 3 collect getPointPos node p
@mjdb3d wrote:
is there any new python API documentation that I can use?
MAXScript reference.