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