Duplicate multileader style - correct approach?

Duplicate multileader style - correct approach?

Mike_68
Explorer Explorer
949 Views
2 Replies
Message 1 of 3

Duplicate multileader style - correct approach?

Mike_68
Explorer
Explorer
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}
0 Likes
950 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
I would look at your code if I didn't have to reformat it, and because I
don't use the web interface, it is complete reformatted into an unreadable
mess in my newsreader. In the web interface, formatted code is word-wrapped
to the point where it is unreadable as well.

My advice would be to also attach your code in a .txt file because Autodesk
just can't seem to get it right.



--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:[email protected]...
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)
_ 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}
0 Likes
Message 3 of 3

Mike_68
Explorer
Explorer
Thanks for the suggestion.

The code is in the attached text file.

Also, while reviewing my code, I realized that the majority of the code samples I've seen use the transaction's GetObject method while I've been using the ObjectID's GetObject method. Is using the transaction's GetObject method considered a better practice, personal preference, or something else?

Again, thanks for any feedback you can offer. Edited by: Mike_68 on Jan 28, 2009 8:19 AM
0 Likes