Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Im- and export of InDesign Snippet (*.inds)

New Here ,
Jan 13, 2009 Jan 13, 2009
Hello,

I need to export page items as InDesign snippets (*.inds), and reimport these snippets in other documents.
Could anyone point me to the right direction, I couldn't find anything about it in the sdksamples or in this forum.

Thanks in advance,
Detlef
TOPICS
SDK
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 13, 2009 Jan 13, 2009
Here's something that works for me...<br />Import from Snippet<br /><br /> const IDFile snippetFile;<br /> InterfacePtr<IPMStream> stream(StreamUtil::CreateFileStreamRead(snippetFile));<br /> if (stream == nil) break;<br /><br /> // get the active document interface<br /> IDocument* iDocument = ::GetFrontDocument();<br /> if ( iDocument == nil ) break;<br /><br /> // do the import<br /> InterfacePtr<IXMLFragment> documentElement(iDocument, UseDefaultIID());<br /> ErrorCode err = Utils<ISnippetImport>()->ImportFromStream(stream, documentElement);<br /><br />... and export to Snippet file<br /><br /> // capture selection to snippet file.<br /> PMString snippetFilename;<br /> IDFile snippetFile( WideString( snippetFilename ) )<br /><br /> InterfacePtr<IPMStream> stream(StreamUtil::CreateFileStreamWrite( snippetFile, kOpenOut | kOpenTrunc ));<br /> if (stream)<br /> {<br /> ErrorCode error = Utils<ISnippetExport>()->ExportToStream(stream, snippetUIDList, kInCopyProductFS);<br /> stream->Close();<br /> }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 14, 2009 Jan 14, 2009
Thanks, this code does exactly what I needed !

There is still one problem left: how can I get the UID of the created page item ?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 14, 2009 Jan 14, 2009
I'm afraid I cracked that nut using the proverbial sledgehammer.

I build a UIDlist of all page items before the paste and then again afterwards, then iterate over the beforeUIDList removing each uid from the afterUIDList.

If anyone has a more elegant solution, I'd be interested.

It depends on how much control you have over the snippet files you're pasting, but any one snippet file could contain more than one resulting page item, or even groups of page items.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 14, 2009 Jan 14, 2009
Oh, that was my first thought - I hoped there was a better way...
One solution could be an observer that takes notice of every page item being created - but it's pretty much work for such a "simple" information...

I'll post my solution as soon as it is completed.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 15, 2009 Jan 15, 2009
Take a look at Adobe's solutions:

