CADViewer Technical Documentation, Installation Guide and Reference Samples Library

API Color Controls

Application programmers can control the line colors in the drawings by using the CADViewer API.

For this purpose the drawing needs to be converted with the conversion parameter colorasc activated. This parameter will allow application programmers to control the AutoCAD Palettes.

See the two default AutoCAD palettes: AutoCAD Light Palette and AutoCAD Dark Pallette.

NOTE: The index in the Palette will start from 0 when using the CADViewer API!

For CAD converter AutoXchange AX2023 from version v23.12.108 and above the colorasc parameter is default, for previous versions (v23.12.106 - v23.12.107 ),use the following converter setting:

cvjs_conversion_addAXconversionParameter("colorasc", "");	

The following Color Palette API are supported:

Extract full Color Palette List used
/**
 *  Returns a list of all active palette colors in drawing. NOTE, first palette color has index 0.
 * <strong>CADViewer Internal Command Groups:</strong> [All]{@link https://cadviewer.com/cadviewerproapi/global.html?id=All}. 
 * @returns - list of color palette numbers
 */
function cvjs_getActivePaletteColorList()
// echo the list of palette colors used in drawing
window.alert(cvjs_getActivePaletteColorList());
Extract the color associated with a Palette Number
/**
 * Get the color of a given palette number in the drawing. NOTE, first palette color has index 0.
 * 
* <strong>CADViewer Internal Command Groups:</strong> [All]{@link https://cadviewer.com/cadviewerproapi/global.html?id=All}. 
 * @param {int} colornumber   - palette number
 * @returns  - hex code of color
 */
function cvjs_getActivePaletteColor(colornumber)
// Echo the hex color of color 2. Color Yellow is 2 in the AutoCAD Light Palette list ( index 3  - 1)
window.alert(cvjs_getActivePaletteColor(2));
Set color of a Palette number
/**
 *  Set a given palette color number with a hex color. NOTE, first palette color has index 0.
 * <strong>CADViewer Internal Command Groups:</strong> [All]{@link https://cadviewer.com/cadviewerproapi/global.html?id=All}. 
 * @param {*} colornumber - color palette number
 * @param {*} hex  - new color, given in hex number.
 */
function cvjs_setActivePaletteColor(colornumber, hex)
// Color Yellow is 2 in the AutoCAD Light palette list ( index 3  - 1), we set that to RED #F00
cvjs_setActivePaletteColor(2, "#F00"));
Have FUN!
Last updated on 29 Jan 2023
Published on 29 Jan 2023