Ronan
2005-10-20 20:49:39 UTC
I try to access all sketches of an assembly in a drawing to then unhide
them to enable the "Insert model items" to automatically import the
sketches dimensions in the drawings.
My first step is to test the way to access those sketches but I can't.
I'm stopped at the RootDrawingComponent level. I don't manage to go
further. Impossible to edit the first feature.
Here one of my test codes to explain where I would like to go. Any
suggestion?
Thanks,
Ronan
Solidworks 2005 SP5
Sub ParFonction()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim swRootDrawComp As SldWorks.DrawingComponent
Dim swComp As SldWorks.Component2
Dim swFeat As SldWorks.Feature
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
' Make sure that the active document is a drawing
'If swModel.GetType <> swDocDRAWING Then
If swModel.GetType <> 3 Then
Msg = "Only Allowed on Drawings" ' Define message
Style = vbOKOnly ' OK Button only
Title = "Error" ' Define title
Call MsgBox(Msg, Style, Title) ' Display error message
Exit Sub ' Exit this program
End If
Set swSheet = swModel.GetCurrentSheet
Set swView = swModel.GetFirstView
Debug.Print " "
Debug.Print "***********************"
Debug.Print "Doc =" & swModel.GetPathName
Debug.Print "Sheet =" & swSheet.GetName
While Not swView Is Nothing
Debug.Print " "
Debug.Print "View = " & swView.GetName2 & " [" & swView.Type & "]"
Debug.Print "View = " & swView.Name
Debug.Print "Ref = " & swView.GetReferencedModelName
Set swRootDrawComp = swView.RootDrawingComponent
If Not swRootDrawComp Is Nothing Then
Debug.Print "RtComp = " & swRootDrawComp.Name
Set swComp = swRootDrawComp.Component
Set swFeat = swComp.FirstFeature
Do While Not swFeat Is Nothing
Debug.Print swFeat.Name
Set swFeat = swFeat.GetNextFeature
Loop
End If
Set swView = swView.GetNextView
Wend
End Sub
them to enable the "Insert model items" to automatically import the
sketches dimensions in the drawings.
My first step is to test the way to access those sketches but I can't.
I'm stopped at the RootDrawingComponent level. I don't manage to go
further. Impossible to edit the first feature.
Here one of my test codes to explain where I would like to go. Any
suggestion?
Thanks,
Ronan
Solidworks 2005 SP5
Sub ParFonction()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim swRootDrawComp As SldWorks.DrawingComponent
Dim swComp As SldWorks.Component2
Dim swFeat As SldWorks.Feature
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
' Make sure that the active document is a drawing
'If swModel.GetType <> swDocDRAWING Then
If swModel.GetType <> 3 Then
Msg = "Only Allowed on Drawings" ' Define message
Style = vbOKOnly ' OK Button only
Title = "Error" ' Define title
Call MsgBox(Msg, Style, Title) ' Display error message
Exit Sub ' Exit this program
End If
Set swSheet = swModel.GetCurrentSheet
Set swView = swModel.GetFirstView
Debug.Print " "
Debug.Print "***********************"
Debug.Print "Doc =" & swModel.GetPathName
Debug.Print "Sheet =" & swSheet.GetName
While Not swView Is Nothing
Debug.Print " "
Debug.Print "View = " & swView.GetName2 & " [" & swView.Type & "]"
Debug.Print "View = " & swView.Name
Debug.Print "Ref = " & swView.GetReferencedModelName
Set swRootDrawComp = swView.RootDrawingComponent
If Not swRootDrawComp Is Nothing Then
Debug.Print "RtComp = " & swRootDrawComp.Name
Set swComp = swRootDrawComp.Component
Set swFeat = swComp.FirstFeature
Do While Not swFeat Is Nothing
Debug.Print swFeat.Name
Set swFeat = swFeat.GetNextFeature
Loop
End If
Set swView = swView.GetNextView
Wend
End Sub