Ccomqiptr Assignment Sheet

By Wayne Brill

There is a VBA example that uses the PDF translator in the Inventor API help file. Here is an example in C++. You can  replace the code in the SimpleExe SDK example to test this code.  (At this location on my system)  

"C:\Users\Public\Documents\Autodesk\Inventor 2014\SDK\DeveloperTools\Samples\VC++\Standalone Applications\Inventor\SimpleExe"

It creates a pdf for each sheet and one PDF with all the sheets.

<code_begin>
// SimpleExe.cpp : Defines the entry point for the console application.

#include "stdafx.h"

// Forward declarations
static HRESULT PrintPDF();

// Main. Note that all COM related activity (including the automatic 'release' within smart
// pointers) MUST take place BEFORE CoUnitialize(). Hence the function 'block' within which
// the smart-pointers construct and destruct (and AddRef and Release) keeping the CoUnitialize
// safely out of the way.

int _tmain(int argc, _TCHAR* argv[])
{
HRESULT Result = NOERROR;

Result = CoInitialize (NULL);

if (SUCCEEDED(Result))
Result = PrintPDF();

CoUninitialize();

return 0;
}


static HRESULT PrintPDF()
{
HRESULT Result = NOERROR;

CLSID InvAppClsid;
Result = CLSIDFromProgID (L"Inventor.Application", &InvAppClsid);
if (FAILED(Result)) return Result;

CComPtr<IUnknown> pInvAppUnk;
Result = ::GetActiveObject (InvAppClsid, NULL, &pInvAppUnk);
if (FAILED (Result))
{
_tprintf_s (_T("*** Could not get hold of an active Inventor application ***\n"));
return Result;
}

CComPtr<Application> pInvApp;
Result = pInvAppUnk->QueryInterface (__uuidof(Application), (void **) &pInvApp);
if (FAILED(Result)) return Result;

CComPtr<Document> pDoc;
Result = pInvApp->get_ActiveDocument(&pDoc);
if (FAILED(Result)) return Result;

CComQIPtr<DrawingDocument> pDrawDoc = pDoc;

// Get the PDF translator Add-In.
CComPtr<ApplicationAddIns> pAddIns;
Result = pInvApp->get_ApplicationAddIns(&pAddIns);

CComPtr<ApplicationAddIn> pAddIn;
Result = pAddIns->get_ItemById(_bstr_t("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}"), &pAddIn);
 
CComQIPtr<TranslatorAddIn> pTransAddIn = pAddIn;

CComPtr<TransientObjects> pTransObjects;
Result = pInvApp->get_TransientObjects(&pTransObjects);

// Create the context.
CComPtr<TranslationContext> pContext;
Result = pTransObjects->CreateTranslationContext(&pContext);
Result = pContext->put_Type(kFileBrowseIOMechanism);

// Create a NameValueMap object
CComPtr<NameValueMap> pOptions;
Result = pTransObjects->CreateNameValueMap(&pOptions);

// Create a DataMedium object
CComPtr<DataMedium> pDataMedium;
Result = pTransObjects->CreateDataMedium(&pDataMedium);

// Check whether the translator has 'SaveCopyAs' options
VARIANT_BOOL hasOptions;
Result = pTransAddIn->get_HasSaveCopyAsOptions(pDrawDoc, pContext, pOptions, &hasOptions);
if (Result == S_OK)
{
CComPtr<Sheets>pSheets;
Result = pDrawDoc->get_Sheets(&pSheets);

long sheetCount;
Result = pSheets->get_Count(&sheetCount);

if (true)
{
for( int i=1; i<=sheetCount; ++i)
{
Result = pOptions->put_Value(_bstr_t("Vector_Resolution"), CComVariant(400));

Result = pOptions->put_Value(_bstr_t("Sheet_Range"), CComVariant(kPrintSheetRange));
Result = pOptions->put_Value(_bstr_t("Custom_Begin_Sheet"), CComVariant(i));
Result = pOptions->put_Value(_bstr_t("Custom_End_Sheet"), CComVariant(i));

//Set the destination file name
char filename[100];
sprintf_s(filename, "c:\\temp\\test%d.pdf", i);

pDataMedium->put_FileName(_bstr_t(filename));

// Publish document.
Result = pTransAddIn->SaveCopyAs(pDrawDoc, pContext, pOptions, pDataMedium);

}
  
Result = pOptions->put_Value(_bstr_t("Sheet_Range"), CComVariant(kPrintAllSheets));
Result = pOptions->put_Value(_bstr_t("Custom_Begin_Sheet"), CComVariant(1));
Result = pOptions->put_Value(_bstr_t("Custom_End_Sheet"), CComVariant(sheetCount));
pDataMedium->put_FileName(_bstr_t("c:\\temp\\testPDF_all_Sheets_in_one.pdf"));

// Publish document.
Result = pTransAddIn->SaveCopyAs(pDrawDoc, pContext, pOptions, pDataMedium);
}
else
{
Result = pOptions->put_Value(_bstr_t("Vector_Resolution"), CComVariant(400));
Result = pOptions->put_Value(_bstr_t("Sheet_Range"), CComVariant(kPrintSheetRange));
Result = pOptions->put_Value(_bstr_t("Custom_Begin_Sheet"), CComVariant(1));
Result = pOptions->put_Value(_bstr_t("Custom_End_Sheet"), CComVariant(sheetCount));
 
//Set the destination file name
char filename[500];
sprintf_s(filename, "c:\\temp\\testAll.pdf");

pDataMedium->put_FileName(_bstr_t(filename));

// Publish document.
Result = pTransAddIn->SaveCopyAs(pDrawDoc, pContext, pOptions, pDataMedium);
}
}

return Result;
}

<code_end>

CComVariant Class

This class wraps the type, providing a member indicating the type of data stored.

Syntax

Members

Public Constructors

Public Methods

Public Operators

CComVariant::operator <Indicates whether the object is less than the specified VARIANT.
CComVariant::operator >Indicates whether the object is greater than the specified VARIANT.
operator !=Indicates whether the object does not equal the specified VARIANT.
operator =Assigns a value to the object.
operator ==Indicates whether the object equals the specified VARIANT.

wraps the type, which consists of a union and a member indicating the type of the data stored in the union. VARIANTs are typically used in Automation.

derives from the VARIANT type so it can be used wherever a VARIANT can be used. You can, for example, use the V_VT macro to extract the type of a or you can access the vt member directly just as you can with a VARIANT.

Inheritance Hierarchy

Requirements

Header: atlcomcli.h

CComVariant::Attach

Safely clears the current contents of the object, copies the contents of into this object, then sets the variant type of to .

Parameters


[in] Points to the VARIANT to be attached to the object.

Return Value

A standard value.

Ownership of the data held by is transferred to the object.

CComVariant::CComVariant

Each constructor handles the safe initialization of the object by calling the Win32 function or by setting the object's value and type according to the parameters passed.

Parameters

varSrc
[in] The or used to initialize the object. The contents of the source variant are copied to the destination without conversion.


[in] The character string used to initialize the object. You can pass a zero-terminated wide (Unicode) character string to the LPCOLESTR version of the constructor or an ANSI string to the version. In either case the string is converted to a Unicode allocated using SysAllocString. The type of the object will be .


[in] The used to initialize the object. The argument is converted to a VARIANT_BOOL before being stored. The type of the object will be .


[in] The , BYTE, short, long, LONGLONG, ULONGLONG, unsigned short, , or used to initialize the object. The type of the object will be , , , , VT_I8, VT_UI8, VT_UI2, VT_UI4, or VT_UI4, respectively.


[in] The type of the variant. When the first parameter is , valid types are and VT_INT. When the first parameter is long, valid types are and . When the first parameter is double, valid types are and . When the first parameter is , valid types are VT_UI4 and VT_UINT.


[in] The float used to initialize the object. The type of the object will be .


[in] The double used to initialize the object. The type of the object will be .


[in] The CY used to initialize the object. The type of the object will be .


[in] The or IUnknown pointer used to initialize the object. will be called on the interface pointer. The type of the object will be VT_DISPATCH or VT_UNKNOWN, respectively.

Or, the SAFERRAY pointer used to initialize the object. A copy of the SAFEARRAY is stored in the object. The type of the object will be a combination of the original type of the SAFEARRAY and VT_ARRAY.


[in] The used to initialize the object. The type of the object will be VT_I1.


[in] The BSTR used to initialize the object. The type of the object will be .

The destructor manages cleanup by calling CComVariant::Clear.

CComVariant::~CComVariant

The destructor.

This method manages cleanup by calling CComVariant::Clear.

CComVariant::ChangeType

Converts the object to a new type.

Parameters


[in] The new type for the object.


[in] A pointer to the whose value will be converted to the new type. The default value is NULL, meaning the object will be converted in place.

Return Value

A standard value.

If you pass a value for , will use this VARIANT as the source for the conversion. Otherwise, the object will be the source.

CComVariant::Clear

Clears the object by calling the Win32 function.

Return Value

A standard value.

The destructor automatically calls Clear.

CComVariant::Copy

