Ad

Friday, August 06, 2010

Modifying Text Labels

Ever have lots of General Notes styles you have modified that need remodification or need a bunch of general notes changed by say an incremental number.In the Civil 3D 2011 .NET API one can override text components. Here’s a sample showing how to change the first text component in a label.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.Civil.DatabaseServices

<Assembly: CommandClass(GetType(LabelNote))>

Public Class LabelNote

<CommandMethod("C3DRChangeNoteLabel")> _
Public Sub ChangeNoteLabel()
Try
' Have the user select a general note label.
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim entopts As New PromptEntityOptions("Select a general note label: ")
entopts.SetRejectMessage(
"You did not select a valid entity")

Dim entRes As PromptEntityResult = ed.GetEntity(entopts)

If entRes.Status = PromptStatus.OK Then
Dim entid As ObjectId = entRes.ObjectId
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
Using myT As Transaction = tm.StartTransaction()
Dim oNoteLabel As Label = DirectCast(tm.GetObject(entid, OpenMode.ForWrite, True), Label)
oNoteLabel.SetTextComponentOverride(oNoteLabel.GetTextComponentIds(
0), _
"Override", Autodesk.Civil.TextJustificationType.Center)

myT.Commit()
End Using
End If
Catch
Dim oC3DR As New C3DRemindersPack.Utilities
oC3DR.MessageWriter(
"Error changing note label")
End Try
End Sub

End Class

No comments:

LinkWithin

Blog Widget by LinkWithin

Ad