SDK:Enumerate The Color Palettes: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
(Created page with "{{LocationMain|category=LocationSDKSpecial|specific=}} <div class="rightmenu"> __TOC__ </div> By [mailto:vstanev@nemetschek.net Vladislav Stanev] == What's that == Vectorwo...")
 
No edit summary
Line 14: Line 14:
== Enumerate Default Color Palettes Available in Vectorworks ==
== Enumerate Default Color Palettes Available in Vectorworks ==


<code lang="c++">
<code lang="cpp">
using namespace VectorWorks;
using namespace VectorWorks;
using namespace VectorWorks::Filing;
using namespace VectorWorks::Filing;
Line 94: Line 94:
== Enumerate The Color Palette of the Current Document ==
== Enumerate The Color Palette of the Current Document ==


<code lang="c++">
<code lang="cpp">
void CMenu_EventSink::DoInterface()
void CMenu_EventSink::DoInterface()
{
{

Revision as of 18:55, 7 August 2014

.SDK|SDK ..SDK:Types|SDK Types ..SDK:Using the SDK|Using the SDK ..VCOM:VCOM (Vectorworks Component Object Model)|VCOM Basics ..VCOM:Class Reference|VCOM Class Reference

By Vladislav Stanev

What's that

Vectorworks ships with a set of default color palettes defined as XML files in the default content folders. Each color palette contains a set of named color definitions.

Each Vectorworks document has a color palette defined within the document. This palette is accessible through the VCOM IDocumentColorTable interface. The document color palette is dynamically modified by Vectorworks as new colors are being used by the user.

Enumerate Default Color Palettes Available in Vectorworks

using namespace VectorWorks;
using namespace VectorWorks::Filing;

class CColorPalettesCollection : public IFolderContentListener
{
public:
  virtual EFolderContentListenerResult  OnFolderContent(IFolderIdentifier* folderID)
  {
    return eFolderContentListenerResult_StopNoError;
  }

  virtual EFolderContentListenerResult  OnFileContent(IFileIdentifier* fileID)
  {
    IXMLFilePtr  xmlFile( IID_XMLFile );
    if ( VCOM_SUCCEEDED( xmlFile->ReadFile( fileID ) ) )
    {
      SColorPaletteDef  colorPaletteDef;
      xmlFile->GetSimpleValue( "ColorPalette/N", colorPaletteDef.fName );

      TXString      nodePath, nodeValue;
      TXStringSTLArray  arrTokens;
      for(size_t i=0; ; ++i)
      {
        SColorRecord  colorRecord;

        nodePath.Format( "ColorPalette/ColorList/C[%d]/N", i );
        colorRecord.fColorName  = xmlFile->GetSimpleValue( nodePath, "" );
        if ( colorRecord.fColorName.IsEmpty() )
          break;  // STOP!

        nodePath.Format( "ColorPalette/ColorList/C[%d]/D", i );
        nodeValue  = xmlFile->GetSimpleValue( nodePath, "" );
        if ( nodeValue.IsEmpty() )
          break;  // STOP!

        TXStringExt::Tokenize( nodeValue, arrTokens, ",", 1 );
        if ( arrTokens.size() != 4 )
          break;  // STOP!

        colorRecord.fCyan    = (float) arrTokens[ 0 ].atof(); 
        colorRecord.fMagenta = (float) arrTokens[ 1 ].atof();
        colorRecord.fYellow  = (float) arrTokens[ 2 ].atof();
        colorRecord.fKey     = (float) arrTokens[ 3 ].atof();

        colorPaletteDef.farrColors.push_back( colorRecord );
      }

      farrColorPaletteDefs.push_back( colorPaletteDef );
    }
  
    return eFolderContentListenerResult_Continue;
  }

private:
  typedef std::vector<SColorRecord>  TColorRecordsArray;

  struct SColorPaletteDef
  {
    TXString            fName;
    TColorRecordsArray  farrColors;
  };

  typedef std::vector<SColorPaletteDef>  TColorPaletteDefsArray;

  TColorPaletteDefsArray  farrColorPaletteDefs;
};

void CMenu_EventSink::DoInterface()
{
  CColorPalettesCollection  theCollection;

  // collect all color palettes
  IApplicationFoldersPtr  appFolders( IID_ApplicationFolders );
  appFolders->ForEachFileInStandardFolder( &theCollection, kDefaultColorPalettesFolder );
}

Enumerate The Color Palette of the Current Document

void CMenu_EventSink::DoInterface()
{
  CRGBColor	myColor( 255, 0, 0 );

  VCOMPtr<IDocumentColorTable>	documentColorTable( IID_DocumentColorTable );

  SColorRecord	colorRecord;
  documentColorTable->GetColorRecord( myColor.GetColorIndex(), colorRecord );
}

See also