razzendahcuben
Mechanical
- Jan 10, 2009
- 79
Here is what I'd like to do: run through every face in the visible bodies. If a face is blue (B = 1) then mark it. Once all faces have been traversed, select all marked faces.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swBody As Variant
Dim i As Integer
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSelData As SldWorks.SelectData
Dim swFace As SldWorks.Face2
Dim swEntity As SldWorks.Entity
Dim matProps() As Double
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
Set swSelData = swSelMgr.CreateSelectData
'Make sure user has part open
If swModel.GetType <> swDocPART Then
MsgBox "Please open a part."
Exit Sub
End If
swBody = swPart.GetBodies2(0, True) 'put bodies in an array
For i = 0 To UBound(swBody)
Set swFace = swBody(i).GetFirstFace
Do While Not swFace Is Nothing
matProps = swFace.GetMaterialPropertyValues2( _
swInConfigurationOpts_e.swThisConfiguration, Nothing)
'If face is blue then mark
If matProps(2) = 1 Then
swEntity.Select4 True, swSelData
End If
Set swFace = swFace.GetNextFace
Loop
Next i
'select all blue faces
'???
End Sub
Right now I error at this line:
Set swSelData = swSelMgr.CreateSelectData
I know that typically you need to have an item already selected, but in this case I want to mark certain faces and then select those faces. I have really been fighting with the Selection Manager so if someone could please shed some light I'd be very appreciative.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swBody As Variant
Dim i As Integer
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSelData As SldWorks.SelectData
Dim swFace As SldWorks.Face2
Dim swEntity As SldWorks.Entity
Dim matProps() As Double
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
Set swSelData = swSelMgr.CreateSelectData
'Make sure user has part open
If swModel.GetType <> swDocPART Then
MsgBox "Please open a part."
Exit Sub
End If
swBody = swPart.GetBodies2(0, True) 'put bodies in an array
For i = 0 To UBound(swBody)
Set swFace = swBody(i).GetFirstFace
Do While Not swFace Is Nothing
matProps = swFace.GetMaterialPropertyValues2( _
swInConfigurationOpts_e.swThisConfiguration, Nothing)
'If face is blue then mark
If matProps(2) = 1 Then
swEntity.Select4 True, swSelData
End If
Set swFace = swFace.GetNextFace
Loop
Next i
'select all blue faces
'???
End Sub
Right now I error at this line:
Set swSelData = swSelMgr.CreateSelectData
I know that typically you need to have an item already selected, but in this case I want to mark certain faces and then select those faces. I have really been fighting with the Selection Manager so if someone could please shed some light I'd be very appreciative.