AnsweredAssumed Answered

SaveAs and Open questions

Question asked by Ben Reilly on May 4, 2009
Latest reply on May 14, 2009 by Ben Reilly
I'm writing a bit of code as a button click on a user form for a SW macro, and what I need to do is take an assembly and save the assembly and all associated components with a suffix. I cannot save over the original (it is the master assembly). Also I have a 'lookup' button that is supposed to find and open an assembly. Neither works. Also, for the SaveAs and Lookup, the files will be in the same directory as the assembly, or may be in folders in that directory, and I will not necessarily know the path to the assembly. Below is the code for SaveAs:

Dim vResArray As Variant
Dim arrayBound As Integer
Dim titleStr As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

titleStr = swModel.GetTitle() 'get Title
vResArray = Split(titleStr, "-") 'separate at dash

If UBound(vResArray) > 0 Then 'Working door has -ordernumber
BCord = "Bottom Cord-" & vResArray(UBound(vResArray))
CladdingName = "Cladding-" & vResArray(UBound(vResArray))
BotDoorName = "Bottom Door Frame-" & vResArray(UBound(vResArray))
TopDoorName = "Top Door Frame-" & vResArray(UBound(vResArray))
HeaderName = "Header With Obstruction-" & vResArray(UBound(vResArray))
AssemblyName = "DriveWorks Bifold Master -" & vResArray(UBound(vResArray))

Else
BCord = "Bottom Cord"
CladdingName = "Cladding"
BotDoorName = "Bottom Door Frame"
TopDoorName = "Top Door Frame"
HeaderName = "Header With Obstruction"
AssemblyName = "DriveWorks Bifold Master"

End If

Set swModel = swApp.ActivateDoc2(BCord, False, longstatus)
bRet = swModel.Extension.SaveAs3("Bottom Cord-" & DoorNumber, 0, 2, Nothing, longstatus, longwarnings)
Set swModel = swApp.ActivateDoc2(titleStr, False, longstatus)
Set swModel = swApp.ActivateDoc2(CladdingName, False, longstatus)
bRet = swModel.Extension.SaveAs3("Cladding-" & DoorNumber, 0, 2, Nothing, longstatus, longwarnings)
Set swModel = swApp.ActivateDoc2(titleStr, False, longstatus)
Set swModel = swApp.ActivateDoc2(BotDoorName, False, longstatus)
bRet = swModel.Extension.SaveAs3("Bottom Door Frame-" & DoorNumber, 0, 2, Nothing, longstatus, longwarnings)
Set swModel = swApp.ActivateDoc2(titleStr, False, longstatus)
Set swModel = swApp.ActivateDoc2(TopDoorName, False, longstatus)
bRet = swModel.Extension.SaveAs3("Top Door Frame-" & DoorNumber, 0, 2, Nothing, longstatus, longwarnings)
Set swModel = swApp.ActivateDoc2(titleStr, False, longstatus)
Set swModel = swApp.ActivateDoc2(HeaderName, False, longstatus)
bRet = swModel.Extension.SaveAs3("Header With Obstruction-" & DoorNumber, 0, 2, Nothing, longstatus, longwarnings)
Set swModel = swApp.ActivateDoc2(titleStr, False, longstatus)
Set swModel = swApp.ActivateDoc2(AssemblyName, False, longstatus)
bRet = swModel.Extension.SaveAs3("Driveworks Bifold Master -" & DoorNumber, 0, 2, Nothing, longstatus, longwarnings)
Set swModel = swApp.ActivateDoc2(titleStr, False, longstatus)


'arrayBound = UBound(vResArray)
'titleStr = vResArray(arrayBound) 'Set title to second Part

End Sub


And for LOOKUP:

Private Sub Lookup_Click()

Dim Retval As Object
Dim Filename, nErrors, nWarnings As String

Set swApp = Application.SldWorks

DoorNumber = DoorNum.Value
Filename = "DriveWorks Bifold Master -" & DoorNumber & ".sldasm"

MsgBox Filename

Set swModel = swApp.OpenDoc6("C:\Documents and Settings\Administrator\My Documents\Schweiss\Bifold Model\Driveworks Bifold Master\" & Filename, swDocASSEMBLY, swOpenDocOptions_Silent, "Open", nErrors, nWarnings)

Errors: Type Mismatch. Any help?

Outcomes