Layout

Hello

I have a drawing model on which there is a front view of a flange. To show the front view, I need to select the bottom view of the flange.
I want, via a macro, to change the configuration of this view (it's the DN that changes).

The macro recorder gives me a code that works but when I run the macro the first time, it creates a configuration that ends with "-SM-FLAT-PATTERN" and I am forced to run it a second time for the configuration to change (it displays the configuration created on the first run).

I don't want to create new configurations and run the macro once.

Below is the code obtained:

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.267271785970659, 0.323684671386922, 0, False, 0, Nothing, 0)
boolstatus = Part.ChangeRefConfigurationOfFlatPatternView("O:\FJS flange type11B ASA300. SLDPRT", "DN040")
Part.ClearSelection2 True
End Sub

Thank you for your help.

 

Hello

What is the DN in the sentence "it's the DN that changes"?

Do you have to do it on many levels? Does the view still have the same name and so does the configuration?

Edit: in fact the DN corresponds to the different configurations

.PL

The DN corresponds to the diameter of the flange.

Yes, I try to automate this function because it has to be done on many levels by my colleagues and myself. The view still has the same name but the configuration changes. I attach an image of the configurations.
I want to change the configuration according to the value of the DN.

 

I found a code that works but asks which configuration I want to display but I would like it to be done automatically according to the value of the DN (I get this value in an Excel file):

  •  Sub ChangeRefConfig()  
  • Dim myApp As SldWorks.SldWorks  
  • Set myApp = Application.SldWorks  
  • Dim myDraw As DrawingDoc  
  • Set myDraw = myApp.ActiveDoc  
  • Dim myView As View  
  • Set myView = myDraw.ActiveDrawingView  
  • Dim myModel As ModelDoc2  
  • Set myModel = myView.ReferencedDocument  
  • Dim msg As String  
  • msg = "Please select config to change to for view " & myView.Name & vbCrLf  
  • For i = 0 TB UBound(myModel.GetConfigurationNames)  
  •     msg = msg & i + 1 & vbTab & myModel.GetConfigurationNames(i) & vbCrLf  
  • Next  
  • X = InputBox(msg, "Select config", 1)  
  • Dim config as string  
  •  config = myModel.GetConfigurationNames(X - 1)  
  • myView.ReferencedConfiguration = config  
  • myDraw.ForceRebuild  
  • MsgBox "Done"  
  • End Sub

configurations.png

Hello

in fact it  creates a sheet metal configuration  in unfolded version hence the name "-SM-FLAT-PATTERN" and to answer to PL the DN is the Nominal Diameter of the flange. Maybe the bridle and sheet metal and that's why she creates the flat-pattern version for you.

DN = Nominal diameter of a tube used in piping and therefore on a DN100, DN 200 flange, ....

 

@manu67,

 

I don't understand why it creates a sheet metal configuration because the part is created as a volume body...

I'm looking for the "ShowConfiguration2" function because this function works in 3D but not in drawing.

Below is the code for the 3D:

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.Extension.SelectByID2("DN300@Bride FJS type11B ASA300. SLDPRT", "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.ShowConfiguration2("DN050")
End Sub

 

Can someone help me adapt it to the drawing?

Look in the code of your question, the 4th line from the bottom you have:                                                                                                                                                                       "boolstatus = Part.ChangeRefConfigurationOfFlatPatternView("O:\FJS Bride " I think this part of the code should be modified or removed so that it no longer creates the flatpattern version

 

I've already tried to edit this line but I'm getting an error.

My research in the SolidWorks API help didn't move me forward either.

Try this one:

 

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.267271785970659, 0.323684671386922, 0, False, 0, Nothing, 0)
boolstatus = Part.ChangeRefConfigurationOfDefaultView("O:\FJS flange type11B ASA300. SLDPRT", "DN040")
Part.ClearSelection2 True
End Sub

This code should work:

Set swView = swDraw.IGetFirstView

Do
    Set swView = swView.GetNextView
    If swView Is Nothing Then Exit Do
    swView.ReferencedConfiguration =  ConfigName

Loop

 

Hi all

Thank you manu67 and .PL for your answers.

I tried both codes but neither worked.

For manu67's code, the error is in the line boolstatus = Part.ChangeRefConfigurationOfDefaultView("O:\FJS flange type11B ASA300. SLDPRT", "DN040". The error displayed is: "Runtime error '438': Property or method not handled by this object"

For the .PL code, the error is in the line Set swView = swDraw.IGetFirstView: "Runtime error '424':  object required. I tried to declare the ConfigName variable but the error is the same:

Dim ConfigName As String
ConfigName = "DN040"

swDraw avant, essaye ceci :

Set swDraw = swApp.ActiveDoc

Set swView = swDraw.IGetFirstView

Dim ConfigName As String
ConfigName = "DN040"

Do
    Set swView = swView.GetNextView

    If swView.GetName2 = "Drawing view1" then
    swView.ReferencedConfiguration =  ConfigName

    end if

Loop

The problem is still there.

Below is the code obtained:

Sub main()

Dim ConfigName As Variant

Dim swView As IView
Dim swDraw As IDrawingDoc
Set swDraw = swApp.ActiveDoc
Set swView = swDraw.IGetFirstView

Do
    Set swView = swView.GetNextView
    If swView Is Nothing Then Exit Do
    swView.ReferencedConfiguration = ConfigName

Loop

End Sub

stupid question sorry ;-(

Have you made a family of parts for your different bridles

and store in a specific personal files and biblio outside the SW library 

Why a personal library?

to be able to keep your libraries when you change SW version

@+ ;-)

gt22,

Yes, the different configurations are managed in a family of parts and they are saved in a specific folder outside of SolidWorks.

 

But that doesn't answer my question...

I found the solution to my problem. I put the code below:

Sub ChangeRefConfig()
Dim myApp As SldWorks.SldWorks
Set myApp = Application.SldWorks
Dim myDraw As DrawingDoc
Set myDraw = myApp.ActiveDoc
Dim myView As View
Set myView = myDraw.ActiveDrawingView
Dim myModel As ModelDoc2
Set myModel = myView.ReferencedDocument
Dim msg As String
myView.ReferencedConfiguration = "DN125"
myDraw.ForceRebuild
MsgBox "Done"
End Sub

In quotation marks, I type the name of the configuration I want and the macro changes the configuration in the drawing

Have a nice day