Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Spline Vertices in Python?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
gmlealll5
1252 Views, 7 Replies

Get Spline Vertices in Python?

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

7 REPLIES 7
Message 2 of 8
Swordslayer
in reply to: gmlealll5

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

 

Message 3 of 8
gmlealll5
in reply to: Swordslayer

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.

Message 4 of 8
mjdb3d
in reply to: Swordslayer

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,

 
Message 5 of 8
Swordslayer
in reply to: mjdb3d

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
Message 6 of 8
mjdb3d
in reply to: Swordslayer

Thank you for your quick response, one more question please, is there any new python API documentation that I can use?
Message 7 of 8
Swordslayer
in reply to: mjdb3d
Message 8 of 8
mjdb3d
in reply to: Swordslayer

Thank you very much, 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report