-1

Erase line on a layer a layer in a cad, using python

Hi, I want to select objects on a specific layer in my autocad drawning. After, I want to delete them. I tried a couple thing (using python) with exdxf or pyautocad. Can someone send me line to select and delete an object in a cad? Sorry if my english is bad, it's not my first language but i'm trying my best! :) Thank you

1 Answers1

0

Select the object as you prefer (by name maybe?) and delete it with

from pyautocad import Autocad
acad = Autocad()
for entity in acad.ActiveDocument.ModelSpace:
    name = entity.EntityName
    if name == 'AcDbBlockReference':
        HasAttributes = entity.HasAttributes
        if HasAttributes:
            objectID = entity.ObjectID
            name = entity.Name
             if name == 'the object you are looking for'
              acad.doc.SendCommand('WRITECOMMANDHERE')

This could be useful: https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-6B6AC9D6-7F6B-4A2C-B772-04CD817F4D97

Bire
  • 3
  • 2
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 30 '23 at 18:13