CS2_SDK/source/sdksamples/incopyfileactions/InCopyDocUtils.cpp
CS3_SDK/source/sdksamples/incopyfileactions/InCopyDocUtils.cpp
CS4_SDK/source/open/components/incopyfileactions/utils/InCopyDocUtils.cpp
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2009 Jan 15, 2009
LATEST
I had a look at the sample files - it doesn't look that good...while writing this sample code Adobe should have recognized that there is something missing (getting a UIDList of all imported page items).<br /><br />So I coded a solution using an IObserver which works fine for me:<br />---------------------------------------------------------------------<br />observer.cpp<br />------------<br />#include "VCPlugInHeaders.h"<br />#include "observer.h"<br /><br />CREATE_PMINTERFACE(IRserverDocObserver, kIRserverDocObserverImpl)<br /><br />IRserverDocObserver::IRserverDocObserver(IPMUnknown* boss) : CObserver(boss, IID_IIRSERVEROBSERVER)<br />{<br />}<br />IRserverDocObserver::~IRserverDocObserver() <br />{<br />}<br />void IRserverDocObserver::AutoAttach()<br />{<br />}<br />void IRserverDocObserver::AutoDetach()<br />{<br />}<br />void IRserverDocObserver::Update(const ClassID& theChange, ISubject* theSubject, const PMIID& protocol, void* changedBy)<br />{<br /> if (theChange == kAddToHierarchyCmdBoss)<br /> {<br /> ICommand* iCommand = (ICommand*)changedBy;<br /> const UIDList* itemList = iCommand->GetItemList();<br /> IDataBase* database = ::GetUIDRef(theSubject).GetDataBase();<br /> for (int i = 0; i < itemList->Length(); i++)<br /> {<br /> if (database->GetClass(itemList->At(i)) == kSplineItemBoss)<br /> {<br /> if (!this->newPageitemsUIDs.Contains(itemList->At(i)))<br /> {<br /> if (this->newPageitemsUIDs.Length() == 0)<br /> {<br /> this->newPageitemsUIDs = UIDList(database, itemList->At(i));<br /> }<br /> else<br /> {<br /> this->newPageitemsUIDs.Append(itemList->At(i));<br /> }<br /> }<br /> }<br /> }<br /> }<br />}<br />bool IRserverDocObserver::AttachDocument()<br />{<br /> bool retval = false;<br /> this->newPageitemsUIDs.Clear();<br /> InterfacePtr<IDocument> document(this, UseDefaultIID());<br /> if (document)<br /> {<br /> InterfacePtr<ISubject> docSubject(document, UseDefaultIID());<br /> if (docSubject && !docSubject->IsAttached(this, IID_IHIERARCHY_DOCUMENT, IID_IIRSERVEROBSERVER))<br /> {<br /> docSubject->AttachObserver(this, IID_IHIERARCHY_DOCUMENT, IID_IIRSERVEROBSERVER);<br /> retval = true;<br /> }<br /> }<br /> return retval;<br />}<br />bool IRserverDocObserver::DetachDocument()<br />{<br /> bool retval = false;<br /> InterfacePtr<IDocument> document(this, UseDefaultIID());<br /> if (document)<br /> {<br /> InterfacePtr<ISubject> docSubject(document, UseDefaultIID());<br /> if (docSubject && docSubject->IsAttached(this, IID_IHIERARCHY_DOCUMENT, IID_IIRSERVEROBSERVER))<br /> {<br /> docSubject->DetachObserver(this, IID_IHIERARCHY_DOCUMENT, IID_IIRSERVEROBSERVER);<br /> retval = true;<br /> }<br /> }<br /> return retval;<br />}<br />PMString IRserverDocObserver::GetNewPageitemsUIDs()<br />{<br /> PMString UIDs;<br /> for (int i = 0; i < this->newPageitemsUIDs.Length(); i++)<br /> {<br /> if (!UIDs.IsEmpty())<br /> {<br /> UIDs.Append(",");<br /> }<br /> UIDs.AppendNumber(this->newPageitemsUIDs.At(i).Get());<br /> }<br /> return UIDs;<br />}<br />---------------------------------------------------------------------<br />observer.h<br />----------<br />#include "IDocument.h"<br />#include "IHierarchy.h"<br />#include "ISubject.h"<br />#include "CObserver.h"<br />#include "UIDList.h"<br />#include "SplineID.h"<br />#include "IRserverID.h"<br /><br />class IRserverDocObserver : public CObserver<br />{<br />public:<br /> IRserverDocObserver(IPMUnknown* boss);<br /> virtual ~IRserverDocObserver();<br /> void AutoAttach();<br /> void AutoDetach();<br /> bool AttachDocument();<br /> bool DetachDocument();<br /> virtual void Update(const ClassID& theChange, ISubject* theSubject, const PMIID& protocol, void* changedBy);<br /> PMString GetNewPageitemsUIDs();<br />protected:<br /> UIDList newPageitemsUIDs;<br />};<br />---------------------------------------------------------------------<br />*.fr file<br />---------<br />AddIn<br />{<br /> kDocBoss,<br /> kInvalidClass,<br /> {<br /> IID_IIRSERVEROBSERVER, kIRserverDocObserverImpl<br /> }<br />},<br />---------------------------------------------------------------------<br /><br />Then I use this code around the import:<br /><br />InterfacePtr<IRserverDocObserver> docObserver(documentUIDRef, IID_IIRSERVEROBSERVER);<br />if (!docObserver->AttachDocument())<br />{<br /> return; <br />}<br />if (Utils<ISnippetImport>()->ImportFromStream(stream, documentElement, kInvalidClass, kSuppressUI) != kSuccess)<br />{<br /> return;<br />}<br />PMString importedItems = docObserver->GetNewPageitemsUIDs();<br />docObserver->DetachDocument();<br /><br />Maybe this is useful for anyone having the same problem.<br />Thanks for your help<br />Detlef
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines