iLogic - Delete inactive sheets

iLogic - Delete inactive sheets

GKPByDesign
Advocate Advocate
342 Views
1 Reply
Message 1 of 2

iLogic - Delete inactive sheets

GKPByDesign
Advocate
Advocate

Is there a basic code then will run on all open drawings to delete all sheets that does not have the same sheet name as file name. 

 

Perhaps a code for one file is a good start, but if I can get it to run on more. I want to retain the sheet with the same name, making sure to consider sheet 1:1, sheet 1:2, sheet 1:3 .... and containing these to the same file.

0 Likes
343 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @GKPByDesign.  I do not quite fully understand the details of what you are trying to do.  Can you please explain it a bit differently, or with more details?  What do you mean by 'inactive sheets'?  It sounds like each of your open drawing files will have one sheet named exactly the same as the file name, then the rest of the sheets will have generic names like "sheet 1:1" or "sheet 1:2" and so on, is that correct?  And you only want to retain that one sheet that is named exactly the same as the owning drawing file's name, while deleting all the others within that file, right?  What do you mean by "containing these to the same file"?  Do you want to copy/move the one retained sheet from each file all into one drawing file?  It would be simple to process all open drawings in one go, but I just need to fully understand all the details involved?  Maybe telling us why you are wanting to do this may help us understand also.

Below is a starter iLogic rule code you can play around with.

Dim oOpenDocs As Documents = ThisApplication.Documents
For Each oDoc As Document In oOpenDocs
	If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Continue For
	Dim oDDoc As DrawingDocument = oDoc
	Dim sFileName As String = System.IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
	Dim oSheets As Sheets = oDDoc.Sheets
	For Each oSheet As Sheet In oSheets
'		If oSheet.Name.Contains(":") Then
'			Dim sFirstPart As String = oSheet.Name.Split(":").First
'			If sFirstPart <> sFileName Then oSheet.Delete
'		End If
		If oSheet.Name <> sFileName Then oSheet.Delete
	Next
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes