Danielm103 Posted 3 hours ago Posted 3 hours ago Filters Instead of creating a dedicated ResultBuffer class like in .NET, I decided to build a wrapper for Python’s built in types. Throughout the API, resbuf* or ResultBuffer are simply a list of tuples, in the format of a group code and a value typedValues = [(TYPE, VALUE)] Depending on the context the group code may be a Lisp type code, or in the case of selection sets, DXF codes. Here are two possible formats # long format filter = [ (Db.DxfCode.kDxfStart, "TEXT,LWPOLYLINE,LINE"), (Db.DxfCode.kDxfOperator, "<OR"), (Db.DxfCode.kDxfLayerName, "0"), (Db.DxfCode.kDxfLayerName, "8"), (Db.DxfCode.kDxfOperator, "OR>"), ] # short format filter = [ (0, "TEXT,LWPOLYLINE,LINE"), (-4, "<OR"), (8, "Layer1"), (8, "Layer2"), (8, "Layer3"), (-4, "OR>"), ] Quote
Danielm103 Posted 3 hours ago Author Posted 3 hours ago SelectionSet filters can also be inline Ed.Editor.select([(0, "TEXT,LWPOLYLINE,LINE")]) Quote
Danielm103 Posted 3 hours ago Author Posted 3 hours ago The SelectionSet class is an enumerable collection of ObjectIds, example #returns a PromptStatus and a SelectionSet class ps, ss = Ed.Editor.select() for id in ss: ent = Db.Entity(id) print(ent.isA().dxfName()) Quote
Danielm103 Posted 3 hours ago Author Posted 3 hours ago The real power is post filtering entity types, for example, we want the selection set to filter the visual selection set on screen, but then we want to separate out objects by type. SelectionSet.objectIds() method is overloaded to take an entity class description and returns the types that match. it does not open the object, so it’s extremely fast #returns a PromptStatus and a SelectionSet class ps, ss = Ed.Editor.select([(0, "TEXT,LWPOLYLINE,LINE")]) if ps != Ed.PromptStatus.eOk: raise RuntimeError("Selection Error! {}: ".format(ps)) # create a list of entites ant are opened for read texts = [Db.Text(id) for id in ss.objectIds(Db.Text.desc())] lines = [Db.Line(id) for id in ss.objectIds(Db.Line.desc())] plines = [Db.Polyline(id) for id in ss.objectIds(Db.Polyline.desc())] for text in texts: pass # do something for line in lines: pass # do something for pline in plines: pass # do something Quote
Danielm103 Posted 3 hours ago Author Posted 3 hours ago Support derived types, Lets say you want to get all the objects in the set that are derived from AcDbCurve, to do some sort of base class operation (AcDb2dPolyline, AcDb3dPolyline, AcDbArc, AcDbCircle, AcDbEllipse, AcDbLeader, AcDbLine, AcDbPolyline, AcDbRay, AcDbSpline, AcDbXline) # returns a PromptStatus and a SelectionSet class ps, ss = Ed.Editor.select([(8, "0")]) if ps != Ed.PromptStatus.eOk: raise RuntimeError("Selection Error! {}: ".format(ps)) curves = [Db.Curve(id) for id in ss.objectIds(Db.Curve.desc())] for curve in curves: print(curve.getDistAtParam(curve.getEndParam())) Quote
Danielm103 Posted 3 hours ago Author Posted 3 hours ago Lets say we want only lines and arcs, but still want to use AcDbCurve class, pass a list of descriptions # returns a PromptStatus and a SelectionSet class ps, ss = Ed.Editor.select([(8, "0")]) if ps != Ed.PromptStatus.eOk: raise RuntimeError("Selection Error! {}: ".format(ps)) curves = [Db.Curve(id) for id in ss.objectIds([Db.Line.desc(),Db.Arc.desc()])] for curve in curves: print(curve.getDistAtParam(curve.getEndParam())) Quote
Danielm103 Posted 2 hours ago Author Posted 2 hours ago (edited) SelectionSet class methods class SelectionSet: def add(self, id: Db.ObjectId, /) -> None: ... def adsname(self, /) -> Db.AdsName: ... def clear(self, /) -> None: ... def hasMember(self, id: Db.ObjectId, /) -> bool: ... def objectIdArray(self, desc: Rx.RxClass = Db.Entity, /) -> Db.ObjectIdArray: ... def objectIds(self, desc: Rx.RxClass = Db.Entity, /) -> list[Db.ObjectId]: ... def remove(self, id: Db.ObjectId, /) -> None: ... def size(self, /) -> int: ... def ssNameX(self, val: int = 0, /) -> list: ... def ssSetFirst(self, /) -> bool: ... def ssXform(self, xform: Ge.Matrix3d, /) -> Ed.PromptStatus: ... def toList(self, /) -> list[Db.ObjectId]: ... Note, ObjectIdArray is basically the same as list[Db.ObjectId], but the memory is allocated in C++ instead of Python. There may be performance reasons to choose one of the the other, but for now, they can be used interchangeably Edited 2 hours ago by Danielm103 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.