2 Replies Latest reply on Feb 10, 2016 7:56 AM by Erik Söderby

    Edit/replace reference entities for a point (API)

    Erik Söderby

      Hi,

       

      I'm trying to do - what I thought - a simple operation, but the struggle is real... I want to replace a reference in a point, from one spline (Spline1@3DSketch1) to another (Spline1@3DSketch2). I assume that swRefPtData.Selections is an array with reference entities and in my case I just have one entity, therefore I want to replace number 0. Works perfectly when I do it manually, so no issues with the CAD model, but nothing happens when I run the macro (I've re-written the code multiple times, can't figure out what's wrong). My code is based on this example (Ivana's answer): SolidWorks API - EditReferencePoint , but instead of changing the distance I want to change the reference entity. Does anyone have an idea?

       

      Here's my code:

       

      Sub main()

       

      Set swApp = _

      Application.SldWorks

       

      Set Part = swApp.ActiveDoc

      boolstatus = Part.Extension.SelectByID2("Point1", "DATUMPOINT", 0, 0, 0, False, 0, Nothing, 0)

      Set swSelMgr = Part.SelectionManager

      Set swFeature = swSelMgr.GetSelectedObject6(1, -1)

      Set swRefPt = swFeature.GetSpecificFeature2

      Set swRefPtData = swFeature.GetDefinition

      boolstatus = swRefPtData.AccessSelections(Part, Nothing)

      swRefPtData.Selections(0) = "Spline1@3DSketch2"

      swFeature.ModifyDefinition swRefPtData, Part, Nothing

      Part.EditRebuild3

       

      End Sub

       

      ReplacePointRef.PNG

       

      Thanks in advance!

        • Re: Edit/replace reference entities for a point (API)
          Artem Taturevych

          You need to pass the array of pointers instead of names. So something like this will work:

           

          swRefPtData.Selections = part.FeatureByName("3DSketch2").GetSpecificFeature().GetSketchSegments()

          Thanks,

          Artem

            • Re: Edit/replace reference entities for a point (API)
              Erik Söderby

              It worked in another way, by using ISetSelections. Here's the code:

               

              Sub main()

               

              Set swApp = _

              Application.SldWorks

              Set Part = swApp.ActiveDoc

              boolstatus = Part.Extension.SelectByID2("Spline1@3DSketch2", "EXTSKETCHSEGMENT", 5.21258681764607E-02, -0.288752179158223, -0.174936389034599, True, 0, Nothing, 0)

              Set swSelMgr = Part.SelectionManager

              Set swFeature2 = swSelMgr.GetSelectedObject6(1, -1)

              Part.ClearSelection2 True

              boolstatus = Part.Extension.SelectByID2("Point1", "DATUMPOINT", 0, 0, 0, False, 0, Nothing, 0)

              Set swSelMgr = Part.SelectionManager

              Set swFeature = swSelMgr.GetSelectedObject6(1, -1)

              Set swRefPt = swFeature.GetSpecificFeature2

              Set swRefPtData = swFeature.GetDefinition

              boolstatus = swRefPtData.AccessSelections(Part, Nothing)

              Longy = 1

              swRefPtData.ISetSelections Longy, swFeature2

              swFeature.ModifyDefinition swRefPtData, Part, Nothing

              Part.EditRebuild3

               

              However, I want to make the solution generic and therefore I need access to the array of reference entities. I'm trying with Debug.Print to figure out how to code, but how do I use that function when I have an array of objects? Let's say I have to reference entities in a point, "RefNo1" and "RefNo2" and I simply want to know their names. Something like this:

               

              For I=0 To (swRefPtData.GetSelectionsCount - 1)

              Debug.Print swRefPtData.Selections(I).GetName

              Next I

               

              Maybe it seems simple, but a debug function is crucial in my project.