.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: Copy all objects to new drawing template
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: Copy all objects to new drawing template
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: Copy all objects to new drawing template
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
@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
Re: Copy all objects to new drawing template
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: Copy all objects to new drawing template
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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 ClassThis 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.



