Sub main()
Dim swApp As SldWorks.SldWorks
Dim SwModel As SldWorks.ModelDoc2
Dim SwFeat As SldWorks.Feature
Set swApp = Application.SldWorks
Set SwModel = swApp.ActiveDoc
'Debug.Print "File = " & swModel.GetPathName
Set SwFeat = SwModel.FirstFeature
Do While Not SwFeat Is Nothing
With SwFeat
If .GetTypeName = "Reference" Then
Debug.Print .Name, .GetTypeName
End If
Set SwFeat = SwFeat.GetNextFeature
End With
Loop
End Sub
code result is Part1-1
help me , need result is Part-1→ (a2) (a4) Configuration name
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("Part1-1@b", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Part.CompConfigProperties4 2, 0, True, True, "a4", False
Part.ClearSelection2 True
End Sub
**********************************
'Get Components in Drawing View Example (VB)
'This example shows how to get the components in a drawing view.
'----------------------------------------------
'
' Preconditions:
' (1) Drawing document is open.
' (2) Drawing view is selected.
'
' Postconditions: None
'
'----------------------------------------------
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim swRootDrawComp As SldWorks.DrawingComponent
Dim vDrawChildCompArr As Variant
Dim vDrawChildComp As Variant
Dim swDrawComp As SldWorks.DrawingComponent
Dim swComp As SldWorks.Component2
Dim swCompModel As SldWorks.ModelDoc2
Dim i As Long, ss
Dim bRet As Boolean
Dim rootConf As Configuration
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject5(1)
ss = swView.ReferencedConfiguration
Stop
Set swCompModel = swApp.GetOpenDocumentByName(swView.GetReferencedModelName)
Debug.Print swCompModel.GetTitle
Set rootConf = swCompModel.GetActiveConfiguration
Debug.Print rootConf.Name
Stop
Set swRootDrawComp = swView.RootDrawingComponent
Set swComp = swRootDrawComp.Component
Debug.Print swComp.Name
Debug.Print "File = " & swModel.GetPathName
Debug.Print " View = " & swView.Name
vDrawChildCompArr = swRootDrawComp.GetChildren
Set swDrawComp = vDrawChildCompArr(0)
Debug.Print swDrawComp.Name
Debug.Print swDrawComp.Component.Name
Stop
For Each vDrawChildComp In vDrawChildCompArr
Set swDrawComp = vDrawChildComp
' Returns NULL if underlying model is open in a different configuration
Set swComp = swDrawComp.Component
If Not Nothing Is swComp Then
' Returns NULL if drawing is lightweight
Set swCompModel = swComp.GetModelDoc
Debug.Print " "
Debug.Print " Component = " & swComp.Name2
Debug.Print " Configuration = " & swComp.ReferencedConfiguration
If Not Nothing Is swCompModel Then
Debug.Print " File = " & swCompModel.GetPathName
Debug.Print " "
End If
End If
Next
End Sub
'-----------------------------
Private Sub llll()
Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2
Set SwApp = Application.SldWorks
Set SwModel = SwApp.ActiveDoc
Debug.Print SwModel.GetTitle
Set swSelMgr = SwModel.SelectionManager
Dim SwComp As Component2, Str, SwFeat As Feature
'Set SwComp = swSelMgr.GetSelectedObjectsComponent(1)
'Debug.Print SwComp.Name2
Str = "Part1-1"
Set SwFeat = SwModel.FeatureByName(Str)
Debug.Print SwFeat.Name
Set SwComp = SwFeat.GetSpecificFeature
Debug.Print SwComp.GetModelDoc.GetTitle
Debug.Print SwComp.ReferencedConfiguration
Dim oSwModel As ModelDoc2
Set oSwModel = SwComp.GetModelDoc
oSwModel.ShowConfiguration2 SwComp.ReferencedConfiguration
Stop
End Sub
Sub main()
Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, SwDraw As DrawingDoc
''
Set SwApp = Application.SldWorks
Set SwModel = SwApp.ActiveDoc
Dim SwSelMgr As SelectionMgr
Set SwSelMgr = SwModel.SelectionManager
SwModel.Extension.SelectByID2 "Bill of Materials2", "BOMFEATURE", 0, 0, 0, False, 0, Nothing, 0
Dim SwBomFeat As BomFeature
Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)
Dim Visible, Names
Names = SwBomFeat.GetConfigurations(False, Visible)
Names(2) = ""
Names(1) = ""
Names(3) = ""
SwBomFeat.SetConfigurations True, Visible, Names
End Sub
SolidworksApi macros