Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Get text content dynamo civil 3d

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 *

# Enable Python support and load DesignScript library
from System.Collections.Generic import Dictionary

def get_text_props():
	
	textProps = []
	obj=[]
	keys = ["Contents","Horizontal mode","Vertical mode","Height","Rotation","Width factor","Obliquing","Alignment point","Insertion point","Upside down","Backward"]
	errorReport = None
	
	handles = []
	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))
				for h in handles:
					oid=(db.GetObjectId(False,Handle(int(h,16)),0))
					obj.append(t.GetObject(oid, OpenMode.ForRead))					
				# Create list of properties for each DBtext
				for i in obj:
					val=[]
					try:
						
						val.append(i.TextString)
						
						#Remove "Text" from beginning of text alignment modes
						hMode=str(i.HorizontalMode)
						vMode=str(i.VerticalMode)
						hMode_trim=hMode.Replace("Text","")
						vMode_trim=vMode.Replace("Text","")
						val.append(hMode_trim)
						val.append(vMode_trim)
						
						val.append(i.Height)
						val.append(i.Rotation)
						val.append(i.WidthFactor)
						val.append(i.Oblique)
						
						# Create alignment point
						alignX=i.AlignmentPoint.X
						alignY=i.AlignmentPoint.Y
						alignZ=i.AlignmentPoint.Z
						alignPt=Point.ByCoordinates(alignX,alignY,alignZ)
						val.append(alignPt)
						
						#Create insertion point
						insX=i.Position.X
						insY=i.Position.Y
						insZ=i.Position.Z
						insPt=Point.ByCoordinates(insX,insY,insZ)
						val.append(insPt)
						
						val.append(i.IsMirroredInY)
						val.append(i.IsMirroredInX)				
					# Error handling
					except:
						import traceback
						errorReport = traceback.format_exc()	
					d = {k:v for k,v in zip(keys,val)}
					dict = Dictionary[str,object](d)
					textProps.append(dict)		
				
				t.Commit()			
	if errorReport == None:
		return textProps
	else:
		return errorReport
	
OUT = get_text_props()
Comment

PREVIOUS NEXT
Code Example
Python :: how to read xlsx file from one directory above python 
Python :: flask request file upload to dropbox 
Python :: operations in python 
Python :: filtrar en python/how to filter in python 
Python :: python date_end-date_Start in seconds 
Python :: test api register user 
Python :: hypercorn initiate 
Python :: python split files into even sets of folders 
Python :: get node name dynamo revit 
Python :: mechanize python #12 
Python :: pseudo-random input signal python 
Python :: get users except superuser django 
Python :: how to run function when file is modified python 
Python :: accumulate sum of elements in list 
Python :: pandas str contains only true 
Python :: filter all columns in pandas 
Python :: fill variable based on values of other variables python 
Python :: double except python 
Python :: splitting Feature and target using iloc 
Python :: pyttsx3 interrupting an utterance 
Python :: aws chalice 
Python :: tuple with mixed data types 
Python :: for i in range(6, 11): print(i, end="") 
Python :: codeforces 1133A in python 
Python :: which can be reversed , string or list? 
Python :: list update python 
Python :: Python NumPy transpose Function Example in one line of code 
Python :: python code to find duplicate row in sqlite database 
Python :: Python NumPy hstack Function Example with 2d array 
Python :: structure conditionnelle python 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =