Configuration Macro
Configuration Macro
(OP)
I have about 600 configurations of a part and I need to gernerate DWG's of each configuration (without me watching) I can't seem to find anyhting and my codes suck. Any help would be great.
When was the last time you drove down the highway without seeing a commercial truck hauling goods?
Download nowINTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
|
RE: Configuration Macro
Windows 2000 Professional / Microsoft Intellimouse Explorer
SolidWorks 2006 SP02.0 / SpaceBall 4000 FLX
Diet Coke with Lime / Dark Chocolate
Lava Lamp
www.Tate3d.com
RE: Configuration Macro
-create drawing template with pre-defined views
-get names of all configs
-activate first config (ModelDoc2.ShowConfiguration2)
-create new drawing (sldworks.NewDrawing)
-use InsertModelInPredefinedView to populate those drawing views
-save drawing, close
-loop to next configuration in the model
as to dimensions, notes etc. that vary between parts, you would have to set those to be inserted for each new config
RE: Configuration Macro
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swDrawModel As SldWorks.ModelDoc2
Dim nOldVal As Long
Dim bRet As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set Doc = swApp.ActiveDoc
Set swModel = swApp.ActiveDoc
peder = Doc.GetConfigurationNames
For Each Name In peder
Set swDraw = swApp.NewDrawing2(swDwgTemplateA1size, "C:\Program Files\SolidWorks\data\templates\no title block.drwdot", swDwgPaperA1size, 0.841, 0.594)
Set swDrawModel = swDraw
bRet = swDraw.CreateFlatPatternViewFromModelView2( _
swModel.GetPathName, Name, _
PaperWidth / 2, PaperHeight / 2,0#,True)
Set swApp = Application.SldWorks
Next Name
End Sub
RE: Configuration Macro
I have no idea where I obtained it from, so unfortunately cannot give credit to its author.
It works well in SW05, but I don't know if it will work for SW06.
The macro traverses a part file & creates a new part for every config it finds. The SW Task Scheduler could then be used to create a drawing & then save them in DWG format.
CODE
Sub main()
Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Dim swConfig As SldWorks.configuration
Set swConfig = swModel.GetActiveConfiguration
Dim fname, ext, current As String
fname = swModel.GetPathName
ext = Mid(fname, InStr(fname, ".")) ' extension with leading dot
fname = Mid(fname, 1, InStr(fname, ".") - 1) ' path + name without extension
current = swModel.GetActiveConfiguration.name
Dim configs As Variant
configs = swModel.GetConfigurationNames
Dim i As Long
For i = 0 To UBound(configs)
If Not swModel.ShowConfiguration2(configs(i)) Then
Debug.Print ("Could not switch to config " + configs(i))
Else
Dim name As String
name = fname + "-" + configs(i) + ext
Dim err As Long
Dim warning As Long
Call swModel.SaveAs4(name, swSaveAsCurrentVersion, _
swSaveAsOptions_Copy + swSaveAsOptions_Silent + swSaveAsOptions_AvoidRebuildOnSave, _
err, warning)
Dim newdoc As SldWorks.ModelDoc2
Set newdoc = swApp.OpenDoc(name, swDocPART) ' works only for parts at the moment
If Not (newdoc Is Nothing) Then ' let's remove the unneeded configs
Dim j As Long
For j = 0 To UBound(configs)
If (i <> j) Then newdoc.DeleteConfiguration (configs(j))
Next j
swApp.CloseDoc (name)
End If
End If
Next i
swModel.ShowConfiguration2 (current) ' revert to current config
End Sub
Helpful SW websites FAQ559-520
How to get answers to your SW questions FAQ559-1091
RE: Configuration Macro
I don't know where I got the SaveAs2 command, the 2006 API help only talks about Save3 and SaveAs4 so maybe its from an earlier version...the lines I added are commented for easy reading.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swDrawModel As SldWorks.ModelDoc2
Dim nOldVal As Long
Dim bRet As Boolean
'Dim Pathout As String
'Dim ShortName As String
Set swApp = CreateObject("SldWorks.Application")
Set Doc = swApp.ActiveDoc
Set swModel = swApp.ActiveDoc
peder = Doc.GetConfigurationNames
'Pathout = "C:\Program Files\SolidWorks\autodraw\"
For Each Name In peder
Set swDraw = swApp.NewDrawing2(swDwgTemplateA1size, "C:\Program Files\SolidWorks\data\templates\no title block.drwdot", swDwgPaperA1size, 0.841, 0.594)
Set swDrawModel = swDraw
bRet = swDraw.CreateFlatPatternViewFromModelView2( _
swModel.GetPathName, Name, _
PaperWidth / 2, PaperHeight / 2,0#,True)
'Shortname = Str(Name)
'swDraw.SaveAs2 pathOut & Shortname & ".SLDDRW", 0, True, False
'Set Part = Nothing
'swApp.CloseDoc pathOut & Shortname & ".SLDDRW"
Set swApp = Application.SldWorks
Next Name
End Sub