- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a "template" file that has all the layouts I need. I'm making a function to copy ones that I need from the "template" to the current drawing. The viewports in the template layouts have some layers turned off. The "current" file and the "template" both have the same layers over all.
The copy from the "template" to the "current" successfully occurs, but all the layers are visible through the viewport of the copied layouts.
Any help would be greatly appreciated.
/*
* Opens the "template" database in ReadWrite mode and then passes it into
* the lambda which is after the =>
*/
ResourceFolder.ReadWriteTemplate((database =>
{
ObjectIdCollection layoutsToCopy = new ObjectIdCollection();
/*
* Opens the layout dictionary for the database and passes the dictionary
* and the transaction to the lambda
*/
database.LayoutDictionaryId.TryGetRead<DBDictionary>((templateLayouts, tr) =>
{
foreach (DBDictionaryEntry entry in templateLayouts)
{
string[] entrySplit = entry.Key.Split(' ');
if(entrySplit.Length < 1) continue;
string entryMain = entrySplit[0];
/*
* If the _viewmodel (which for the sake of this is a list of strings)
* contains a string that matches the first part of the layout name
* it should be copied over
*
* for example: Main Layout will split to Main and will be searched in the _viewmodel
*/
if (_viewModel.Contains(entryMain))
{
layoutsToCopy.Add(entry.Value);//add to list to copy
/*
* My attempt to get the viewports from the layout to be copied.
* This opens the viewport using the transaction that is passed as the first parameter
* then adds each of its viewports from the Acad GetViewport() function
*/
entry.Value.TryGetRead<Layout>(tr, layout =>
{
var vpIds = layout.GetViewports();
foreach (ObjectId id in vpIds)
{
layoutsToCopy.Add(id);
}
});
}
}
/*
* Uses WblockCloneObjects to copy the selected entities to the Active Database
* which is the "current" database of the open drawing, not the "template" which is the
* source of the entities.
*/
var mappings = new IdMapping();
database.WblockCloneObjects(layoutsToCopy, Active.Database.LayoutDictionaryId, mappings, DuplicateRecordCloning.Ignore, false);
});
}));
Solved! Go to Solution.
Link copied