Thanks Gupta for your reply but this is for an open draw.
My macro is a batch so i don't have any draw open and any view selected.
You don't have any example corresponding more to i need to do ?
Don't have a macro but I remember making a batch macro to save referenced model (though all files were on local hard disk and not vault)
Thanks again for your help; i tried all day long and didn't manage to make it through the vault.
Another solution to solve my problem would be to "guess" the part or the assembly name which in 98% of the case is the same than the draw (the 2% can be done manually for now).
I works well but:
I use this to get the part or the assembly in local:
Set doc = alldocs(fileprt)
doc.Save "C:\temp dir\"
It works well; i get the assembly and the prt and after save it in .step with another Sub in the macro.
The problem is as i need to guess the file name and don't know if it is a .sldprt or .sldasm when i have an error the script kill.
How in VBA, can i catch the error and try another name of file ?
Thanks for your help !
File extension or model type can be found. Are the files in the vault when you run the macro. If yes then I feel you would have to check then out, activate the model and then save as step file. And finally delete all local files
Thanks Deepak for your advises.
i finally made a function that return the first part found in the draw (we could return an array but i don't need it)
As i'm a beginner in VBA i'm pretty sure that there is few things to optimize. Do not hesitate to let me know !
' the function don't check that the file exist... you should check it before or add it in the function.
Function GetFilePartFromDraw(sDocFileName As String)
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim nDocType As Long
Dim nErrors As Long
Dim nWarnings As Long
Set swApp = CreateObject("SldWorks.Application")
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDrawModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim swActiveView As SldWorks.View
Dim bRet As Boolean
' Determine type of SolidWorks file based on file extension
If InStr(LCase(sDocFileName), "slddrw") > 0 Then
nDocType = swDocDRAWING
Set swModel = swApp.OpenDoc6(sDocFileName, nDocType, _
swOpenDocOptions_Silent, "", nErrors, nWarnings)
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
Set swActiveView = swDraw.ActiveDrawingView
Set swView = swDraw.GetFirstView
While Not swView Is Nothing
If swView.GetReferencedModelName <> "" Then
GetFilePartFromDraw = swView.GetReferencedModelName
bRet = swDraw.ActivateView(swView.GetName2):
If False = bRet Then
bRet = swDraw.ActivateSheet(swView.GetName2)
Set swView = swView.GetNextView
So how do you intend to run it with WPDM?