Created
February 5, 2017 16:19
-
-
Save rockjail/cd7ac41791a40004803cf74cba74b837 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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