Drawing iLogic code to Delete unwanted sheets

Drawing iLogic code to Delete unwanted sheets

Scott.Hallmark
Advocate Advocate
1,093 Views
4 Replies
Message 1 of 5

Drawing iLogic code to Delete unwanted sheets

Scott.Hallmark
Advocate
Advocate

This might be a long shot but I will test the waters.  I produce a dwg that has a main assembly as the first sheet.  The remaining sheets are the details of every part in that assembly, whether visible or not in the assembly.  In the main assembly sheet, I generate a Parts List from a Design View of only visible parts.  My code is turning visibility of items on and off as needed, among several other things.  So, I have the main assembly sheet and 40+ details of parts that I may or may not need in the final drawing.

 

What I would like to be able to do is to have the code in the DWG read the existing Parts List and then delete the sheets of the items that do not belong.  So a single Part may be called 101-MM1 and the Sheet is also called 101-MM1 and that sheet needs to stay.  If I have a Sheet that is called 101-MM2, but 101-MM2 is turned off in the assembly which means that part does not appear in the Parts List, I would like that Sheet deleted automatically.  Does that make sense?

 

The reason for this?  I may at times have to delete 20 or more sheets so I can finalize my assembly package drawing.  That is time consuming and prone to error if I delete the wrong one or don't delete one that should have been.

 

Thanks!

** If my reply resolves this issue, please choose Accept Solution **
Scott Hallmark, Design Specialist | Fluor Corporation
Inventor and AutoCAD Certified Professional, Autodesk Certified Instructor | My Plant3D Notes | AU Speaker | ROLL TIDE!
0 Likes
Accepted solutions (1)
1,094 Views
4 Replies
Replies (4)
Message 2 of 5

clutsa
Collaborator
Collaborator
Accepted solution

Give this a try (on a copy of course)

SyntaxEditor Code Snippet
Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument

Dim sheetCol As ObjectCollection = app.TransientObjects.CreateObjectCollection

For Each oSheet As Sheet In doc.Sheets
	sheetCol.Add(oSheet.Name)
	For Each partListObj As PartsListRow In doc.Sheets(1).PartsLists(1).PartsListRows
		If oSheet.Name Like partListObj.Item(3).Value & ":*" Then sheetCol.Remove(sheetCol.Count) 'change Item(3) to your PartNumber Column #
	Next
Next
sheetCol.Remove(1)
For x= sheetCol.Count to 1 step - 1
	'MessageBox.Show(sheetCol(x), "Title")
	doc.Sheets.Item(sheetCol(x)).Delete
Next

 Edit: changed code so it runs the loop backwards because after it deleted the first sheet all the names changed

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 3 of 5

Scott.Hallmark
Advocate
Advocate

It seems very close.  It deletes the first unused sheet in the list then throws an error. 

 

Error in rule: DeleteUnusedSheets_Rule, in document: 203-UNIT FAB.dwg
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
 
And I did change the Item(X) to the correct column number.
** If my reply resolves this issue, please choose Accept Solution **
Scott Hallmark, Design Specialist | Fluor Corporation
Inventor and AutoCAD Certified Professional, Autodesk Certified Instructor | My Plant3D Notes | AU Speaker | ROLL TIDE!
0 Likes
Message 4 of 5

clutsa
Collaborator
Collaborator

I caught that and did an edit on my response but I see I wasn't quick enough.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 5

Scott.Hallmark
Advocate
Advocate

wow, that is superb!  Perfect!

 

Thank you!

** If my reply resolves this issue, please choose Accept Solution **
Scott Hallmark, Design Specialist | Fluor Corporation
Inventor and AutoCAD Certified Professional, Autodesk Certified Instructor | My Plant3D Notes | AU Speaker | ROLL TIDE!
0 Likes