How to replace document and specify configuration

I want at replacing a reference using ReplaceReferencedDocument to specify also the configuration. Is that possibile?

Thanks

SolidworksApi macros
Answers 9
JN
JN 2010-12-17 Best Answer

I just submitted a service request for the same thing you are asking.  I will let you know what I find out.

SP
SP 2010-12-19

Try if this method works....

1. Load the new document first

2. Change active configruation

3. Save the document

4. Replacedocument

Usually last active configuration is used.....

DG
DG 2010-12-20

Not sure about SolidWorks but DriveWorks should be able to change it.

JN
JN 2010-12-20

Sujan,

This works only if you have to replace the component in one assembly with one different configuration.  It does not work with multiple assemblies and multiple confiugrations.  I did a test case to confirm this.  Follow the example below.

Parts
Available Configuration(s)
Part1Default
Part2Default
Part3

1

2

Assembly1:

PartsConfiguration Used
Part1Default
Part2Default

Assembly2:

PartsConfiguration Used
Part1Default
Part2Default

Now replace part1 with part3 in Assembly1 with the active configurations being Part3, configuration 1 using SolidWorks Replace from right click menu. Done.  Assembly1 looks like this:

Assembly1:

PartsConfiguration Used
Part31
Part2Default

Next replace part1 with part3 in Assembly2 with active configuration being Part3, configuration 2 using SolidWorks Replace from right click menu.  Done.  Assembly2 looks like this:

Assembly2:

PartsConfiguration Used
Part32
Part2Default

However, when you check Assembly 1, it now looks like this:

Assembly1:

PartsConfiguration Used
Part32
Part2Default

Assembly2 is correct but now Assembly1 is wrong.  You see, replacing a part only replaces the .sldprt in the assembly.  It does not deal with configurations.  This a problem for me because I have this situation but on a larger scale.  I need to replace a part in about 50 assemblies but different configurations in each assembly.  I don't want to open the assemblies in SolidWorks because of other problems in the assemblies that I don't want to deal with. Also, automating this would be nice using the API.

JN
JN 2010-12-20

I emailed DriveWorks a few minutes ago asking about this.  I will post what I find here.

DG
DG 2010-12-20

I have tested that and it works fine. You need to just define the rule for configuration 

JN
JN 2010-12-20

What level of DriveWorks allows this?  Can I do it with the Express version?

DG
DG 2010-12-20

Solo for minimum.. Not sure if it can work with Xpress.

SP
SP 2010-12-20

I may be wrong but you want to look these...

Assembly can have reference to a part file. The part may have multiple instances in the assembly. Each instance of the part can be a different configuration. Whic configuration is used when you replace reference and do not handle all instances of the part

ReplaceReference allows you to swap file.....not instances

this is what I have done if it helps...

This using SolidWorks API Call....you can automate so that the assembly opens itself, replace components, close

Do While (Not line Is Nothing)
                        Dim configlists As Object
                        configlists = Split(line, ",")
                        If configlists(0) = exname Then ' this is the existing config name

                            Dim selmg As SelectionMgr
                            Dim ext As IModelDocExtension
                            ext = ParModel.Extension
                            selmg = ParModel.SelectionManager


                            If ext.SelectByID2(swChildComp.Name2 & "@" & asmtitle, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) Then
                                MsgBox("Existing Component " & swChildComp.Name2 & " and its config " & exname & " is replaced by" & vbCrLf & "New component " & ReplacementFile & " configuration " & configlists(1))
                                Try

                                    swasm.ReplaceComponents(localworking & "\" & ReplacementFile, configlists(1), False, True)
                                Catch ex As Exception
                                    MsgBox(ex.Message)
                                End Try
                                ParModel.ClearSelection2(True)
                            End If
                            Exit Do
                        End If

                        ' Read in the next line.
                        line = r.ReadLine

                    Loop

Following is using SW Document manager (does not take care of configurations....just file reference)


For Each OldDocName In OldDocNames
            ' check with items in listbox 1
            Dim olddoccounter As Long
            For olddoccounter = 0 To Me.ListBox1.Items.Count - 1
                If UCase(OldDocName) = UCase(Me.ListBox1.Items.Item(olddoccounter).ToString) Then
                    swDoc.ReplaceReference(OldDocName, Me.ListBox2.Items.Item(olddoccounter))
                    Exit For
                End If
            Next
Next