Macro to open, forcerebuild, close sw docs
Macro to open, forcerebuild, close sw docs
(OP)
I found this question on comp.cad.solidworks here: http://g roups.goog le.com/gro up/comp.ca d.solidwor ks/browse_ thread/thr ead/0a0e7b 1bc1d50f4e /6c1bdb433 6ad1d3d?hl =en#6c1bdb 4336ad1d3d
Basically does anyone have a macro tht will open a file, forcerebuild it, save it, then close it? Is sounds pretty easy, and I'd work on this myself except I don't have a lot of time right now. Has anyone else done this?
Basically does anyone have a macro tht will open a file, forcerebuild it, save it, then close it? Is sounds pretty easy, and I'd work on this myself except I don't have a lot of time right now. Has anyone else done this?
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group






RE: Macro to open, forcerebuild, close sw docs
RE: Macro to open, forcerebuild, close sw docs
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: Macro to open, forcerebuild, close sw docs
CODE
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim strPathAndFilename As String
Dim strResponse As String
Dim strFileType As Long
Dim longstatus As Long
Dim longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
strPathAndFilename = "C:\Temp\Part1.SLDDRW"
strResponse = vbYes
If StrComp((UCase$(Right$(strPathAndFilename, 7))), ".SLDPRT", vbTextCompare) = 0 Then
strFileType = swDocPART
ElseIf StrComp((UCase$(Right$(strPathAndFilename, 7))), ".SLDASM", vbTextCompare) = 0 Then
strFileType = swDocASSEMBLY
ElseIf StrComp((UCase$(Right$(strPathAndFilename, 7))), ".SLDDRW", vbTextCompare) = 0 Then
strFileType = swDocDRAWING
End If
Set swModel = swApp.OpenDoc6(strPathAndFilename, strFileType, 0, "", longstatus, longwarnings)
Set swModel = swApp.ActivateDoc2(strPathAndFilename, False, longstatus)
If (swModel Is Nothing) Then
strResponse = MsgBox("The file could not be found." & Chr(13) & "Routine Ending.", vbCritical, "FileOpenRebuildSaveClose")
End
End If
If (swModel.IsOpenedReadOnly = "False") Then
If (swModel.GetType <> swDocDRAWING) Then
'Shade Part
swModel.ViewDisplayShaded
'Set view
'swModel.ShowNamedView2 "*Isometric", 7
'swModel.ShowNamedView2 "*Trimetric", 8
swModel.ShowNamedView2 "*Dimetric", 9
'Set Feature Manager Splitter Position
swModel.FeatureManagerSplitterPosition = 0.3
End If
'Rebuild File
'swModel.EditRebuild3 'Stoplight or [Ctrl]+B
swModel.ForceRebuild '[Ctrl]+Q
'Zoom to extents
swModel.ViewZoomtofit2
'Save
swModel.Save2 False
Else
strResponse = MsgBox("The file is Read-Only." & Chr(13) & "Do you want to close the file without Saving?", vbCritical + vbYesNo, "FileOpenRebuildSaveClose")
End If
Set swModel = Nothing
If (strResponse = vbYes) Then
'Close
swApp.CloseDoc strPathAndFilename
End If
Set swApp = Nothing
End Sub
RE: Macro to open, forcerebuild, close sw docs
Thanks! Are you the author or do you have a source for this code?
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: Macro to open, forcerebuild, close sw docs
Ken
RE: Macro to open, forcerebuild, close sw docs
Mind if I tinker with the macro and host it on my site? I would like to had a userform for starters.
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: Macro to open, forcerebuild, close sw docs
Ken
RE: Macro to open, forcerebuild, close sw docs
Thanks for helping me out, I will work with this, need it to run a whole dir drawing by drawing. Will see what I can come up with myself and then get back if I wont succeed.
RE: Macro to open, forcerebuild, close sw docs
if you're interested, I've written an outside SolidWorks macro .
It rebuild an Assembly and all parts which compose the assembly.
In the rebuilding, all configurations are activated to "forceRegen" them.
Maybe this macro interests you (it's a self executable which starts SW)
SW2007 SP4
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450
RE: Macro to open, forcerebuild, close sw docs
Location where this is available?
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group