Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add a CustomTable to an IDW programatically using C++/COM, example anywhere?

1 REPLY 1
SOLVED
Reply
Message 1 of 2
oransen
388 Views, 1 Reply

Add a CustomTable to an IDW programatically using C++/COM, example anywhere?

I can't find any example of the topic. Added to that the fact that the CustomTables Add member uses SAFEARRAY and that CSafeArray in the SafeArrayUtil.h header tells me not to use CSafeArray any more...

 

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! This file is provided for backwards compatibility for existing clients only.
!!! New clients should probably consider using the more robust CComSafeArray wrapper provided in ATL instead.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

...is there an example using C++/COM of creatng a CustomTable in an IDW?

 

In this fragment I'm unsure of how to init the pColumnTitles and the TableWidths and TableHeights...

 

 

    SAFEARRAY* pColumnTitles = new SAFEARRAY ;

    CComPtr<CustomTables> pCustomTables = nullptr ;
    pSheet->get_CustomTables (&pCustomTables) ;

    CComPtr<Point2d> ptTable; // Create a 2d point
    theApp.GetTransGeomPtr()->CreatePoint2d(0.0,0.0,&ptTable);   

    const int ikNumCols = 3 ;
    const int ikNumRows = 6 ;
    
    CComPtr<CustomTable> pCustomTable = nullptr ;
    pCustomTables->Add (L"HOLES",ptTable,ikNumCols,ikNumRows,&pColumnTitles,TableWidths,TableHeights,varEmpty,&pCustomTable) ;

 

 

1 REPLY 1
Message 2 of 2
oransen
in reply to: oransen

I've managed to drag myself ahead a bit, as follows:

 

    wchar_t* ColNames[128] = {L"Column One",L"Column Two",L"Column Three"};

    SAFEARRAY* pstrColumns = CreateSafeStringArray(3, ColNames);

    CComPtr<CustomTables> pCustomTables = nullptr ;
    pSheet->get_CustomTables (&pCustomTables) ;

    CComPtr<Point2d> ptTable; // Create a 2d point
    theApp.GetTransGeomPtr()->CreatePoint2d(10.0,10.0,&ptTable);   

    const int ikNumCols = 3 ;
    const int ikNumRows = 6 ;

    /*double Widths[] = {10,10,10} ;
    SAFEARRAY* pWidths = CreateSafeDoubleArray(3, Widths) ;

    double Heights[] = {10,10,10} ;
    SAFEARRAY* pHeights = CreateSafeDoubleArray(3, Heights) ;*/

    CComVariant varEmpty ;   
    CComPtr<CustomTable> pCustomTable = nullptr ;
    pCustomTables->Add (CComBSTR(L"HOLES"),ptTable,ikNumCols,ikNumRows,&pstrColumns,
                        varEmpty, // contents?
                        varEmpty, // widths?
                        varEmpty, // heights?
                        varEmpty, // more info
                        &pCustomTable) ; // table returned
    
    SafeArrayDestroy (pstrColumns) ;
    
    return true ;

 

and

SAFEARRAY* CreateSafeStringArray(long nElements, TCHAR *elements[])
{
    SAFEARRAYBOUND saBound[1];

    saBound[0].cElements = nElements;
    saBound[0].lLbound = 0;

    SAFEARRAY *pSA = SafeArrayCreate(VT_BSTR, 1, saBound);

    if (pSA == NULL)
    {
        return NULL;
    }

    for (int ix = 0; ix < nElements; ix++)
    {
        BSTR pData = SysAllocString(elements[ix]);

        long rgIndicies[1];

        rgIndicies[0] = saBound[0].lLbound + ix;

        HRESULT hr = SafeArrayPutElement(pSA, rgIndicies, pData);
    }

    return pSA;
}

 

It works, but what do I need to pass for Contents, Widths and Heights in the call to Add?

 

And can any experts see any problems with my COM SAFEARRAY code?

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report