Creating AcDbMaterial Object 2



Author Erhan Toker
Profession Architect M.Sc.
  Autodesk Authorized Consultant
  Software Specialist
e-mail  

Autocad 2007 and higher versions

 

In my previous article, we have checked if the material, we want to create, exists in the drawing database or not. As the second step, we will see how to add a new material to the database. To do this, we will create addMaterial( ... ) function and examine it. ( Fig. 1 )

Fig.1
Fig. 1

Input parameters:

AcDbDatabase *db: Pointer to drawing database.
AcDbMaterial *mat: New material definition object.
AcDbObjectId &idm: Object ID of the created material.
bool overWrite: pass ‘true’ to overwrite existing materials, ‘false’ to avoid overwrite.

Return value:

true: Material successfully added in to dictionary.
false: Unable to add material.

First we will check if the material exists in the drawing or not. To do this, we are using the ( hasMaterial() ) function (with mat->name() ) which we have created and explained in the previous article. If the material that we will add exists in the project, depending on the overWrite boolean (if it is TRUE or FALSE) variable, either we will directly exit the function or we will overwrite the new material over the existing one. Due to the fact that, by default AcDbDictioanary::setAt() function overwrites the entries that has the same name, there is no need to delete the old one. After adding the material to the dictionary, we must not forget to close the dictionary and material object. Finally, I would like to remind you that we are not deleting the AcDbMaterial *mat object, we are just closing it.

Similar Posts

Rate this article:

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply