I'll elaborate a little more on where I am with this issue.
I have x number of drawings open and I Arrange them. And on each drawing, I run the rule, minimize the resulted drawing from the rule, close the original and move to the next. Until I'm left with only the resulting drawings at which point I save and overwrite the original.
Part of my issue before even considering code that would go through all the open drawings is I can only do it based on a "view 1" so its use as only been for flat pattern drawings with a single view. I'm not sure how I need to modify the code to take all views/elements and not a specific view.
Essentially I want to copy all created element on my sheet to my new drawing.
The idea of saving over the original file was so its history was kept in the vault.
Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Temp\DWG. Template.dwg", True)
Dim oView As DrawingView
If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
MsgBox ("No views found in the source drawing !")
Return
End If
oView = oSrcDwg.ActiveSheet.DrawingViews(1)
Dim oSheet As Sheet
For Each oSheet In oDrawingDoc.Sheets
oSheet.Activate
Call oView.CopyTo(oSheet)
Exit For
Next
Call oSrcDwg.Save
'Call oSrcDwg.Close(True)The commented out part at the end to close the original file caused "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
However, it does close and allow me to move on but I don't really want to be risking crashing out or corrupting the file.
So moving on from the above the next step id be looking at would be how I could have this rule run through my open dwg's. I use the below code as part of a batch export which exports x number of open files all in a single press. I assume its something totally different but in theory, it's working without moving to the next drawing. Obviously, what am now trying to achieve you would assume id need to move to the next drawing before the rule ran again. I'm thinking an addin maybe that recognised the number of open document and somehow linked to my rule whereby it ran the rule and then the keyboard command "ctrl+tab" moved to the next, running the rule again until it's gone over the originally opened drawing. The first thing that comes to mind is how does it stop as the original amount of drawings will still be present only having been replaced with the new templates.
'Go through each view and save if it's a drawing document
For Each view As View In ThisApplication.Views