×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Marking selected objects (API)

Marking selected objects (API)

Marking selected objects (API)

(OP)
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.

RE: Marking selected objects (API)

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)

RE: Marking selected objects (API)

(OP)
That explains the difficulty. Thanks.

RE: Marking selected objects (API)

(OP)
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.

RE: Marking selected objects (API)

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources