Click here to Skip to main content
15,898,938 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a program with which I work through the directive #import. In it I create the new document and for the first page I place TextFrame which is created with parameters by default.
C++
HRESULT hr = CoInitialize(NULL);
_ApplicationPtr myApp("InDesign.Application");
 
DocumentPtr myDoc = myApp->ActiveDocument;
PagePtr myPage = myDoc->Pages->Item[1L];
TextFramePtr myTextFrame = myPage->TextFrames->Add(); // create frame on Page

Now I want to paint frame with one of predefined swatches. I have to give instance of Swatch to frame by FillColor, i.e.
C++
myTextFrame->FillColor = SomeSwatch->Name;

Got the collection:
C++
SwatchesPtr mySwatches = myApp->Swatches;

Got Swatch instance and Swatch Name:
C++
double SwatchCount = mySwatches->Count; //get quantity of elements
std::cout << SwatchCount << std::endl; // SwatchCount = 10
SwatchPtr mySwatch_1 = mySwatches->Item[1L];
_variant_t mySwatchName_1 = mySwatch->Name;

but here the second element isn't available:
C++
SwatchPtr mySwatch_1 = mySwatches->Item[2L]; // m_pInterface = 0x00000000

How get all elements?
Posted
Updated 17-Aug-15 22:56pm
v3
Comments
OriginalGriff 17-Aug-15 14:51pm    
Don't "bump" your question.
Add information by all means, but just bumping it to get it back to the top of the list is rude and unnecessary.
Nindzzya 17-Aug-15 16:52pm    
what information? I don't know
OriginalGriff 17-Aug-15 17:23pm    
Precisely.

for the first COM is not c++! There are no overloaded operators for COM. The only function to that is the ptr->Item(index). Usually for template smart pointers the element calls return Interface pointers i.e. itemptr = ptr->Item and your ptr->Item[1] will deliver itemptr+1 pointer increment not itemptr->Item(1) explicit call on the returned object.
regards.
 
Share this answer
 
the docs[^] are perplexing

count would appear to refer to elements in the swatch, length would appear to refer to number of swatches in the array
 
Share this answer
 
Comments
Nindzzya 18-Aug-15 1:36am    
so, what to do?
barneyman 18-Aug-15 1:47am    
have you tried 'length' ?
Nindzzya 18-Aug-15 3:11am    
there is only "Count". "lenght" is only in JS (for Indesing model)
barneyman 18-Aug-15 18:58pm    
unlikely - if it's in the typelib, it's in the api - it's a property tho, so it would be get_length

anyway, there are a number of other ways of iterating thru the swatches, have you tried them?
Nindzzya 18-Aug-15 3:17am    
Swatches->Count = 10 (in my question)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900