XML API: how to change the objects color
Moderators: SDS, support, admin
XML API: how to change the objects color
Hello everyone,
In this topic we will explain how to apply a new color value to all the entities in Model space through the XML API. Basically, you will need a SelectAll command to select the entities and <apply/> instruction which modifies the properties of selected graphical and non-graphical objects. As you may know, the entity color can be specified by a number of methods:
1) An AutoCAD Color Index (ACI) number of 1 through 255 (1 - Red, 2 - Yellow, 3 - Green and so on).
2) RGB color value (R, G, B).
3) ByLayer - means that the color of objects is determined by its layer's color.
4) ByBlock - means that objects in blocks take on the color of the block. Choosing ByBlock causes objects to use the default color (white or black, depending on your background color) until they are turned into a block. When the block is inserted, the objects inherit the color of the block insertion.
Let's take a look at the examples of using these methods in the XML API:
An AutoCAD Color Index number:
You may be wondering why the Color value uses two numbers. The first number specifies a color system: 0 - AutoCAD Color Index, 1 - the RGB system. The second one specifies a color value in the given color system. The code above applies an AutoCAD color with index 1 (Red) to all the entities in a drawing.
RGB Color:
This code applies red color (255, 0, 0) represented by a hexadecimal value to the selected entities. To obtain a hexadecimal string from values for Red, Green and Blue, you can use RGB to HEX online converter, for example, rgb.to.
ByLayer:
ByBlock:
Mikhail
In this topic we will explain how to apply a new color value to all the entities in Model space through the XML API. Basically, you will need a SelectAll command to select the entities and <apply/> instruction which modifies the properties of selected graphical and non-graphical objects. As you may know, the entity color can be specified by a number of methods:
1) An AutoCAD Color Index (ACI) number of 1 through 255 (1 - Red, 2 - Yellow, 3 - Green and so on).
2) RGB color value (R, G, B).
3) ByLayer - means that the color of objects is determined by its layer's color.
4) ByBlock - means that objects in blocks take on the color of the block. Choosing ByBlock causes objects to use the default color (white or black, depending on your background color) until they are turned into a block. When the block is inserted, the objects inherit the color of the block insertion.
Let's take a look at the examples of using these methods in the XML API:
An AutoCAD Color Index number:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<cadsofttools version="2">
<command text="SelectAll"/>
<apply Color="0;1;"/>
</cadsofttools>
RGB Color:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<cadsofttools version="2">
<command text="SelectAll"/>
<apply Color="1;#FF0000;"/>
</cadsofttools>
ByLayer:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<cadsofttools version="2">
<command text="SelectAll"/>
<apply Color="ByLayer"/>
</cadsofttools>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<cadsofttools version="2">
<command text="SelectAll"/>
<apply Color="ByBlock"/>
</cadsofttools>
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support