5 Replies Latest reply on Aug 19, 2014 8:51 PM by Deepak Gupta

    ReplaceViewModel in SW 2014 API

    scott cleveland

      I have been trying to use example in API help file to see how this works. Although I can do what is below as a user in SW, when I try the example equivalent (below) the code does seen to work. Both returns for selection come back true (although I don't know why the block20/part portion is required to select the Assembly above it), but the final call to ReplaceModelView always comes back false (although new doc load event fires). Anyone try this yet, and have experience or comments? Thanks in Advance.

       

      ============================= API Example =========================================

       

       

        partial class SolidWorksMacro
          {

             
      ModelDoc2 Part;
             
      DrawingDoc draw;
             
      SelectionMgr selMgr;
             
      object[] vViews = new object[1];
             
      object[] vInstances = new object[1];

             
      bool boolstatus;

             
      public void Main()
              {
                  Part = (
      ModelDoc2)swApp.ActiveDoc;
                  draw = (
      DrawingDoc)Part;

                 
      // Select the view in which to replace the model
                  boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);
                  selMgr = (
      SelectionMgr)Part.SelectionManager;
                  vViews[0] = selMgr.GetSelectedObject6(1, -1);

                 
      // Select the instance of the model to replace
                  boolstatus = Part.Extension.SelectByID2("Assem20-3@Drawing View1/block20-1@assem20", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                  vInstances[0] = selMgr.GetSelectedObject6(1, -1);

                  boolstatus = draw.ReplaceViewModel(
      "C:\\Program Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\api\\bagel.sldprt", vViews, vInstances);

              }
       

          }
      }

        • Re: ReplaceViewModel in SW 2014 API
          Edgar Quintana

          I have the exact same issue. This macro is NOT working. It should replace block20.sldprt with bagel.sldprt, but is not doing anything. Hope somebody from SolidWorks API Support can review this.

           

          I even try to change "Assem20-3@Drawing View1/block20-1@assem20" to "Assem20-3@Drawing View1" to select assembly only but is not working either

          • Re: ReplaceViewModel in SW 2014 API
            Edgar Quintana

            I contacted apisupport@solidworks.com and they found an error on this example. They sent me a correction, i haven't tested yet, but i assume it should work now.

             

             

            /////////////////////////////////////

             

            Hi Edgar,

             

            Sorry about the issue with that help example. I opened SPR 818790 to modify the example by our documentation team. We will try to get that into the next service pack of SolidWorks 2014.

             

            Here is the code as it should be:

             

            Option Explicit

             

            Dim swApp As SldWorks.SldWorks

            Dim Part As SldWorks.ModelDoc2

            Dim draw As SldWorks.DrawingDoc

            Dim selMgr As SldWorks.SelectionMgr

            Dim vViews As Variant

            Dim viewArray(0) As Object

            Dim vInstances As Variant

            Dim InstanceArray(0) As Object

            Dim boolstatus As Boolean

            Dim drComp As SldWorks.DrawingComponent

             

             

             

            Sub main()

             

             

                Set swApp = Application.SldWorks

                Set Part = swApp.ActiveDoc

                Set draw = Part

               

                boolstatus = Part.ActivateView("Drawing View1")

               

                ' Select the view in which to replace the model

                boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)

                Set selMgr = Part.SelectionManager

                Set viewArray(0) = selMgr.GetSelectedObject6(1, -1)

                vViews = viewArray

               

                ' Select the instance of the model to replace

                boolstatus = Part.Extension.SelectByID2("Assem20-3@Drawing View1/block20-1@assem20", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

                Set InstanceArray(0) = selMgr.GetSelectedObject6(1, -1)

                Set drComp = InstanceArray(0)

                Set InstanceArray(0) = drComp.Component

                vInstances = InstanceArray

             

             

                boolstatus = draw.ReplaceViewModel("C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\api\bagel.sldprt", (vViews), (vInstances))

             

             

            End Sub

             

            I hope this helps.

             

            Regards,

             

            Mick Kozikowski

            Sr. API Support Engineer

            Dassault Systèmes SolidWorks Corp.