I have a master file, driven by a design table. The macro is supposed to;
- save each configuration of this master file out as a separate file
- open this new file, delete the design table and all other configurations
- re-save modified file
- switch back to original master file, index to next config and repeat.
- master file is to remain unchanged.
The macro runs correctly for 1st configuration (creates new file, opens new file, strips out DT & configs, re-saves new file.
The problem comes at trying to switch back to original master file. I get a run-time error "The object invoked has disconnected from its clients"
What am I missing here? Below is the section of code giving the error.
CT = 0
For x = 0 To ListBoxUserSelect.ListCount - 1 ' each item
If ListBoxUserSelect.Selected(x) = True Then ' item select
CT = CT + 1
End If
Next ' Get next cfg
LabelStatus.Caption = "" ' Clear status
DocName = ModelDoc2.GetTitle ' Doc title
DocPathname = ModelDoc2.GetPathName ' Doc path
For i = 1 To Len(DocPathname)
If Mid$(DocPathname, i, 1) = "\" Then z = i ' last slash
Next i
DocPath = Left$(DocPathname, z) ' remove doc name
Count = 0
For x = 0 To ListBoxUserSelect.ListCount - 1 ' each item
If ListBoxUserSelect.Selected(x) = True Then ' item select
ThisConfigName = ListBoxUserSelect.List(x, 0)
ExportName = ThisConfigName & _
ComboFileType.List(ComboFileType.ListIndex, 1) ' Export name
LabelStatus.Caption = " (" & Count + 1 & "/" & CT & ")" & _
" Exporting: " & ExportName ' Show name
FormLibExport.Repaint ' Repaint form
ModelDoc2.ShowConfiguration2 ThisConfigName ' Show config <<<ERRORS HERE ON 2ND PASS>>>
ModelDoc2.GraphicsRedraw2 ' Redraw screen
Retval = ModelDoc2.Extension.SelectByID2("Sketch1", "SKETCH", _
0#, 0#, 0#, False, 0, Nothing, swSelectOptionDefault) ' Select sketch
ModelDoc2.SaveAs4 DocPath & ExportName, swSaveAsCurrentVersion, _
swSaveAsOptions_Silent, Errors, Warnings ' Create file
'Open the new file with the Correct Configuration
Set ModelDocCopy = swApp.OpenDoc6(ExportName, swDocPART, _
swOpenDocOptions_Silent, ThisConfigName, Errors, Warnings)
' Delete design table
ModelDocCopy.DeleteDesignTable
'Get all the configurations names into an array
ConfigNames = ModelDocCopy.GetConfigurationNames
'Delete each configuration except the one that is the active one
For nCountCopy = 0 To UBound(ConfigNames)
If ConfigNames(nCountCopy) <> ConfigNames(nCount) Then
ModelDocCopy.DeleteConfiguration2 (ConfigNames(nCountCopy))
ModelDocCopy.DeleteConfiguration2 ("Default")
End If
Next
'Save and close the modelcopy
ModelDocCopy.SaveSilent
swApp.CloseDoc ModelDocCopy.GetPathName
Set ModelDocCopy = Nothing
Count = Count + 1
CheckBoxFilter.Enabled = True
EXType = "configurations"
End If
Next ' Get next cfg
Any help would be greatly appreciated.
- Mark
- save each configuration of this master file out as a separate file
- open this new file, delete the design table and all other configurations
- re-save modified file
- switch back to original master file, index to next config and repeat.
- master file is to remain unchanged.
The macro runs correctly for 1st configuration (creates new file, opens new file, strips out DT & configs, re-saves new file.
The problem comes at trying to switch back to original master file. I get a run-time error "The object invoked has disconnected from its clients"
What am I missing here? Below is the section of code giving the error.
CT = 0
For x = 0 To ListBoxUserSelect.ListCount - 1 ' each item
If ListBoxUserSelect.Selected(x) = True Then ' item select
CT = CT + 1
End If
Next ' Get next cfg
LabelStatus.Caption = "" ' Clear status
DocName = ModelDoc2.GetTitle ' Doc title
DocPathname = ModelDoc2.GetPathName ' Doc path
For i = 1 To Len(DocPathname)
If Mid$(DocPathname, i, 1) = "\" Then z = i ' last slash
Next i
DocPath = Left$(DocPathname, z) ' remove doc name
Count = 0
For x = 0 To ListBoxUserSelect.ListCount - 1 ' each item
If ListBoxUserSelect.Selected(x) = True Then ' item select
ThisConfigName = ListBoxUserSelect.List(x, 0)
ExportName = ThisConfigName & _
ComboFileType.List(ComboFileType.ListIndex, 1) ' Export name
LabelStatus.Caption = " (" & Count + 1 & "/" & CT & ")" & _
" Exporting: " & ExportName ' Show name
FormLibExport.Repaint ' Repaint form
ModelDoc2.ShowConfiguration2 ThisConfigName ' Show config <<<ERRORS HERE ON 2ND PASS>>>
ModelDoc2.GraphicsRedraw2 ' Redraw screen
Retval = ModelDoc2.Extension.SelectByID2("Sketch1", "SKETCH", _
0#, 0#, 0#, False, 0, Nothing, swSelectOptionDefault) ' Select sketch
ModelDoc2.SaveAs4 DocPath & ExportName, swSaveAsCurrentVersion, _
swSaveAsOptions_Silent, Errors, Warnings ' Create file
'Open the new file with the Correct Configuration
Set ModelDocCopy = swApp.OpenDoc6(ExportName, swDocPART, _
swOpenDocOptions_Silent, ThisConfigName, Errors, Warnings)
' Delete design table
ModelDocCopy.DeleteDesignTable
'Get all the configurations names into an array
ConfigNames = ModelDocCopy.GetConfigurationNames
'Delete each configuration except the one that is the active one
For nCountCopy = 0 To UBound(ConfigNames)
If ConfigNames(nCountCopy) <> ConfigNames(nCount) Then
ModelDocCopy.DeleteConfiguration2 (ConfigNames(nCountCopy))
ModelDocCopy.DeleteConfiguration2 ("Default")
End If
Next
'Save and close the modelcopy
ModelDocCopy.SaveSilent
swApp.CloseDoc ModelDocCopy.GetPathName
Set ModelDocCopy = Nothing
Count = Count + 1
CheckBoxFilter.Enabled = True
EXType = "configurations"
End If
Next ' Get next cfg
Any help would be greatly appreciated.
- Mark