Split Multisheet Inventor DWG drawing into Separate files

Split Multisheet Inventor DWG drawing into Separate files

GKPByDesign
Advocate Advocate
1,654 Views
22 Replies
Message 1 of 23

Split Multisheet Inventor DWG drawing into Separate files

GKPByDesign
Advocate
Advocate

I need help with code someone else I written about this issue. I have a mutlisheet dwg drawing created in inventor, but I need to split it into separate files. ie each page is a separate file. I have each sheet saved as the file name of the part saved, so I need a code that's saves the file by sheet name. Someone made this code attached which requires someone to run two codes, and it works fine, but now I am finding it is working very slow. Bear in mind the file is also loading items from vault etc. 

 

First Code: 

 

'RUN RULE will save-copy-as the existing multi-sheet Inventor DWG to new Inventor multisheet DWG's with the new file 
'names being the existing Sheet Names. To make life simple, you should rename each sheet to match the drawing shown. I havent worked out how to automate that yet.
'In the exmaple below the original multi sheet drawing is named in the format Region-DrawingNumber-Revsion Eg: FN-1234567-0A
'In the exmaple below the sheet names are in the format DrawingNumber-SheetNo. Eg: 1234567-01, 1234567-02
'Sooo....you may have to modify to suit.

Dim oDoc As Inventor.DrawingDocument
oDoc = ThisDoc.Document
Dim oSheet As Inventor.Sheet

'Get folder (using the same path as this doc)
folderName = ThisDoc.Path

	'Look at each sheet in drawing set
	For Each oSheet In oDoc.Sheets
		
	'Fix sheeet names for export, removing colon
	Try
	oName = Replace(oSheet.Name, ":", "-") 
	'Save sheets as Inventor DWGs
	
	'Remove what used to be a colon (:01,:02,:03 etc) & is now a dash (-01,-02,-03 etc)
	SheetName = oName
	ColonIndex = SheetName.LastIndexOf("-")
	SheetNameOnly = SheetName.Substring(0, ColonIndex)
		
	SaveName = SheetNameOnly
	
	'Save existing multi sheet drawing to new copies with new file names matching existing sheet names
	ThisDoc.Document.SaveAsInventorDWG(ThisDoc.Path & "\" & SaveName & ".dwg", True) 
	Catch
	End Try
	Next
  
  	'Message to tell the user the files were created
	MessageBox.Show("New *.dwg files created in: " _
	&folderName, "iLogic")

	'To delete sheets from newly saved drawings that do not match newly saved filename:
	
	'Look at Each sheet
	For Each oSheet In oDoc.Sheets
		
	'Fix name for search, removing colon
	Try
	oName = Replace(oSheet.Name, ":", "-") 
	
	'Remove what used to be a colon (:01,:02,:03 etc) & is now a dash (-01,-02,-03 etc)
	SheetName = oName
	ColonIndex = SheetName.LastIndexOf("-")
	SheetNameOnly = SheetName.Substring(0, ColonIndex)
		
	SaveName = SheetNameOnly
	
	'Open each newly created document indivdually & run external rule to delete all sheets that dont match new drawing number
	doc = ThisApplication.Documents.Open(ThisDoc.Path & "\" & SaveName & ".dwg", True) 
	auto = iLogicVb.Automation
	auto.RunExternalRule(doc, "STEP2-DELETE SHEETS") 
	'Have to save or it will do nothing
	doc.Save
	doc.Close(True)
	
	Catch
	End Try
	Next

 

Second code:

''From here sort of: https://forums.autodesk.com/t5/inventor-forum/using-ilogic-to-delete-a-sheet-from-a-drawing/td-p/5385055
'Drawing is multi-sheet Inventor DWG, with sheets named 
'1234567-01:1
'1234567-02:2
'1234567-03:3
'1234567-04:4
'1234567-05:5
'1234567-06:6
'1234567-07:7

'This doc file name is 1234567-01.dwg To get doc filename without extension ".dwg"
SName = ThisDoc.FileName(False)
'Gets File Name "1234567-01"

'Create name & add (:) to search sheets for deletion
oKeepsheet = SName & ":1"
'Should change to this: "1234567-01:1"

'Iterate through the sheets & delete everything that is not "1234567-01:1
Dim oSheet As Sheet
oSheetName = oKeepsheet
'oKeepsheet = "1234567-01:01" 
'If its (:02) in the series, I think it shouldn't matter as it will iterate until there is only (:01) left 

'Search drawing sheets and delete anything anything that is not Keepsheet = "1234567-01:01"   
For Each oSheet In ThisApplication.ActiveDocument.Sheets
	If oSheet.Name <> oSheetName Then
	oSheet.Delete
	End If
Next
0 Likes
Accepted solutions (2)
1,655 Views
22 Replies
Replies (22)
Message 21 of 23

GKPByDesign
Advocate
Advocate

I havent had a chance to save this, but I just realised, could I not just export the drawing by sheet as dwg file, as long as I called the sheets by the file name, it will do the same job no? 

0 Likes
Message 22 of 23

A.Acheson
Mentor
Mentor

There isn't really a method for exporting sheets as far as I know. Is the rule still crashing inventor? Do you know is it in the saving process or deleting process? It certainly shouldn't be doing that. There must be a stability problem of some kind. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 23 of 23

GKPByDesign
Advocate
Advocate

Yes after a period of drawing inventor closes, strangely every time it has done this, it does not generate that crash report window? So I am unsure, and it varies in regard to the number of sheets. 

0 Likes