Hi
I m trying to clone all the layouts in a drawing. I'm using wblock clone with the ids of the layouts and the layoutdictionaryId of the new drawing. It works as far as copying everything that is in the layouts. But it doesn't get the xdata with frozen layers from the viewports. Is there a way to clone this as well?
Thanks
Dim IMAP2 As New IdMapping Try acCurDb.WblockCloneObjects(LayoutObjIdColl, acCurDb2.LayoutDictionaryId, IMAP2, DuplicateRecordCloning.Ignore, False) Catch ex As Exception MsgBox(ex.Message) End Try
Solved! Go to Solution.
Solved by GeeHaa. Go to Solution.
Hi,
I tried the program but it still does not copy the xdata with the viewport layer info so I modified it to try to attach it manually. The drawing I am trying has three viewports. The program transfers one set of xdata ok but on the viewport I need(with the layer info) it crashes with einvalidinput on this line
vport.xdata = vp.xdata can anyone tell me what I am doing wrong.
Thanks in advance
Sub copyLayoutToNewDwg(ByVal db As Database, ByVal newdb As Database, ByVal NewLayoutName As String) Dim layout As New Layout Dim layoutNameInCurDwg As String = NewLayoutName Dim lytMgr As LayoutManager Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor() Dim layoutId As ObjectId Using tr As Transaction = newDb.TransactionManager.StartTransaction() 'Make the working database the new database HostApplicationServices.WorkingDatabase = newDb ' Create a new Layout Dim newLytMgr As LayoutManager = LayoutManager.Current() Dim newLayoutId As ObjectId = newLytMgr.CreateLayout(NewLayoutName) Dim newLayout As Layout = tr.GetObject(newLayoutId, OpenMode.ForWrite) 'Make the original database the working database HostApplicationServices.WorkingDatabase = db Using tr2 As Transaction = db.TransactionManager.StartTransaction() ' Get the dictionary of the original database Dim lytDict As DBDictionary = tr2.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) 'Make sure the layout existes in the original database If Not lytDict.Contains(layoutNameInCurDwg) Then ed.WriteMessage("Layout named ""Layout1"" does not exist in current dwg") Return End If 'Get the layout in the original database lytMgr = LayoutManager.Current() layoutId = lytMgr.GetLayoutId(layoutNameInCurDwg) layout = tr2.GetObject(layoutId, OpenMode.ForRead) newLayout.CopyFrom(layout) 'Get the block table record of the existing layout Dim blkTableRec As BlockTableRecord blkTableRec = tr2.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) 'Get the object ids of the objects in the existing block table record Dim objIdCol As New ObjectIdCollection() Dim vportlist As List(Of vportClass) = New List(Of vportClass) For Each objId As ObjectId In blkTableRec objIdCol.Add(objId) Dim ent As Entity = tr2.GetObject(objId, OpenMode.ForRead) Dim vpcItem As vportClass = New vportClass If TypeOf (ent) Is Viewport Then Dim vport As Viewport = ent vpcItem.LayoutName = NewLayoutName vpcItem.oldId = vport.ObjectId vpcItem.xdata = vport.XData vportlist.Add(vpcItem) End If Next ' Clone the objects to the new layout Dim idMap As IdMapping = New IdMapping() newdb.WblockCloneObjects(objIdCol, newLayout.BlockTableRecordId, idMap, DuplicateRecordCloning.Ignore, False) 'was manglename instead of ignore HostApplicationServices.WorkingDatabase = newdb For Each idp As IdPair In idMap For Each vp As vportClass In vportlist If idp.Key = vp.oldId Then Dim vport As Viewport = tr.GetObject(idp.Value, OpenMode.ForWrite) MsgBox("old Viewport=" + vp.xdata.ToString) MsgBox("New Viewport=" + vport.XData.ToString) vport.XData = vp.xdata End If Next Next tr2.Commit() End Using tr.Commit() End Using End Sub
Maybe RegApp using in Xdata is not registered in current Database?
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Hi Alexander,
Thanks for the response I think that the application is already registered as ACAD.
I think you have to:
1. Clear all xdata of new Viewport
2. Create all layers from xdata in old Viewport (see group 1003 for layers names) in current Database
3. Set xdata from old Viewport to new Viewport
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
I figured it out. You have to set the viewport active, add the xdata then set the viewport active again then commit the transaction. BTW the code for setting a viewport active is below.
'This goes before Commandmethod <DllImport("ACCORE.DLL", CallingConvention:=CallingConvention.Cdecl, _
EntryPoint:="?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PEBVAcDbViewport@@@Z")> _ Public Shared Function acedSetCurrentVPort(ByVal AcDbVport As IntPtr) As IntPtr End Function 'This is the calling Statement acedSetCurrentVPort(vport.UnmanagedObject)
Thanks again for all your help Alexander.
Can't find what you're looking for? Ask the community or share your knowledge.