
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Probably a very simple solution to this problem, but I cannot for the life of me figure out how to accomplish this.
I have a rule that exports a named .dwg to a named folder. This helps me stay organized when batching out parts pre-CNC.
This is all fine except I can't figure out how to get a true "cancel" out my rule. When exporting iParts, I have a for loop that iterates through each member. In that loop a sub is called to do the exporting. However, if I have exported the parts I need, or just want to cancel out early, I can't get out of the loop until all of the members have run. I tried "Return", "Exit Sub" and "GoTo" and couldn't get it. I only managed to exit the sub, but still have to finish looping.
Maybe I'm just approaching the whole problem wrong.
Thoughts appreciated.
Thanks,
'Funnybus
Sub Main Dim oDocPath As String = ThisDoc.Path Dim oDoc As Document = ThisDoc.Document Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition Dim sPrtPath As String = (Left(oDocPath,InStrRev(oDocPath, "\"))&"_CNC") If Not System.IO.Directory.Exists(sPrtPath) Then MessageBox.Show("Could not locate CNC folder for this project." & vbLf & vbLf & sPrtPath & vbLf, "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) Return End If If oDoc.DocumentType <> kPartDocumentObject Then MessageBox.Show("Rule can only be run from a part document.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) Exit Sub End If If oCompDef.IsiPartFactory Then Export2iPart(oCompDef, sPrtPath) Else Export2Part(sPrtPath) End If End Sub Private Sub Export2Part (sPrtPath As String) Dim sPrtNum As String = iProperties.Value("Project", "Description") YesNo(sPrtNum, sPrtPath) End Sub Private Sub Export2iPart (oCompDef As ComponentDefinition, sPrtPath As String) Dim oFactory As iPartFactory = oCompDef.iPartFactory For Each oRow As iPartTableRow In oFactory.TableRows Dim sPrtNum As String = oRow.memberName iPart.ChangeRow("", sPrtNum) YesNo(sPrtNum, sPrtPath) Next End Sub Private Sub YesNo (sPrtNum As String, sPrtPath As String) Dim sPrtFldr As String = sPrtPath & "\" & sPrtNum Dim sPrtDwg As String = sPrtFldr & "\" & sPrtNum & ".dwg" oMSG = MessageBox.Show("Create CNC?" & vbLf & vbLf & "Part Number: " & sPrtNum & vbLf & vbLf & sPrtDwg & vbLf, "Export to CNC", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If oMSG = vbYes Then If System.IO.Directory.Exists(sPrtFldr) oMSG2 = MessageBox.Show("Existing folder found: " & vbLf & vbLf & sPrtFldr & vbLf & vbLf & "Overwrite existing folder?" & vbLf, "Existing Folder Found", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) If oMSG2 = vbYes Then System.IO.Directory.CreateDirectory(sPrtFldr) Dim oPrt As PartDocument = ThisApplication.ActiveDocument oPrt.SaveAs(sPrtDwg, True) Else If oMSG2 = vbCancel Then 'End rule End If Else System.IO.Directory.CreateDirectory(sPrtFldr) Dim oPrt As PartDocument = ThisApplication.ActiveDocument oPrt.SaveAs(sPrtDwg, True) End If Else If oMSG = vbCancel Then 'End rule End If End Sub
Solved! Go to Solution.