Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Marking selected objects (API)

Status
Not open for further replies.

razzendahcuben

Mechanical
Jan 10, 2009
79
0
0
US
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.
 
Replies continue below

Recommended for you

Selection marks are only valid while the object is selected. Marks do not persist after the item is deselected. Marking only functions do differentiate the various items selected for use in certain features.

If you are iterating through all the faces, just select them as you go rather than trying to "mark" them and then select them.

-handleman, CSWP (The new, easy test)
 
Actually, if you don't mind I have a followup question: what is the purpose of the CreateSelectData method and the ISelectData interface? I see it used in conjunction with marking a lot but looking over the examples I can't tell why it's used exactly. Thanks.
 
Insert the line
Set swSelMgr = swModel.SelectionManager
before your line
Set swSelData = swSelMgr.CreateSelectData

This will make the swSelMgr object available and should stop the error mentioned in the first post.

Look at FeatureManager::InsertMirrorFeature2 in the API help file to see an example of selection with marking.
 
Status
Not open for further replies.
Back
Top