Yes I think it can be done. But one may need to write a few more helper classes in C#.
One issue I found is you can’t open objects for write with ironpython (I don’t know why).
But it would be easy enough for one to write helper functions for adding objects to records or the database
Another issue I found is that there is no casting in Python, so if one were to use a method like
tr.GetObject(id , AcDb.OpenMode.ForRead ,False)
what type of object does python see? How would one cast from a DbObject to a BlockTableRecord?
Again one could write helper functions to get objects ie GetBlockTableRecord(…);
So in the end, it certainly is possible
maybe someone could look at my attemp and point out my errors
#thanks to kwb for the C# code to translate
import System
import Autodesk.AutoCAD.DatabaseServices as AcDb
import Autodesk.AutoCAD.Geometry as AcGe
import Autodesk.AutoCAD.ApplicationServices as AcAp
try:
ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage("\n Hello")
db = AcDb.HostApplicationServices.WorkingDatabase
tm = db.TransactionManager
tr = tm.StartTransaction()
line = AcDb.Line(AcGe.Point3d(0,0,0),AcGe.Point3d(100,100,0))
id = AcDb.SymbolUtilityServices.GetBlockModelSpaceId(db)
# fails to open
# can I cast this way???
btrArray = System.Array[AcDb.BlockTableRecord]([tr.GetObject(id , AcDb.OpenMode.ForWrite ,False)])
# btrArray = System.Array[AcDb.BlockTableRecord]([tr.GetObject(id , AcDb.OpenMode.ForRead ,False)])
# btrArray = System.Array.CreateInstance(AcDb.BlockTableRecord, 1)
# btrArray[0] = tr.GetObject(id , AcDb.OpenMode.ForRead ,False)
btrArray[0].AppendEntity(line)
tr.AddNewlyCreatedDBObject(line, true)
tr.Commit()
tr.Dispose()
except:
tr.Dispose()
line.Dispose()