Frees the object and then assigns it a copy of the specified VARIANT.

Parameters


[in] A pointer to the VARIANT to be copied.

Return Value

A standard value.

CComVariant::CopyTo

Copies the contents of the object.

Parameters

pstrDest
Points to a that will receive a copy of the contents of the object.

Return Value

A standard value.

The CComVariant object must be of type .

CComVariant::Detach

Detaches the underlying VARIANT from the object and sets the object's type to .

Parameters


[out] Returns the underlying value of the object.

Return Value

A standard value.

Note that the contents of the referenced by will automatically be cleared before being assigned the value and type of the calling CComVariant object.

CComVariant::GetSize

For simple-fixed size s, this method returns the the underlying data type plus .

Return Value

The size in bytes of the current contents of the object.

If the contains an interface pointer, queries for or . If successful, the return value is the low-order 32 bits of the value returned by plus the a and . If the interface pointer is , returns the a plus . If the total size is larger than , returns which indicates an error.

In all other cases, a temporary of type is coerced from the current . The length of this is calculated as the size of the length of the string plus the length of the string itself plus the size of the null character plus . If the cannot be coerced to a of type , returns .

The size returned by this method matches the number of bytes used by CComVariant::WriteToStream under successful conditions.

CComVariant::operator =

Assigns a value and corresponding type to the object.

Parameters

varSrc
[in] The or VARIANT to be assigned to the object. The contents of the source variant are copied to the destination without conversion.


[in] The BSTR to be assigned to the object. The type of the object will be .


[in] The character string to be assigned to the object. You can pass a zero-terminated wide (Unicode) character string to the LPCOLESTR version of the operator or an ANSI string to the version. In either case, the string is converted to a Unicode allocated using SysAllocString. The type of the object will be .


[in] The to be assigned to the object. The argument is converted to a VARIANT_BOOL before being stored. The type of the object will be .


[in] The , BYTE, short, long, LONGLONG, ULONGLONG, unsigned short, , or to be assigned to the object. The type of the object will be , , , , VT_I8, VT_UI8, VT_UI2, VT_UI4, or VT_UI4, respectively.


[in] The float to be assigned to the object. The type of the object will be .


[in] The double to be assigned to the object. The type of the object will be .


[in] The CY to be assigned to the object. The type of the object will be .


[in] The or IUnknown pointer to be assigned to the object. will be called on the interface pointer. The type of the object will be VT_DISPATCH or VT_UNKNOWN, respectively.

Or, a SAFEARRAY pointer to be assigned to the object. A copy of the SAFEARRAY is stored in the object. The type of the object will be a combination of the original type of the SAFEARRAY and VT_ARRAY.


[in] The char to be assigned to the object. The type of the object will be VT_I1.

CComVariant::operator ==

Indicates whether the object equals the specified VARIANT.

Returns true if the value and type of varSrc are equal to the value and type, respectively, of the object. Otherwise, false. The operator uses the user's default locale to perform the comparison.

The operator compares only the value of the variant types. It compares strings, integers, and floating points, but not arrays or records.

CComVariant::operator !=

Indicates whether the object does not equal the specified VARIANT.

Returns true if either the value or type of varSrc is not equal to the value or type, respectively, of the object. Otherwise, false. The operator uses the user's default locale to perform the comparison.

The operator compares only the value of the variant types. It compares strings, integers, and floating points, but not arrays or records.

CComVariant::operator <

Indicates whether the object is less than the specified VARIANT.

Returns true if the value of the object is less than the value of varSrc. Otherwise, false. The operator uses the user's default locale to perform the comparison.

CComVariant::operator >

Indicates whether the object is greater than the specified VARIANT.

Returns true if the value of the object is greater than the value of varSrc. Otherwise, false. The operator uses the user's default locale to perform the comparison.

CComVariant::ReadFromStream

Sets the underlying VARIANT to the VARIANT contained in the specified stream.

Parameters


[in] A pointer to the IStream interface on the stream containing the data.

Return Value

A standard value.

ReadToStream requires a previous call to WriteToStream.

CComVariant::SetByRef

Initializes the object and sets the vt member to VT_BYREF.

Parameters


The type of VARIANT, for example, , , or .

pT
The pointer used to initialize the object.

is a function template that initializes the object to the pointer pT and sets the vt member to VT_BYREF. For example:

CComVariant::WriteToStream

Saves the underlying VARIANT to a stream.

Parameters


[in] A pointer to the IStream interface on a stream.

Return Value

A standard value.

See Also

Class Overview

0 thoughts on “Ccomqiptr Assignment Sheet

Leave a Reply

Your email address will not be published. Required fields are marked *