Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Selects elements that are symmetrical to the current selection.
#!/usr/bin/env python
import lx
import lxifc
import lxu.command
class GetSymmetricalVertex(lxifc.Visitor):
def __init__(self, accessor):
self.accessor = accessor
self.sym_ids = set()
def vis_Evaluate(self):
try:
if not self.accessor.OnSymmetryCenter():
sym = self.accessor.Symmetry()
if sym:
self.sym_ids.add(sym)
except:
pass
class GetSymmetricalEdge(lxifc.Visitor):
def __init__(self, accessor):
self.accessor = accessor
self.sym_ids = set()
def vis_Evaluate(self):
try:
if not self.accessor.OnSymmetryCenter():
sym = self.accessor.Symmetry()
if sym:
self.accessor.Select(sym)
self.sym_ids.add(self.accessor.Endpoints())
except:
pass
class GetSymmetricalPolygon(lxifc.Visitor):
def __init__(self, accessor):
self.accessor = accessor
self.sym_ids = set()
def vis_Evaluate(self):
try:
sym = self.accessor.Symmetry()
if sym:
self.sym_ids.add(sym)
except:
pass
class SelectSymmetrical_Cmd(lxu.command.BasicCommand):
def __init__(self):
lxu.command.BasicCommand.__init__ (self)
def cmd_Interact(self):
pass
def cmd_UserName(self):
return 'Select Symmetrical'
def cmd_Desc(self):
return 'Selects elements that are symmetrical to the current selection.'
def cmd_Tooltip(self):
return 'Selects elements that are symmetrical to the current selection.'
def cmd_Help(self):
return 'http://www.farfarer.com/'
def basic_ButtonName(self):
return 'Select Symmetrical'
def cmd_Flags(self):
return lx.symbol.fCMD_SELECT | lx.symbol.fCMD_MODEL | lx.symbol.fCMD_UNDO
def basic_Enable(self, msg):
return True
def basic_Execute(self, msg, flags):
sel_svc = lx.service.Selection()
mesh_svc = lx.service.Mesh()
layer_svc = lx.service.Layer()
mode = mesh_svc.ModeCompose('select', 'hide lock')
layer_scan = lx.object.LayerScan(layer_svc.ScanAllocate(lx.symbol.f_LAYERSCAN_ACTIVE | lx.symbol.f_LAYERSCAN_MARKALL))
if not layer_scan.test():
return
types = lx.object.storage('i', 4)
types.set((lx.symbol.iSEL_VERTEX, lx.symbol.iSEL_EDGE, lx.symbol.iSEL_POLYGON, 0))
currentType = sel_svc.CurrentType(types)
sel_svc.StartBatch ()
for l in xrange(layer_scan.Count()):
mesh = lx.object.Mesh (layer_scan.MeshBase (l))
point = lx.object.Point (mesh.PointAccessor ())
edge = lx.object.Edge (mesh.EdgeAccessor ())
polygon = lx.object.Polygon (mesh.PolygonAccessor ())
if not point.test () or not edge.test () or not polygon.test ():
continue
if currentType == lx.symbol.iSEL_VERTEX:
getSymVertex = GetSymmetricalVertex(point)
point.Enumerate(mode, getSymVertex, 0)
sel_type_vertex = sel_svc.LookupType (lx.symbol.sSELTYP_VERTEX)
vertex_pkt_trans = lx.object.VertexPacketTranslation (sel_svc.Allocate(lx.symbol.sSELTYP_VERTEX))
for vertex_id in getSymVertex.sym_ids:
sel_svc.Select (lx.symbol.iSEL_VERTEX, vertex_pkt_trans.Packet (vertex_id, 0, mesh))
elif currentType == lx.symbol.iSEL_EDGE:
getSymEdge = GetSymmetricalEdge(edge)
edge.Enumerate(mode, getSymEdge, 0)
sel_type_edge = sel_svc.LookupType (lx.symbol.sSELTYP_EDGE)
edge_pkt_trans = lx.object.EdgePacketTranslation (sel_svc.Allocate(lx.symbol.sSELTYP_EDGE))
for edge_id in getSymEdge.sym_ids:
sel_svc.Select (lx.symbol.iSEL_EDGE, edge_pkt_trans.Packet (edge_id[0], edge_id[1], 0, mesh))
elif currentType == lx.symbol.iSEL_POLYGON:
getSymPolygon = GetSymmetricalPolygon(polygon)
polygon.Enumerate(mode, getSymPolygon, 0)
polygon_pkt_trans = lx.object.PolygonPacketTranslation (sel_svc.Allocate(lx.symbol.sSELTYP_POLYGON))
print getSymPolygon.sym_ids
for poly_id in getSymPolygon.sym_ids:
sel_svc.Select (lx.symbol.iSEL_POLYGON, polygon_pkt_trans.Packet (poly_id, mesh))
layer_scan.Apply()
sel_svc.EndBatch ()
lx.bless(SelectSymmetrical_Cmd, 'ffr.selectSymmetrical')
@RumbaYou

This comment has been minimized.

Copy link

commented Feb 22, 2019

image
Hi!
Script error((
MODO version 12v1

Hope this helps You.
Tnx!

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.