.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating a user defined style and attaching it to the dbEntity

2 REPLIES 2
Reply
Message 1 of 3
NikWach
263 Views, 2 Replies

Creating a user defined style and attaching it to the dbEntity

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, _
OpenMode.ForRead)


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

'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), _
OpenMode.ForWrite)
'' 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
acBlkTblRec.AppendEntity(acText)
acTrans.AddNewlyCreatedDBObject(acText, True)
Next

 

 

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.

2 REPLIES 2
Message 2 of 3
Matti72
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.

Message 3 of 3
NikWach
in reply to: Matti72

Thanks a lot! It does workSmiley Wink

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost