1 Reply Latest reply on Jul 25, 2015 11:03 AM by Ash Can

    Select object via its PID

    Ash Can

      I am having trouble selecting faces via their PID. I obtain the PIDs via the PID  collector, but now am stuck at selecting the returned objects from the PID.

      This is what I am trying right now with little success. My final goal is to make an intersection sketch using these selected faces. Right now, I use the Select by ID, but as expected am having issues getting the right faces.

      Dim pid1 as string
      pid1 = "xxxxxxxx <Long PID here>"
      
      Set Swobj = GetObjectFromString(swApp, Part, pid1)
           If Not Nothing Is Swobj Then
          Dim swSelMgr As SldWorks.SelectionMgr
              Dim seldat As SelectData
              Set swSelMgr = Part.SelectionManager
              Set seldat = swSelMgr.CreateSelectData
              boolstatus = swSelMgr.AddSelectionListObject(Swobj, seldat)
              Debug.Print boolstatus
          Else
              Debug.Print "  ModelDocExtension::GetObjectByPersistReference3 broken"
          End If
      Function GetObjectFromString(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, IDstring As String) As Object
          Dim swModExt                    As SldWorks.ModelDocExtension
          Dim ByteStream()                As Byte
          Dim vPIDarr                     As Variant
          Dim nRetval                     As Long
          Dim i                           As Long
          Set swModExt = swModel.Extension
          ReDim ByteStream(Len(IDstring) / 3 - 1)
          For i = 0 To Len(IDstring) - 3 Step 3
              ByteStream(i / 3) = CByte(Mid(IDstring, i + 1, 3))
          Next i
          vPIDarr = ByteStream
          Set GetObjectFromString = swModExt.GetObjectByPersistReference3((vPIDarr), nRetval)
          Debug.Assert swPersistReferencedObject_Ok = nRetval
          Debug.Assert Not GetObjectFromString Is Nothing
      End Function
      

       

      Is there something I am missing?

        • Re: Select object via its PID
          Ash Can

          So, this is how I manged to solve my issue for future reference!

          Set swObj = GetObjectFromString(swApp, swModel, sIDstring)
          Dim swEnt      As SldWorks.Entity
          Dim swSelData  As SldWorks.SelectData
          Dim status     As Boolean
          Set swEnt = swObj
          Debug.Print swEnt.GetType
          If swEnt.GetType = 2 Then ' It's a Face!
                status = swEnt.Select4(True, swSelData
          End