Jump to content

Recommended Posts

Posted

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>"),
        ]

 

Posted

SelectionSet filters can also be inline

 

 Ed.Editor.select([(0, "TEXT,LWPOLYLINE,LINE")])

 

Posted

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())

 

Posted

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 

 

 

Posted

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()))

 

Posted

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()))

 

Posted (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 by Danielm103

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...