HI Ronan I wrote the program and i am posting it here since found that a little tricky put the content in a nacro and you can run it
'================================================ Dim swApp As SldWorks.SldWorks Dim oModeldoc As SldWorks.ModelDoc2 Dim oDrwDoc As DrawingDoc Dim oView As SldWorks.View Dim bStatus As Boolean Dim oDrwComp As DrawingComponent Dim oSwSheet As SldWorks.Sheet Dim m_StrViewName As String
Sub main() Dim i As Integer Dim oRootCompDoc As ModelDoc2 Dim strConfigName As String Dim oConfig As Configuration Dim strFullSketcName As String Dim lerr As Long Dim vChildren As Variant Dim oFeature As SldWorks.Feature Dim oComp As Component2
Set swApp = Application.SldWorks Set oModeldoc = swApp.ActiveDoc ' getting the active doc 'testing for drawing If oModeldoc.GetType swDocDRAWING Then swApp.SendMsgToUser ("Document is not drawing") Exit Sub End If
Set oDrwDoc = oModeldoc ' just for convinence to enable autocomplete Set oSwSheet = oDrwDoc.GetCurrentSheet 'getting the current sheet If oSwSheet Is Nothing Then swApp.SendMsgToUser ("cannot get current sheet") Exit Sub End If
Set oView = oDrwDoc.GetFirstView 'first view is the drwing sheet sketch so we have to move get the next for real view Set oView = oView.GetNextView ' getting the first view Do While Not oView Is Nothing ' make sure you get a view m_StrViewName = oView.Name ' getting the view name Debug.Print "View Name: " & m_StrViewName ' for debuging Set oDrwComp = oView.RootDrawingComponent ' getting the root drawing component Set oRootCompDoc = oView.ReferencedDocument ' getting the drawing component document since the ' root component is not exactly an assembly component ' there for when we get its component we cannot get access to the first feature ' we use as workaround by going to the specific configuration of the model and getting the ' the sketches names from there strConfigName = oView.ReferencedConfiguration ' the current configuration of the root component Set oRootCompDoc = swApp.ActivateDoc2(oRootCompDoc.GetPathName, True, lerr) ' activating the reference document
bStatus = oRootCompDoc.ShowConfiguration2(strConfigName) 'activating the configuration Set oFeature = oRootCompDoc.FirstFeature ' getting the first fieatur of the document Do While Not oFeature Is Nothing ' steping through the feature tree of root doc If oFeature.GetTypeName = "ProfileFeature" Then ' checking for sketch strFullSketcName = getSketchFullName(oView.Name, oDrwComp.Name, oFeature.Name) ' getting the sketch name for selectbyis bStatus = oModeldoc.Extension.SelectByID2(strFullSketcName, "SKETCH", 0, 0, 0, False, 0, Nothing, 0) ' selecting the sketch in drawing If bStatus Then oModeldoc.BlankSketch ' blanking the sketch End If Set oFeature = oFeature.GetNextFeature Loop Debug.Print "Drawing RootComp Name " & oDrwComp.Name If oDrwComp.GetChildrenCount > 0 Then Call traverse_drwcomponent(oDrwComp) ' travesing the children components Set oView = oView.GetNextView Loop
End Sub
Function getSketchFullName(strViewName As String, strComponentName As String, strSketchName As String) As String 'this function construct the name of the sketch for selection in drawing Dim vStr As Variant Dim i As Long Dim tmpStr As String Dim StrParentName As String
vStr = Split(strComponentName, "/") tmpStr = strSketchName & "@" & vStr(0) & "@" & strViewName For i = 0 To UBound(vStr) - 1 StrParentName = Left(vStr(i), InStrRev(vStr(i), "-") - 1) tmpStr = tmpStr & "/" & vStr(i + 1) & "@" & StrParentName Next i getSketchFullName = tmpStr Debug.Print getSketchFullName End Function
Sub traverse_drwcomponent(oDrcmp As DrawingComponent) Dim vChildren As Variant Dim oComp As Component2 Dim tmpDrcmp As DrawingComponent Dim i As Long Call traverse_Features(oDrcmp) If oDrcmp.GetChildrenCount > 0 Then vChildren = oDrcmp.GetChildren For i = 0 To oDrcmp.GetChildrenCount - 1 Debug.Print vChildren(i).Name Set tmpDrcmp = vChildren(i) Call traverse_drwcomponent(tmpDrcmp) Next i End If End Sub
Sub traverse_Features(oDrcmp As DrawingComponent) 'this program traverse feature of child component and blank the sketch in the drawing view Dim i As Long Dim oFeature As Feature Dim oComp As Component2 Dim strSketchFullName As String
Set oComp = oDrcmp.Component Set oFeature = oComp.FirstFeature Do While Not oFeature Is Nothing If oFeature.GetTypeName = "ProfileFeature" Then strSketchFullName = getSketchFullName(oView.Name, oDrcmp.Name, oFeature.Name) bStatus = oModeldoc.Extension.SelectByID2(strSketchFullName, "SKETCH", 0, 0, 0, False, 0, Nothing, 0) If bStatus Then oModeldoc.BlankSketch End If Set oFeature = oFeature.GetNextFeature Loop End Sub '==================================================================== regards dudi peer