Skip to content

Instantly share code, notes, and snippets.

Created November 7, 2019 10:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mattcox/f26e18950187b687415b0e7b678fb110 to your computer and use it in GitHub Desktop.
Demonstrates how to print vertex information for the points on an ILxCurve.
import lx
import lxifc
import lxu.command
import modo
class Command(lxu.command.BasicCommand):
def __init__(self):
self.mMeshItems = modo.Scene().selectedByType(lx.symbol.sITYPE_MESH)
def cmd_Flags(self):
return lx.symbol.fCMD_UI
def basic_Enable(self, msg):
return bool(self.mMeshItems)
def PrintCurveData(self, index, curve):
message = "Curve {}\n".format(index)
message += " Curve Length: {}\n".format(curve.Length())
# Get the mesh and polygon for the curve.
attributes = lx.object.Attributes(curve)
meshAttributesIndex = attributes.Lookup("mesh")
mesh = lx.object.Mesh(attributes.Value(meshAttributesIndex, 0))
polygonAttributesIndex = attributes.Lookup("polygon")
polygonAccessor = lx.object.Polygon(attributes.Value(polygonAttributesIndex, 0))
# Get the point accessor the mesh
pointAccessor = lx.object.Point(mesh.PointAccessor())
# Loop over the points on the polygon.
vertexCount = polygonAccessor.VertexCount()
message += " Point Count: {}\n".format(vertexCount)
for i in range(vertexCount):
# The polygon accessor is pointing at the curve polygon - setup the point accessor.
pointID = polygonAccessor.VertexByIndex(i)
message += " Point {}\n".format(i)
message += " Point Index: {}\n".format(pointAccessor.Index())
# Get the point position and print it out.
position = pointAccessor.Pos()
message += " Point Position: [{}, {}, {}]\n".format(position[0], position[1], position[2])
# Find the closest point on the curve to the point position and print the parameter.
parameter = curve.Closest(position)[0]
message += " Point Parameter: {}\n".format(parameter)
print message
def basic_Execute(self, msg, flags):
sceneService = lx.service.Scene()
curveChannel = sceneService.ItemTypeGetTag(sceneService.ItemTypeLookup(lx.symbol.sITYPE_MESH), lx.symbol.sPKG_CURVES_CHANNEL, 0)
channelRead = None
for meshItem in self.mMeshItems:
# Get a channel read object for reading the curve group.
if channelRead == None:
scene = meshItem.Context()
channelRead = lx.object.ChannelRead(scene.Channels(None, lx.service.Selection().GetTime()))
if channelRead == None:
raise lx.result.FAILED
# Read the curve group channel from the item. The curve group contains the curves.
valueReference = lx.object.ValueReference(channelRead.ValueObj(meshItem, meshItem.ChannelLookup(curveChannel)))
# Loop over the curves and print the debug data for each one.
curveGroup = lx.object.CurveGroup(valueReference.GetObject())
curveCount = curveGroup.Count()
for i in range(curveCount):
curve = lx.object.Curve(curveGroup.ByIndex(i))
self.PrintCurveData(i, curve)
lx.bless(Command, "mesh.dumpCurve")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment