AnsweredAssumed Answered

Don't use SelectByID2,How to select Feature in Assemblies

Question asked by Yong Ning on Apr 5, 2012
Latest reply on May 13, 2015 by Simon Turner

360截图20120405.jpg

 

Now Select Feature method is

  boolstatus = swPart.Extension.SelectByID2(message, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

 

My code

 

 

Sub ls1()

 

  Dim nSelMark As Long, bRet As Boolean

 

  Dim swApp As SldWorks.SldWorks, swPart As SldWorks.ModelDoc2

  Dim swFeat As SldWorks.Feature

  Set swApp = Application.SldWorks

 

 

  Set swPart = swApp.ActiveDoc

  Dim Str, SwSelMgr As SldWorks.SelectionMgr

  Set SwSelMgr = swPart.SelectionManager()

  Str = "法兰"

    '------------------------------------------------------------------

    ' Get the first feature in part

    Set Feature = swPart.FirstFeature

  Dim sFileName, AsmName

  AsmName = Split(swPart.GetPathName, "\")

  AsmName = Split(AsmName(UBound(AsmName)), ".")(0)

  sFileName = "E:\MyWorkSummary\BE(J)S\HG20592+接管\法兰g.SLDPRT"

  ' While we have a valid feature

  While Not Feature Is Nothing

    ' Get the name of the feature

    FeatureName = Feature.Name

    message = FeatureName & "@" & AsmName

    If message Like "*" & Str & "*" Then

      boolstatus = swPart.Extension.SelectByID2(message, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

      Set swSelComp = SwSelMgr.GetSelectedObjectsComponent(1)

      bRet = swPart.ReplaceComponents(sFileName, "", True, True)

      Exit Sub

    End If

    ' Get the next feature

    Set Feature = Feature.GetNextFeature()

    ' Continue until the last feature is done

  Wend

  ''

End Sub

 

-------------------

 

My quest and code need is

  Don't use SelectByID2, How to select Feature in Assemblies 

Thanks

Outcomes