SelectByPolygon Method (ActiveX) command in Python language

SelectByPolygon Method (ActiveX) command in Python language

luizchequini
Enthusiast Enthusiast
1,903 Views
3 Replies
Message 1 of 4

SelectByPolygon Method (ActiveX) command in Python language

luizchequini
Enthusiast
Enthusiast

I have a polyline that delimits an area, within this area I have several blocks, in the documentation I could not understand the procedure, below is my coding that is giving an exception.

Documentation: SelectByPolygon Method (ActiveX)
https://help.autodesk.com/view/ACD/2017/ESP/?guid=GUID-D8002585-5D08-45E2-AF6C-6E894FA3D463

 

import win32com.client as wc
import pythoncom as p
acad = wc.Dispatch("AutoCAD.Application")
acadDoc = acad.ActiveDocument
acadModel = acad.ActiveDocument.ModelSpace

def APoint(x, y, z = 0):
    return wc.VARIANT(p.VT_ARRAY | p.VT_R8, (x, y, z))

def ADouble(xyz):
    return wc.VARIANT(p.VT_ARRAY | p.VT_R8, xyz)

def ADispatch(vObject):
    return wc.VARIANT(p.VT_ARRAY | p.VT_R8, vObject)

ponto = []

for entity in acadModel:
     name = entity.EntityName
     if name == 'AcDbPolyline':
           ponto.append(entity.Coordinates)

#ERROR EXCEPTION
acadModel.SelectByPolygon(ponto[0])

 

0 Likes
Accepted solutions (1)
1,904 Views
3 Replies
Replies (3)
Message 2 of 4

daniel_cadext
Advisor
Advisor

according to the link, you're missing the mode argument

enum AcSelect
    {
        acSelectionSetWindow	= 0,
        acSelectionSetCrossing	= 1,
        acSelectionSetFence	= 2,
        acSelectionSetPrevious	= 3,
        acSelectionSetLast	= 4,
        acSelectionSetAll	= 5,
        acSelectionSetWindowPolygon	= 6,
        acSelectionSetCrossingPolygon	= 7
    } 	AcSelect;

 

so maybe acadModel.SelectByPolygon(6, ponto[0])?

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 4

luizchequini
Enthusiast
Enthusiast

in the documentation
object.SelectByPolygon

acadModel does not recognize the command, and is giving the following error.
AttributeError: <unknown>.SelectByPolygon

The variable I created has the following result that was taken from a polyline
0.0, 0.0, 0.0,
0.0, 1.0, 0.0,
1.0, 1.0, 0.0,
1.0, 0.0, 0.0,
0.0, 0.0, 0.0
dot.append(entity.Coordinates)

then the command
acadModel.SelectByPolygon(6, point[0])

Did not work.

0 Likes
Message 4 of 4

luizchequini
Enthusiast
Enthusiast
Accepted solution

I managed to do it here, I'm doing the final tests and creating the final logic of the application so that I can use it calmly 😉

 

The code below worked for me.

 

 

from pyautocad import Autocad, APoint, ACAD
import win32com.client
import pythoncom

acad = win32com.client.Dispatch("AutoCAD.Application")
acadDoc = acad.ActiveDocument
acadModel = acad.ActiveDocument.ModelSpace

def APoint(x, y, z=0):
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))

def aDouble(xyz):
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (xyz))

def aVariant(vObject):
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_DISPATCH, (vObject))

aaa = acadDoc.ActiveSelectionSet
aaa.SelectByPolygon(7, aDouble([0,0,0, 0,10,0, 10,10,0, 10,0,0, 0,0,0]))
print(aaa.Count)
aaa = aVariant(aaa)
acad.ZoomExtents()

 

 

0 Likes