TheSwamp

Code Red => .NET => Topic started by: mgreven on August 22, 2012, 04:02:24 PM

Title: Probem with WblockCloning PropertySets
Post by: mgreven on August 22, 2012, 04:02:24 PM
Hello,

I have made a routine to WblockClone PropertySets between drawings...

When i use the routine i am getting a "Exception: eInvalidInput" on the commandline and the PropertySet is Not Cloned to the drawing.

What is wrong here?

        Sub WblockPropsets(ByVal SourceDrawing As String, ByVal PropsetName As String)
            ' Connect to Current Drawing
            Dim MyDWG As Autodesk.AutoCAD.ApplicationServices.Document = _ Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim MyDB As Autodesk.AutoCAD.DatabaseServices.Database = MyDWG.Database
            Dim MyTransMan As Autodesk.AutoCAD.DatabaseServices.TransactionManager = MyDWG.TransactionManager
            ' Connect to Source Drawing
            Using SrcDB As Autodesk.AutoCAD.DatabaseServices.Database = New Autodesk.AutoCAD.DatabaseServices.Database(False, True)
                ' Read Source Drawing
                SrcDB.ReadDwgFile(SourceDrawing, IO.FileShare.ReadWrite, True, "")
                ' Start Transactions
                Dim SrcTransMan As Autodesk.AutoCAD.DatabaseServices.TransactionManager = SrcDB.TransactionManager
                Using SrcTrans As Autodesk.AutoCAD.DatabaseServices.Transaction = SrcTransMan.StartTransaction,
                        MyTrans As Autodesk.AutoCAD.DatabaseServices.Transaction = MyTransMan.StartTransaction

                    ' Open de source PropSet Dictionary...
                    Dim SrcPropsetDict As New DictionaryPropertySetDefinitions(SrcDB)

                    ' Open de destination PropSet Dictionary and get de Dictionary ID...
                    Dim DestPropsetDict As New DictionaryPropertySetDefinitions(MyDB)
                    Dim DestPropsetDictID = DestPropsetDict.DictionaryId

                    Dim MyPropSetColl As New Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection ' Colection that Stores the Entities ID

                    ' Get the collection of MvBlocks...
                    ' Loop entities in Source Dictionary
                    For Each ObjID In SrcPropsetDict.Records
                        Dim PropSet As PropertySetDefinition = SrcTrans.GetObject(ObjID, OpenMode.ForRead)
                        If PropSet.Name = PropsetName Then
                            MyPropSetColl.Add(ObjID)
                        End If

                    Next

                    ' WblockClone the Source Entitys
                    Dim myMap As New Autodesk.AutoCAD.DatabaseServices.IdMapping
                    MyDB.WblockCloneObjects(MyPropSetColl, DestPropsetDictID, myMap, Autodesk.AutoCAD.DatabaseServices.DuplicateRecordCloning.Replace, False)

                    ' Commit, Close and Dispose Transactions
                    MyTrans.Commit()
                    SrcTrans.Commit()
                End Using
            End Using
        End Sub

Title: Re: Probem with WblockCloning PropertySets
Post by: kaefer on August 23, 2012, 12:47:18 AM
What is wrong here?

You could try Autodesk.Aec.ApplicationServices.Utility.CloningHelper() instead. This was described recently on Autodesk's AEC DevBlog (http://adndevblog.typepad.com/aec/2012/08/importexport-styles-fromto-another-drawing-in-net-.html).
Title: Re: Probem with WblockCloning PropertySets
Post by: mgreven on August 24, 2012, 06:20:16 PM
Thanks for your help... It does the trick.

Regards,

Marco