Macro Help
Macro Help
(OP)
A fellow over at solidworks community helped me out and wrote a macro for me. It's works fine on my work machine but I can't get it to run on my home machine. I asked for some help over there but no responses. I was hoping someone here could help.
I get a run time error. See attatchment.
My home rig specs are
SW2009 32 SP 1.0
Home built pc
Nvidia Quadro FX 1100
Core 2 1.8GHZ, 2GB RAM
XP Pro 32 SP2.0
work machine specs are below.
here is the code
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim vConfs As Variant
Dim i As Integer
Dim sDrTemplate As String
Dim lDrSize As Long
Dim sOutputFolder As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
sOutputFolder = Left(swModel.GetPathName(), Len(swModel.GetPathName()) - Len(swModel.GetTitle()) - 7)
sDrTemplate = swApp.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateDrawing)
lDrSize = swDwgPaperSizes_e.swDwgPaperA0size
vConfs = swModel.GetConfigurationNames()
For i = 0 To UBound(vConfs)
Set swDraw = swApp.NewDocument(sDrTemplate, lDrSize, 0, 0)
swDraw.Create1stAngleViews2 swModel.GetPathName
Dim swView As SldWorks.View
Set swView = swDraw.GetFirstView
While Not swView Is Nothing
swView.ReferencedConfiguration = vConfs(i)
Set swView = swView.GetNextView
Wend
Dim swDrawModel As SldWorks.ModelDoc2
Set swDrawModel = swDraw
swDrawModel.ForceRebuild3 False
swDraw.InsertModelAnnotations3 swImportModelItemsSource_e.swImportModelItemsFromEntireModel, 32776, True, True, False, False
swDrawModel.Extension.SaveAs sOutputFolder + swModel.GetTitle() + "_" + vConfs(i) + ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0
swApp.CloseDoc swDrawModel.GetTitle()
Next
End Sub
I get a run time error. See attatchment.
My home rig specs are
SW2009 32 SP 1.0
Home built pc
Nvidia Quadro FX 1100
Core 2 1.8GHZ, 2GB RAM
XP Pro 32 SP2.0
work machine specs are below.
here is the code
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim vConfs As Variant
Dim i As Integer
Dim sDrTemplate As String
Dim lDrSize As Long
Dim sOutputFolder As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
sOutputFolder = Left(swModel.GetPathName(), Len(swModel.GetPathName()) - Len(swModel.GetTitle()) - 7)
sDrTemplate = swApp.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateDrawing)
lDrSize = swDwgPaperSizes_e.swDwgPaperA0size
vConfs = swModel.GetConfigurationNames()
For i = 0 To UBound(vConfs)
Set swDraw = swApp.NewDocument(sDrTemplate, lDrSize, 0, 0)
swDraw.Create1stAngleViews2 swModel.GetPathName
Dim swView As SldWorks.View
Set swView = swDraw.GetFirstView
While Not swView Is Nothing
swView.ReferencedConfiguration = vConfs(i)
Set swView = swView.GetNextView
Wend
Dim swDrawModel As SldWorks.ModelDoc2
Set swDrawModel = swDraw
swDrawModel.ForceRebuild3 False
swDraw.InsertModelAnnotations3 swImportModelItemsSource_e.swImportModelItemsFromEntireModel, 32776, True, True, False, False
swDrawModel.Extension.SaveAs sOutputFolder + swModel.GetTitle() + "_" + vConfs(i) + ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0
swApp.CloseDoc swDrawModel.GetTitle()
Next
End Sub
Certified SolidWorks Associate
SW2009 X64 SP 1.0
Dell Precision T5400
Nvidia Quadro FX 5600
Xeon 2.5GHz Quad Core, 4GB RAM
XP Pro X64 SP2.0






RE: Macro Help
RE: Macro Help
Certified SolidWorks Associate
SW2009 X64 SP 1.0
Dell Precision T5400
Nvidia Quadro FX 5600
Xeon 2.5GHz Quad Core, 4GB RAM
XP Pro X64 SP2.0
RE: Macro Help
Or
Edit the macro in VB editor. Go to Tools > References and look for missing libraries
Deepak Gupta
SW2009 SP4.1
SW2007 SP5.0
MathCAD 14.0
RE: Macro Help
I have checked the ref library and they are the same.
I did copy it to a new macro on my home machine.
Certified SolidWorks Associate
SW2009 X64 SP 1.0
Dell Precision T5400
Nvidia Quadro FX 5600
Xeon 2.5GHz Quad Core, 4GB RAM
XP Pro X64 SP2.0
RE: Macro Help
Deepak Gupta
SW2009 SP4.1
SW2007 SP5.0
MathCAD 14.0
RE: Macro Help
The writer of the macro said to check my default drawing template in settings. He thinks it's not getting a drawing template therfore it has a empty drawing.
I will try that when I get home.
Certified SolidWorks Associate
SW2009 X64 SP 1.0
Dell Precision T5400
Nvidia Quadro FX 5600
Xeon 2.5GHz Quad Core, 4GB RAM
XP Pro X64 SP2.0
RE: Macro Help
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Macro Help
Works great and is a nice macro. I'm trying to figure out how to make it populate predefined views of a template. Once that is ironed out this will be a nice macro for automating simple drawings.
Certified SolidWorks Associate
SW2009 X64 SP 1.0
Dell Precision T5400
Nvidia Quadro FX 5600
Xeon 2.5GHz Quad Core, 4GB RAM
XP Pro X64 SP2.0