6 Replies Latest reply on Nov 14, 2012 10:54 AM by Sal Gerace

    IMathTransform get_IArrayData not populating values

    Sal Gerace

      I am trying to get the array data for a particular IMathTransform to get the 3x3 rotation matrix for the current sketch. Everything compiles and runs, however, when output the values returned by get_IArrayData, only the first element of the array gets populated.  It looks like this element is correct, but none of the other elements change; they just stay at thier initialization value. I've replicated the code in a VB macro and everything seems to function properly there. C++ code is included below.


      In addition, I have tried similar code for getting the array data for IMathPoint and IMathVector and see the same behavior.


      Any help would be greatly appreciated,



      // Initialize COM
      // Initialize SolidWorks COM object
      CComPtr<ISldWorks> swApp;
      HRESULT hres = swApp.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER);
      if (hres != S_OK) { return; }
      // Get active SolidWorks document
      CComPtr<IModelDoc2> swDoc;
      hres = swApp->get_IActiveDoc2(&swDoc);
      if (hres != S_OK) { return; }
      // Get SolidWorks part object from document
      CComPtr<IPartDoc> swPart;
      hres = swDoc->QueryInterface(__uuidof(IPartDoc), reinterpret_cast<void**>(&swPart));
      if (hres != S_OK) { return; }
      // Get SolidWorks model doc extension from document
      CComPtr<IModelDocExtension> swDocExt;
      hres = swDoc->get_Extension(&swDocExt);
      if (hres != S_OK) { return; }
      // Get SolidWorks sketch manager from document
      CComPtr<ISketchManager> swSketchMgr;
      hres = swDoc->get_SketchManager(&swSketchMgr);
      if (hres != S_OK) { return; }
      // Initialize rotation matrix
      double *rot = new double[16];
      std::fill_n(rot, 16, -1.0);
      // Get active sketch
      CComPtr<ISketch> swSketch;
      hres = swSketchMgr->get_ActiveSketch(&swSketch);
      if (hres != S_OK) { return; }
      // Get model to sketch transformation
      CComPtr<IMathTransform> swTransform;
      hres = swSketch->get_ModelToSketchTransform(&swTransform);
      if (hres != S_OK) { return; }
      // Get transformation array data
      for (int kk = 0; kk < 16; ++kk)
           std::cout << rot[kk] << "\r\n"; // Only kk = 0 has a value other than -1 (which is what was initialized)
      // Uninitialize COM