×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Configuration Macro

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.

RE: Configuration Macro

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

RE: Configuration Macro

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

RE: Configuration Macro

(OP)
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

RE: Configuration Macro

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

RE: Configuration Macro

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources