Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations The Obturator on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Configuration Macro

Status
Not open for further replies.

guppy6163

Mechanical
Feb 13, 2006
2
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.
 
Replies continue below

Recommended for you

I'd just create the first & call it a "SEED" file. Then use it to create the rest as you need them. Or maybe do a dozen every day... something like that. You may find that you really will never use all 600 versions.


Windows 2000 Professional / Microsoft Intellimouse Explorer
SolidWorks 2006 SP02.0 / SpaceBall 4000 FLX
Diet Coke with Lime / Dark Chocolate
Lava Lamp
www.Tate3d.com
 
If all your configs are in the same model, you can do this through API.

-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
 
This code I wrote generates the drawing but I cant get it to save and close it.

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
 
The following code is from a macro called SplitConfigs.swp.
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:
Option Explicit
    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

[cheers]
Helpful SW websites FAQ559-520
How to get answers to your SW questions FAQ559-1091
 
Try something like this:

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor