.NET

Reply
Mentor
MarkPendergraft
Posts: 375
Registered: ‎06-27-2005
Message 11 of 15 (179 Views)

Re: Copy all objects to new drawing template

03-04-2013 07:29 AM in reply to: RPeter

It seems to me that your issue is centered around the ed.GetSelection() method.

 

If you want the program to handle the selection, then you need to create an array of TypedValue containing your selection criteria, then create a SelectionFilter and pass the array to it.  Then call ed.GetSelection() and pass your newly created SelectionFilter to it.

 

If you want the user to handle the selection, then you need to create PromptSelectionOptions and set the necessary parameters in order for the ed.GetSelection() method to know what to tell the user to select.

 

-Mark P.

Contributor
jamkhp
Posts: 24
Registered: ‎05-19-2011
Message 12 of 15 (177 Views)

Re: Copy all objects to new drawing template

03-04-2013 07:34 AM in reply to: MarkPendergraft

I do agree with you, what is happening is, when I am selecting through the program, on the screen, after the selection, I dont see the exit of the select, it will be still active and the other document even it is opened, it never get focussed.

 

Valued Contributor
RPeter
Posts: 82
Registered: ‎01-09-2009
Message 13 of 15 (168 Views)

Re: Copy all objects to new drawing template

03-04-2013 12:56 PM in reply to: jamkhp

@jamkhp,

 

Dim ndoc As Document = DocumentCollectionExtension.Add(dm, MyTemplate)

 

Is indeed added in the 2013 version.

 

This line only says that there is a new document created within the documentmanager based on a template.

You can view the code to create a new document with a template in my previous post over here.

 

regards

 

Peter

Contributor
jamkhp
Posts: 24
Registered: ‎05-19-2011
Message 14 of 15 (133 Views)

Re: Copy all objects to new drawing template

03-10-2013 03:57 AM in reply to: RPeter

Peter,

It is some how not working for me.

could you please help.

It is for sure getting stuck when sue editor and change the document, it is not taking my new document as current and clonning, it is still woking on the old document.

 

Valued Contributor
RPeter
Posts: 82
Registered: ‎01-09-2009
Message 15 of 15 (121 Views)

Re: Copy all objects to new drawing template

03-10-2013 11:26 PM in reply to: jamkhp

jamkhp,

 

I've tested the folowing code on the acad 2012 version. I think you've forgot the CommandFlags.Session

Public Class cls_CopySelectedObjects
    <CommandMethod("MyCopyObjects", CommandFlags.Session)> Public Sub Copy2Template()
        Dim MyTemplate As String = "E:\Autocad.dwt"

        Dim oic As ObjectIdCollection = New ObjectIdCollection()

        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Dim dm As DocumentCollection = Application.DocumentManager

        Dim MySelection As PromptSelectionResult = ed.GetSelection()

        If MySelection.Status = PromptStatus.OK Then
            If MySelection.Value.Count > 0 Then
                Dim ndoc As Document = dm.Add(MyTemplate)
                'Dim ndoc As Document = DocumentCollectionExtension.Add(dm, MyTemplate)
                Dim ndb As Database = ndoc.Database

                dm.MdiActiveDocument = ndoc

                Using dl As DocumentLock = doc.LockDocument()
                    Using tr As Transaction = db.TransactionManager.StartTransaction()
                        For Each so As SelectedObject In MySelection.Value
                            oic.Add(so.ObjectId)
                        Next
                        tr.Commit()
                    End Using
                End Using

                Using ndl As DocumentLock = ndoc.LockDocument()
                    Using ntr = ndb.TransactionManager.StartTransaction()
                        Dim nbt As BlockTable = ntr.GetObject(ndb.BlockTableId, OpenMode.ForRead)
                        Dim nbtr As BlockTableRecord = ntr.GetObject(nbt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
                        Try
                            db.WblockCloneObjects(oic, nbtr.ObjectId, New IdMapping(), DuplicateRecordCloning.Ignore, False)
                        Catch ex As Exception
                        End Try
                        ntr.Commit()
                    End Using
                End Using

                dm.MdiActiveDocument = doc
            End If
        End If
    End Sub
End Class

 This code will set the selected objects in an objectcollection, opens a new drawing based on the specified template and activates this document. Then it will copy the objects into the new drawings database and then switches back to the original document, this is needed to close down the active command on the document. Now you can close the file or whatever you want.

 

I found a bug in the wblockcloneobjects (still there in 2013):

When the Layermanager is open in the toolpalletemode when Autocad has started you will get a fatal error, when u use the Classiclayer manager as default you won't have anny errors.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.