Last active
August 23, 2018 00:48
-
-
Save Farfarer/dd2d00c32b247084b38d03500fdfb7de to your computer and use it in GitHub Desktop.
Selects all polygons which face straight up and are at or below 0 in the Y axis.
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
#!/usr/bin/env python | |
import lx | |
import lxifc | |
import lxu.command | |
class SelectGround(lxifc.Visitor): | |
def __init__(self, poly, mesh): | |
self.poly = poly | |
self.mesh = mesh | |
self.sel_svc = lx.service.Selection() | |
self.sel_type_polygon = self.sel_svc.LookupType(lx.symbol.sSELTYP_POLYGON) | |
self.trans = lx.object.PolygonPacketTranslation(self.sel_svc.Allocate(lx.symbol.sSELTYP_POLYGON)) | |
def vis_Evaluate(self): | |
if self.poly.Normal()[1] > 0.999 and self.poly.RepresentativePosition()[1] <= 0.01: | |
sel_pkt = self.trans.Packet(self.poly.ID(), self.mesh) | |
self.sel_svc.Select(self.sel_type_polygon, sel_pkt) | |
class SelectGround_Cmd(lxu.command.BasicCommand): | |
def __init__(self): | |
lxu.command.BasicCommand.__init__(self) | |
def cmd_UserName(self): | |
return 'Select Ground Polys' | |
def basic_ButtonName(self): | |
return 'Select Ground Polys' | |
def cmd_Desc(self): | |
return 'Select all polyons at or below ground level which face upwards' | |
def cmd_Tooltip(self): | |
return 'Select all polyons at or below ground level which face upwards' | |
def cmd_Help(self): | |
return 'https://farfarer.com' | |
def cmd_Flags(self): | |
return lx.symbol.fCMD_UNDO | lx.symbol.fCMD_SELECT | |
def basic_Enable(self, msg): | |
return True | |
def cmd_Interact(self): | |
pass | |
def basic_Execute(self, msg, flags): | |
layer_svc = lx.service.Layer() | |
layer_scan = lx.object.LayerScan(layer_svc.ScanAllocate(lx.symbol.f_LAYERSCAN_ACTIVE)) | |
if not layer_scan.test(): | |
return | |
layer_count = layer_scan.Count() | |
if layer_count == 0: | |
return | |
sel_svc = lx.service.Selection() | |
# If you don't want to drop the current polygon selection first, remove the following line. | |
sel_svc.Drop(sel_svc.LookupType(lx.symbol.sSELTYP_POLYGON)) | |
sel_svc.StartBatch() | |
for layer_idx in xrange(layer_count): | |
mesh = lx.object.Mesh(layer_scan.MeshBase(layer_idx)) | |
if not mesh.test(): | |
continue | |
polygon_count = mesh.PolygonCount() | |
if polygon_count == 0: | |
continue | |
polygon = mesh.PolygonAccessor() | |
if not polygon.test(): | |
continue | |
selectGround = SelectGround(polygon, mesh) | |
polygon.Enumerate(lx.symbol.iMARK_ANY, selectGround, 0) | |
layer_scan.Apply() | |
sel_svc.EndBatch() | |
lx.bless(SelectGround_Cmd, 'ffr.selectGroundPolys') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment