Creating an AcDbMaterial Object - 1



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

Autocad 2007 programming

 

In this series of articles, I will explain how to create a AcDbMaterial object in the drawing database. Although this process is very easy, there are some certain points that you should be careful about. I will explain these points and the process to you step by step.

Before adding any material to drawing database, you should check if another material with the same name exists in the database. For this reason, we will define hasMaterial(…) funtion first (Fig.1).


Fig.1
Fig.1

Input parameters:

AcDbDatabase *db : Pointer to drawing database.
const ACHAR *matName : Material name to query.
AcDbObjectId &id : Object ID of the found material. If there is no ‘matName’ material in drawing database, this parameter will be assigned the value AcDbObjectId::kNull .
Return value:
true :Material name is exists in drawing database.
false :Material is not exists in drawing database.

In AutoCAD drawings, material definitions are stored inside a dictionary (AcDbDictionary object). In order to reach this dictionary AcDbDatabase::getMaterialDictionary(…) function is used. After opening the dictionary as -open for read-; material is searched inside the dictionary by using AcDbDictionary::getAt(…) function. If the material is found in the dictionary, getAt() function also gets the Object Id of the material. After the process is completed, dictionary is closed and the return value is returned.

Similar Posts

Rate this article:

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

Leave a Reply