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,
Sal
SolidworksApi macros// Initialize COM
CoInitialize(NULL);
// 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
swTransform->get_IArrayData(rot);
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
CoUninitialize();
