Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

using iLogic to delete a sheet from a drawing

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
2025 Views, 7 Replies

using iLogic to delete a sheet from a drawing

I have a template set up that opens with a drawing sheet and a history sheet, but I now have a requirement to remove the History sheet for 50% of produced drawings.

I would like to be able to do this autoimaticly using ilogic but I am not very sklilled in this area so any help would be greatly appreciated.

 

Steve

Tags (2)
7 REPLIES 7
Message 2 of 8
salariua
in reply to: Anonymous

You could start by looking at the code injector, it runs codes for batches of files.

 

Then try and identify how to pick on those sheets. Are they having a unique name? Are they keeping the same position relative to the others. Is it the last sheet all the time? the first?

 

How can it be easily identified?

 

 

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 3 of 8
salariua
in reply to: Anonymous

Give us some screen shots of the drawing browser to see what you need deleting.

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 4 of 8
Anonymous
in reply to: salariua

Here you go.

 

I have the template set to select a border format by way of a rule run from a form, but for a few of the templates I do not need the sheet named "History Sheet"

 

Hopefully that is a bit clearer?Smiley Happy


@salariua wrote:

Give us some screen shots of the drawing browser to see what you need deleting.


 

Message 5 of 8
Curtis_Waguespack
in reply to: Anonymous

Hi steveadd,

 

Here is a quick example:

 

'Iterate through the sheets
Dim oSheet As Sheet
For Each oSheet In ThisApplication.ActiveDocument.Sheets
	If oSheet.Name.Contains("History Sheet") Then
	oSheet.Delete
	End If
Next

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 6 of 8
Anonymous
in reply to: Curtis_Waguespack

Hi Curtis,

 

Would it be possible to tweak this so it deleted sheets based on the material...

 

I have drawings with multiple sheets.

Each sheet shows 1 single part only.

The parts all have material assigned to them.

 

Can the Ilogic check if the parts material = "MDF" or "PLY" if it doesn't the illogic would delete the sheet?

 

Thanks for your help


@Curtis_Waguespack wrote:

Hi steveadd,

 

Here is a quick example:

 

'Iterate through the sheets
Dim oSheet As Sheet
For Each oSheet In ThisApplication.ActiveDocument.Sheets
	If oSheet.Name.Contains("History Sheet") Then
	oSheet.Delete
	End If
Next

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


 

Message 7 of 8

Hi Curtis,

My brain is melting; wondering if you could please assist?

I kind of need the opposite to 'contains'. I need it to search 'does not contain' & I don't know how to do that. I've run a rule to save-copy-as a multi sheet Inventor DWG to new drawings with each Sheet Number of the old multi sheet drawing being the newly created drawing file names. I then want to open those new drawings & delete all sheets of the copied drawings that don't match the filename. Then sheet name will match file name.

 

I only started iLogic last week, so its probably messy & there is probably better ways to say it;  but code is below:

 

'Drawing is multi-sheet Inventor DWG, with sheets named 
'Layout1:1
'Layout2:2
'Layout3:3
'Layout4:4
'Layout5:5
'Layout6:6
'Layout7:7

'This doc file name is Layout2-2.dwg. To remove ".dwg":
SName = ThisDoc.FileName
ColonIndex = SName.LastIndexOf(".")
KeepSheetOnly = SName.Substring(0, ColonIndex)
'Should change to this: "Layout2-2"?

'Replace (-) with (:) to search sheets
oKeepSheet = Replace(KeepSheetOnly, "-", ":") 
'Should change to this: "Layout2:2"?

'Iterate through the sheets & delete everything that is not "Layout2:2"
Dim oSheet As Sheet
For Each oSheet In ThisApplication.ActiveDocument.Sheets
	If oSheet.Name <> oKeepSheet Then
	oSheet.Delete
	End If
Next

Gives me this error:

 

Error in rule: Delete Sheets, in document: Layout2-2.dwg

Length cannot be less than zero.
Parameter name: length

 

Tried this also:

 

Dim oSheet As Sheet
For Each oSheet In ThisApplication.ActiveDocument.Sheets
	If Not oSheet.Name = Not oKeepSheet then
	oSheet.Delete
	End If

That has same error.

 

For reference, this is Step 1 (Save Copy As Inventor DWGs):

 

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
	For Each oSheet In oDoc.Sheets
	'Fix name for export, removing colon
	Try
	oName = Replace(oSheet.Name, ":", "-") 
	'Save sheets as Inventor DWGs
	ThisDoc.Document.SaveAsInventorDWG(ThisDoc.Path & "\" & oName & ".dwg", True) 
	Catch
	End Try
	Next
  

'Message to tell the user the files were created
MessageBox.Show("New *.dwg files created in: " _
&folderName, "iLogic")

'Open the folder where the new folders are saved
Shell("explorer.exe " & folderName & "\" ,vbNormalFocus)

Ideally, it would be good to combine all steps in one rule, but I don't really mind the separation between saving>saved folder opening>opening each doc>running rule to delete sheets. Then you can double check drawing before checking in.

 

Any help would be greatly appreciated.

Thanks in advance

Cheers - Daniel

Message 8 of 8

Never mind; after much beating my head against a wall, I got it working.

Solution here:

 

Re: Can I split a multi sheet IDW into single sheet IDWs? - Autodesk Community - Inventor

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report