HI ALL
HI @c.poupin
Please Help
How to choose TEXTS from Autocad drawing by System.Linq
selcet Object cad text by System.Linq does not work
import sys
import clr
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
# Add DesignScript references
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("System.Core")
import System
clr.ImportExtensions(System.Linq)
from System.Linq import Enumerable
# Enable Python support and load DesignScript library
from System.Collections.Generic import Dictionary
def get_text():
textProps = []
obj=[]
handles = []
errorReport = None
global adoc
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
btrlq = btr.Cast[ObjectId ]().ToArray()
btraa = btr.Cast[ObjectId ]().Select(id >= t.GetObject(id, OpenMode.ForWrite))
t.Commit()
if errorReport == None:
return btrlq
else:
return btrlq
OUT = get_text()
I can choose it with this code
import sys
import clr
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
# Add DesignScript references
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("System.Core")
import System
clr.ImportExtensions(System.Linq)
from System.Linq import Enumerable
# Enable Python support and load DesignScript library
from System.Collections.Generic import Dictionary
def get_text():
textProps = []
obj=[]
handles = []
errorReport = None
global adoc
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
for oid in btr:
bl = t.GetObject(oid, OpenMode.ForRead)
if isinstance(bl,DBText):
handles.append(str(bl.Handle))
t.Commit()
if errorReport == None:
return handles
else:
return handles
OUT = get_text()
There is an example with c#
var modelSpace = (BlockTableRecord)tr.GetObject(
SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
// get all curve entities in model space
var curveClass = RXObject.GetClass(typeof(DBText));
var curves = modelSpace
.Cast<ObjectId>()
.Where(id => id.ObjectClass.IsDerivedFrom(curveClass))
.Select(id => (Curve)tr.GetObject(id, OpenMode.ForRead))
.ToArray();
Thanks in advance for any help
Uploading: CCCC.dwg…
linq t.dyn (9.6 KB)