Hi I'm trying to make a macro that will automatically change the configuration of a part in a drawing view to the next configuration in the design tree.

 

 

confName = vConfs(i)

        Dim y As Integer

Dim Modelsw                     As SldWorks.ModelDoc2

Set Modelsw = swApp.ActiveDoc

Set swDraw = Modelsw

    Dim vSheets As Variant

    vSheets = swDraw.GetViews

    ConfigNames = ModelDoc2.GetConfigurationNames()

     numConfigs = ModelDoc2.GetConfigurationCount()    

  For v = 0 To (numConfigs - 1)                    

 

    For y = 0 To UBound(vSheets)

       

        Dim j As Integer

        Dim vViews As Variant

       

        vViews = vSheets(y)

       

        For j = 0 To UBound(vViews)

           

            Set swView = vViews(j)

            swView.ReferencedConfiguration = confName

        Next

       

    Next

        swModel.ForceRebuild3 False

 

 

This is as far as I've gotten.

 

 

Can anyone give me some guidance?


Categories: API∕Macros

Comments
Last comment By: Deepak Gupta   Fri, 13 Oct 2017 14:05:33 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

Hi Charles,

 

Lets try with below lines.

 

Dim swapp As SldWorks.SldWorks

Dim swmodel As SldWorks.ModelDoc2

Dim swdraw As SldWorks.DrawingDoc

Dim Vconfignames As Variant

Dim swview As SldWorks.View

Dim swcompmodel As SldWorks.ModelDoc2

Dim i As Integer

Dim Configname As String

Sub main()

Set swapp = Application.SldWorks

Set swmodel = swapp.ActiveDoc

Set swdraw = swmodel

Set swview = swdraw.GetFirstView

Set swview = swview.GetNextView

Set swcompmodel = swview.ReferencedDocument

Vconfignames = swcompmodel.GetConfigurationNames

Configname = swview.ReferencedConfiguration

For i = 0 To UBound(Vconfignames)

If swview.ReferencedConfiguration = Vconfignames(i) Then

While Not swview Is Nothing

        Debug.Print "    " & swview.GetName2 & " [" & swview.Type & "]"

        swview.ReferencedConfiguration = Vconfignames(i + 1)

        Set swview = swview.GetNextView

    Wend

    Exit For

End If

Next

End Sub

 

Thanks

Manikandan

By: Manikandan Babu  Thu, 12 Oct 2017 07:00:17 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

Charles, I had not been able to spend any time on the macro but can you share a sample drawing and model file? I need to see if you've one view per sheet or multiple?

By: Deepak Gupta  Thu, 12 Oct 2017 07:09:16 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

Manikandan Babu

Thank you I will give it a try.

By: Charles Leonard  Thu, 12 Oct 2017 12:55:08 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

Deepak Gupta I've attached a part and and drawing file to show what I'm trying to accomplish. Thank you

By: Charles Leonard  Thu, 12 Oct 2017 13:01:10 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

Thank you that worked

By: Charles Leonard  Thu, 12 Oct 2017 13:29:50 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

Manikandan

 

I'm having an issue with the script

I am getting a Subscript out of range errorDebug.JPG

 

On this part.

 

hi debug.JPG

 

Do you or anyone else have any suggestions?

The issue seems to be when it gets to the last config it gets suck. Deepak Gupta

By: Charles Leonard  Thu, 12 Oct 2017 19:58:10 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

I'm also stuck with same issue

By: Deepak Gupta  Fri, 13 Oct 2017 04:48:01 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

Hi Charles,

 

Lets try with code.. if it is last configuration, it will skip.

 

Dim swapp As SldWorks.SldWorks

Dim swmodel As SldWorks.ModelDoc2

Dim swdraw As SldWorks.DrawingDoc

Dim Vconfignames As Variant

Dim swview As SldWorks.View

Dim swcompmodel As SldWorks.ModelDoc2

Dim i As Integer

Dim Configname As String

Sub main()

Set swapp = Application.SldWorks

Set swmodel = swapp.ActiveDoc

Set swdraw = swmodel

Set swview = swdraw.GetFirstView

Set swview = swview.GetNextView

Set swcompmodel = swview.ReferencedDocument

Vconfignames = swcompmodel.GetConfigurationNames

Configname = swview.ReferencedConfiguration

For i = 0 To UBound(Vconfignames)

If Configname = Vconfignames(UBound(Vconfignames)) Then

Exit For

ElseIf swview.ReferencedConfiguration = Vconfignames(i) Then

While Not swview Is Nothing

        Debug.Print "    " & swview.GetName2 & " [" & swview.Type & "]"

        swview.ReferencedConfiguration = Vconfignames(i + 1)

        Set swview = swview.GetNextView

    Wend

    Exit For

End If

Next

End Sub

 

Thanks

Manikandan

By: Manikandan Babu  Fri, 13 Oct 2017 12:21:25 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

Thank you Manikandan

 

I actually fixed it with this

 

ConfigName = swView.ReferencedConfiguration

For x = 0 To (UBound(Vconfignames) - 1)

If swView.ReferencedConfiguration = Vconfignames(x) Then

While Not swView Is Nothing

 

Thank you for all of your help

By: Charles Leonard  Fri, 13 Oct 2017 13:38:10 GMT
Re: automatically change the configuration of a part in a drawing view to the next configuration in the design tree

I've managed it work in case first sheet has first config but doesn't work for random config on sheet 1.

By: Deepak Gupta  Fri, 13 Oct 2017 14:05:33 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.