Hi … I am trying to add my own python script node to create MText objects in Model Space.
The input is a list of Points (output of Points.ByCoordinates Node).
Result: Civil 3D Fatal Error. Operation is not valid due to the state of the object.
Python error warning: No method matches given arguments for OnExit
# Load the Python Standard and DesignScript Libraries
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
def create_mtext(pnts):
ipnts = pnts
global adoc
result = False
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
# Place your code below
#
#
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
ms = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
for i in ipnts:
with MText() as mt:
mt.Location = i
mt.Height = 2.5
mt.Contents = 'HELLO!'
ms.UpgradeOpen()
ms.Add(mt)
ms.DowngradeOpen()
t.AddNewlyCreatedDBObject(mt,True)
result = True
# Commit before end transaction
t.Commit()
return result
if IN[0] == None:
OUT = False
else:
OUT = create_mtext(IN[0])
# Load the Python Standard and DesignScript Libraries
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
def create_mtext(pnts):
ipnts = pnts
global adoc
result = False
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
# Place your code below
#
#
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
ms = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
for i in ipnts:
with MText() as mt:
mt.Location = Point3d(i.X ,i.Y , i.Z )
mt.Height = 2.5
mt.Contents = 'HELLO!'
#ms.UpgradeOpen()
#ms.Add(mt)
#ms.DowngradeOpen()
ms.AppendEntity(mt)
t.AddNewlyCreatedDBObject(mt,True)
result = True
# Commit before end transaction
t.Commit()
return result
if IN[0] == None:
OUT = False
else:
OUT = create_mtext(IN[0])
Here is my very bad DYN - including the updated script you provided …
I was planning to script the MTEXT as I needed more MTEXT creation options
Since then … I have opted to use Text instead of MTEXT and all is working correctly.
Would be interesting to figure out what the problem is …
Thanks for your patience.