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
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)
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.
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
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
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:
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