Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#python
import lx
import lxifc
SERVER_NAME= "mop.2PointCurve"
class pointVisitor(lxifc.Visitor):
def __init__(self, pointObj, markMode):
self.pointObj = pointObj
self.values = []
self.count = 0
self.markMode = markMode
def vis_Evaluate(self):
if self.pointObj.TestMarks(self.markMode):
self.values.append(self.pointObj.ID())
self.count += 1
class MeshOp(lxifc.MeshOperation):
def mop_Evaluate(self, mesh, type, mode):
mesh = lx.object.Mesh(mesh)
if mesh.test() == False:
return
polygon = lx.object.Polygon(mesh.PolygonAccessor())
if polygon.test() == False:
return
point = lx.object.Point(mesh.PointAccessor())
if point.test() == False:
return
visitorInstance = pointVisitor(point, mode)
point.Enumerate(mode, visitorInstance, 0)
nPoints = visitorInstance.count
points = visitorInstance.values
nPoints = nPoints if nPoints % 2 == 0 else nPoints - 1
points_storage = lx.object.storage()
points_storage.setType('p')
points_storage.setSize(2)
for i in xrange(nPoints/2):
points_storage.set((points[i*2],points[i*2+1]))
polygon.New(lx.symbol.iPTYP_CURVE, points_storage, 2, 0)
mesh.SetMeshEdits(lx.symbol.f_MESHEDIT_GEOMETRY)
tags = {lx.symbol.sMESHOP_PMODEL : "."}
lx.bless(MeshOp, SERVER_NAME, tags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.