Posts: 17
Registered: ‎09-19-2013
Message 1 of 3 (116 Views)

Creating a user defined style and attaching it to the dbEntity

116 Views, 2 Replies
09-19-2013 04:19 AM

Hello everyone!


I have got a following problem. Ich wrote a program to analize a text source, where you can find all draw entities. In this source file you have got all properties of those entities. Ich try to create a custom style and attach it to the ex. text entity. How can I do it? 


Below you find the code, where I create the style and attach it to the entity.


'' Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database

'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _

Dim ed As Editor = acDoc.Editor
Dim st As TextStyleTable = CType(acTrans.GetObject( _
acCurDb.TextStyleTableId, _
OpenMode.ForWrite, False), _
Dim TextStyle As TextStyleTableRecord = _
New TextStyleTableRecord()
TextStyle.Name = "MyStyle"

'default text style properties
'str.FileName = "txt.shx"
'str.PriorSize = 0.2
'str.ObliquingAngle = 0.0
'str.XScale = 1.0
'str.TextSize = 0.0
'str.IsVertical = False
'str.IsShapeFile = False

'using the font descriptor to set the new font style
'Imports Autodesk.AutoCAD.GraphicsInterface
TextStyle.Font = New FontDescriptor("RomanC", True, True, Nothing, Nothing)
acTrans.AddNewlyCreatedDBObject(TextStyle, True)

'' Open the Block table record Model space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
'' Create Text Entities
For CollectionCount = 0 To Text_Collection.Count - 1
'' Create a single-line text object
Dim acText As DBText = New DBText()

acText.Position = New Point3d(Text_Collection(CollectionCount).PKT_X(0), Text_Collection(CollectionCount).PKT_Y(0), 0)
acText.Height = Text_Collection(CollectionCount).HOHE
acText.WidthFactor = Text_Collection(CollectionCount).X_SKAL
acText.Rotation = Text_Collection(CollectionCount).DREHUNG
acText.TextString = Text_Collection(CollectionCount).TEXT
acTrans.AddNewlyCreatedDBObject(acText, True)



I need to attach the "MyStyle" to the acText Entity... It have to work the following way - 


There is a collection of text entities. Each entity has it own text-color, font or what ever. I want while creating acText to use the each entity property for its own acText. I attach my VBProject and the source file with the properties.

Posts: 25
Registered: ‎09-28-2004
Message 2 of 3 (104 Views)

Re: Creating a user defined style and attaching it to the dbEntity

09-19-2013 05:29 AM in reply to: NikWach

Maybe I'm blind, but I can't find the place, where you attach the style to the text.


I miss a line like


acText.TextStyleId = TextStyle.ObjectId


this should normally do the trick.

Posts: 17
Registered: ‎09-19-2013
Message 3 of 3 (100 Views)

Re: Creating a user defined style and attaching it to the dbEntity

09-19-2013 05:41 AM in reply to: Matti72

Thanks a lot! It does work:smileywink:

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.