I was trying this using an iLogic rule, simply because it's quicker & easier for me to test stuff there. So far though, it's just another case of 'almost there'. I can copy the set of related views just fine, all day long, but it's the pasting on the other document's sheet part that's been evading me. I keep pasting a new sheet to the other drawing, instead of pasting the views, for some reason. I definitely confirm that I have copied the views and not the sheet, but it's just mussing a step on the side of the other document. When done manually, I pretty much have to click somewhere on the sheet area before it will let me paste those views. Before that click, it won't let me paste them correctly. That's the missing link in this process.
Here is the iLogic code I started, but the last part of the Sub Main area is where that missing step needs to be added in there, and maybe something else altered. The custom Function is working just fine. The top portion of the Sub Main code is just fine...just puts the parent view and its child views into an ObjectCollection, then puts that ObjectCollection into the SelectSet, so that it is 'selected'. Then copies them to Inventor's session memory (or Clipboard or something). Then the last part of the Sub Main code creates the other/new drawing document that we want to copy those views into. That part is just fine too, because I can do that part manually too between pasting views, and it also works just fine. It's what to do next that is stumping me right now. It seems like I may need to somehow simulate a mouse click somewhere on that new document's sheet area, before using the paste command, otherwise the paste part will not work. The same is true when doing it manually.
Sub Main
'get the 'local' drawing (or one that was active when rule started)
oDDoc = ThisDrawing.Document
oSourceSheet = oDDoc.ActiveSheet
oViews = oSourceSheet.DrawingViews
oDDoc.SelectSet.Clear
'get first view with no parent view, but has child views
For Each oView As DrawingView In oViews
If IsNothing(oView.ParentView) Then
oChildViews = GetChildViewsOnSameSheet(oView)
If oChildViews.Count = 0 Then Continue For
'MsgBox("oChildViews.Count = " & oChildViews.Count,,"")
'found that view, now process it and its child views
'add that parent view to the ObjectCollection
oChildViews.Add(oView)
'add that ObjectCollection to the SelectSet
oDDoc.SelectSet.SelectMultiple(oChildViews)
'now execute a command to copy them (to the Clipboard)
ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd").Execute2(False)
Exit For 'don't process more views
End If
Next
'create a new drawing document
Dim oTempDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , True)
oTempDDoc.SelectSet.Clear
'oNode = oTempDDoc.BrowserPanes.Item("Model").GetBrowserNodeFromObject(oTempDDoc.ActiveSheet)
oTempDDoc.SelectSet.Select(oTempDDoc.ActiveSheet)
oTempDDoc.SelectSet.Clear
'then activate the oTempSheet
'oTempSheet.Activate
'then execute a command to paste those views to it
ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd").Execute '.Execute2(False)
End Sub
Function GetChildViewsOnSameSheet(oDView As DrawingView) As ObjectCollection
oCViews = ThisApplication.TransientObjects.CreateObjectCollection
oSheet = oDView.Parent
For Each oView As DrawingView In oSheet.DrawingViews
If oView Is oDView Then Continue For
If IsNothing(oView.ParentView) Then Continue For
If oView.ParentView Is oDView Then
oCViews.Add(oView)
End If
Next
Return oCViews
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)