SDK:Enumerate The Color Palettes: Difference between revisions
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...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
== Enumerate Default Color Palettes Available in Vectorworks == | == Enumerate Default Color Palettes Available in Vectorworks == | ||
<code lang=" | <code lang="cpp"> | ||
using namespace VectorWorks; | using namespace VectorWorks; | ||
using namespace VectorWorks::Filing; | using namespace VectorWorks::Filing; | ||
Line 81: | Line 81: | ||
TColorPaletteDefsArray farrColorPaletteDefs; | TColorPaletteDefsArray farrColorPaletteDefs; | ||
}; | }; | ||
</code> | |||
<code lang="cpp"> | |||
void CMenu_EventSink::DoInterface() | void CMenu_EventSink::DoInterface() | ||
{ | { | ||
Line 94: | Line 96: | ||
== Enumerate The Color Palette of the Current Document == | == Enumerate The Color Palette of the Current Document == | ||
<code lang=" | <code lang="cpp"> | ||
void CMenu_EventSink::DoInterface() | void CMenu_EventSink::DoInterface() | ||
{ | { | ||
Line 104: | Line 106: | ||
documentColorTable->GetColorRecord( myColor.GetColorIndex(), colorRecord ); | documentColorTable->GetColorRecord( myColor.GetColorIndex(), colorRecord ); | ||
} | } | ||
</code> | |||
== Working with the CMYK Color of SColorRecord == | |||
<code lang="cpp"> | |||
SColorRecord colorRecord; | |||
TGSColorV2 rgbColor( colorRecord.fCyan, colorRecord.fMagenta, colorRecord.fYellow, colorRecord.fKey ); | |||
rgbColor.ConvertTo( TGSColorV2::eRGB ); | |||
Uint8 r, g, b; | |||
rgbColor.GetRGB8( r, g, b ); | |||
</code> | </code> | ||
Latest revision as of 12:46, 8 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
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 ); }
Working with the CMYK Color of SColorRecord
SColorRecord colorRecord; TGSColorV2 rgbColor( colorRecord.fCyan, colorRecord.fMagenta, colorRecord.fYellow, colorRecord.fKey ); rgbColor.ConvertTo( TGSColorV2::eRGB ); Uint8 r, g, b; rgbColor.GetRGB8( r, g, b );