Message 1 of 3
Duplicate multileader style - correct approach?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In AutoCAD 2008, I'd like to duplicate an existing multileader style (and then modify a couple of properties of the new style). I've been reading posts on dictionary access with VB.Net, and I pulled together the code below.
For testing purposes, there's no error-handling or user input. It only clones the "Standard" multileader style to "NewStyle" (I'll deal with changing properties next). It appears to work, but it seems too "simple" compared to some of the examples I've seen.
I was wondering if anyone would be willing to take a look at the code and point out any "beginner's mistakes" that I'm not seeing.
Thank you for your time and advice.
{code}
' CloneMLStyle assumes a "Standard" multileader style exists in the drawing
' (and "NewStyle" does not exist in the drawing)
<CommandMethod("CloneMLStyle")> _
Public Sub CloneMLStyle()
Dim myDoc As Document
Dim myDB As Database
Dim myTransMan As DatabaseServices.TransactionManager
' get active drawing
myDoc = Application.DocumentManager.MdiActiveDocument
' get active drawing's database
myDB = myDoc.Database
' get transaction manager
myTransMan = myDoc.TransactionManager
' lock document
Using myDocLock As DocumentLock = myDoc.LockDocument
' start transaction
Using myTrans As Transaction = myTransMan.StartTransaction
Dim myMLStyleDict As DBDictionary
Dim myMLStyleObjectID As ObjectId
Dim mySourceMLStyle As MLeaderStyle
Dim myNewMLStyle As MLeaderStyle
' get multileader style dictionary
myMLStyleDict = myDB.MLeaderStyleDictionaryId.GetObject(OpenMode.ForRead)
' get "Standard" multileader style object ID
myMLStyleObjectID = myMLStyleDict.GetAt("Standard")
mySourceMLStyle = myMLStyleObjectID.GetObject(OpenMode.ForRead)
' clone "Standard" multileader style to new multileader style
myNewMLStyle = mySourceMLStyle.Clone
' upgrade dictionary to write
myMLStyleDict.UpgradeOpen()
' save new style to dictionary
myMLStyleDict.SetAt("NewStyle", myNewMLStyle)
' notify transaction
myTrans.AddNewlyCreatedDBObject(myNewMLStyle, True)
' commit changes to transaction
myTrans.Commit()
End Using
End Using
' dispose of transaction manager
myTransMan.Dispose()
End Sub
{code}
For testing purposes, there's no error-handling or user input. It only clones the "Standard" multileader style to "NewStyle" (I'll deal with changing properties next). It appears to work, but it seems too "simple" compared to some of the examples I've seen.
I was wondering if anyone would be willing to take a look at the code and point out any "beginner's mistakes" that I'm not seeing.
Thank you for your time and advice.
{code}
' CloneMLStyle assumes a "Standard" multileader style exists in the drawing
' (and "NewStyle" does not exist in the drawing)
<CommandMethod("CloneMLStyle")> _
Public Sub CloneMLStyle()
Dim myDoc As Document
Dim myDB As Database
Dim myTransMan As DatabaseServices.TransactionManager
' get active drawing
myDoc = Application.DocumentManager.MdiActiveDocument
' get active drawing's database
myDB = myDoc.Database
' get transaction manager
myTransMan = myDoc.TransactionManager
' lock document
Using myDocLock As DocumentLock = myDoc.LockDocument
' start transaction
Using myTrans As Transaction = myTransMan.StartTransaction
Dim myMLStyleDict As DBDictionary
Dim myMLStyleObjectID As ObjectId
Dim mySourceMLStyle As MLeaderStyle
Dim myNewMLStyle As MLeaderStyle
' get multileader style dictionary
myMLStyleDict = myDB.MLeaderStyleDictionaryId.GetObject(OpenMode.ForRead)
' get "Standard" multileader style object ID
myMLStyleObjectID = myMLStyleDict.GetAt("Standard")
mySourceMLStyle = myMLStyleObjectID.GetObject(OpenMode.ForRead)
' clone "Standard" multileader style to new multileader style
myNewMLStyle = mySourceMLStyle.Clone
' upgrade dictionary to write
myMLStyleDict.UpgradeOpen()
' save new style to dictionary
myMLStyleDict.SetAt("NewStyle", myNewMLStyle)
' notify transaction
myTrans.AddNewlyCreatedDBObject(myNewMLStyle, True)
' commit changes to transaction
myTrans.Commit()
End Using
End Using
' dispose of transaction manager
myTransMan.Dispose()
End Sub
{code}