.NET

Reply
Active Member
AcadApe
Posts: 7
Registered: ‎03-11-2009
Message 1 of 3 (228 Views)
Accepted Solution

creating a text style

228 Views, 2 Replies
03-19-2013 06:10 AM

Hello Group, this is my attempt, taken from snippets given here, but i obviously havent got the whole picture:

 

PublicSharedSub CreateTextStyle(ByVal TextStyleName AsString, ByVal FontFileName AsString, ByVal OblAng AsDouble)

           

Dim DataB AsDatabase = Application.DocumentManager.MdiActiveDocument.Database

           

Dim MyTransaction AsTransaction = DataB.TransactionManager.StartTransaction()

           

Try

               

Dim MyBlockTable AsBlockTable = MyTransaction.GetObject(DataB.BlockTableId, OpenMode.ForRead)

               

Dim MyBlockTableRecord AsBlockTableRecord = MyTransaction.GetObject(MyBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

               

Dim MyTextStyleTable AsTextStyleTable = MyTransaction.GetObject(DataB.TextStyleTableId, OpenMode.ForRead)

               

'check to see if text style exists, and if not create text style

               

If MyTextStyleTable.Has(TextStyleName) = FalseThen

                    MyTextStyleTable.UpgradeOpen()

                   

Dim MyTextStyleTableRecord AsNewTextStyleTableRecord

                    MyTextStyleTableRecord.FileName = FontFileName

                    MyTextStyleTableRecord.Name = TextStyleName

                    MyTextStyleTableRecord.ObliquingAngle = OblAng

                    MyTextStyleTable.Add(MyTextStyleTableRecord)

                    MyTransaction.AddNewlyCreatedDBObject(MyTextStyleTableRecord,

True)

               

EndIf

           

Finally

                MyTransaction.Commit()

                MyTransaction.Dispose()

           

EndTry

       

EndSub

 

and i call it from sub:

 

Call CreateTextStyle("330", "romans.shx", DTR(330))

 

but error comes up

 

at Autodesk.AutoCAD.DatabaseServices.Transaction.GetObject(ObjectId id, OpenMode mode, Boolean openErased, Boolean forceOpenOnLockedLayer)

 

any help would be appreciated !
 

1. First of all let using Insert Code button:

01-03-2013 15-59-28.png

2. What kind of error happened (full description and error code)?  Maybe eLockViolation ?  If so you have to Lock/Unlock document.

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 2 of 3 (217 Views)

Re: creating a text style

03-19-2013 06:58 AM in reply to: AcadApe

1. First of all let using Insert Code button:

01-03-2013 15-59-28.png

2. What kind of error happened (full description and error code)?  Maybe eLockViolation ?  If so you have to Lock/Unlock document.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Member
AcadApe
Posts: 7
Registered: ‎03-11-2009
Message 3 of 3 (205 Views)

Re: creating a text style

03-19-2013 07:26 AM in reply to: AcadApe

Hi Alex,

 

nearly there then!

 

Dim

lock AsDocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument

 

etc....

 

lock.Dispose()

 

works fine, thank you for response

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!