components of objectarx applications

23
Components of ObjectARX applications. Hello everyone, In this article I will introduce the components of ObjectARX™ applications and tools required to develop them (Fig.1). I know it looks scary. But it gives you amazing customization abilities. Fig.1 Components of an ObjectARX project As I mentioned in my previous article, ObjectARX™ applications are “.dllfiles. Of course, there may be other files like “.xls”, “.doc”, “.exe”, “.bmpect… or other resource files written in other programming languages, “.php”, .asp” files, database, hardware driver connections, etc… depending on what your ObjectARX™ project includes. You should consider it a project composed of many components and files, rather than a code snippet that can be copy-pasted as part of a macro. This “.dll” file, has “.ARX”, or “.DBX” extension. The main application, which I mentioned above, must be ARX file; however if you create your custom objects, which are derived from AutoCAD objects classes, these classes are stored in a DBX extension file, which is linked to main ARX file. At the

Upload: veersh10

Post on 08-Mar-2015

525 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Components of ObjectARX Applications

Components of ObjectARX applications.

Hello everyone,

In this article I will introduce the components of ObjectARX™ applications and tools required

to develop them (Fig.1). I know it looks scary. But it gives you amazing customization

abilities.

Fig.1 Components of an ObjectARX project

As I mentioned in my previous article, ObjectARX™ applications are “.dll” files. Of course,

there may be other files like “.xls”, “.doc”, “.exe”, “.bmp” ect… or other resource files

written in other programming languages, “.php”, “.asp” files, database, hardware driver

connections, etc… depending on what your ObjectARX™ project includes. You should

consider it a project composed of many components and files, rather than a code snippet

that can be copy-pasted as part of a macro.

This “.dll” file, has “.ARX”, or “.DBX” extension. The main application, which I mentioned

above, must be ARX file; however if you create your custom objects, which are derived from

AutoCAD objects classes, these classes are stored in a DBX extension file, which is linked to

main ARX file. At the starting it becomes scary, why two different files, not one? This idea

arises from the separation of UI (user interface) from database operations.

Page 2: Components of ObjectARX Applications

ARX file

In this file you keep the code related to the user interface like toolbars, MFC (Microsoft

Foundation Classes, which is the standard dialog boxes, buttons, scroll bars etc. that

Microsoft use in Windows applications), AutoCAD commands that your application handle

(just like the standard commands you enter from the command line), and other code that

organize the general operation of you application.

DBX file

In this file, you keep your own “custom classes”. Those who don’t know what “object-

oriented programming” is, should skip this part, unless they want to discover a new way of

programming. Those who know about it should also skip because I will try to explain it :) As I

mentioned in my previous article, one of the most exciting features of ObjectARX

programming is ability to create your own custom objects, which may be related to the

concept of “object-oriented programming” in AutoCAD. I will try to explain with an example.

As it is mentioned in this article, TABLE command is introduced with AutoCAD 2005®. This

table entity is a custom object derived from several line, and text entities combined together

to form a TABLE object. I am sure that most of the ObjectARX™ programmers have already

created their TABLE objects before AutoCAD 2005®, and used it in their own applications. At

least, I have done that. These DBX files or the custom objects inside them are totally

reusable, and customizable. Once you create one custom object, you can use it in different

applications or you can derive new custom objects from them and adapt them to your new

problem.

C++ Compiler

Compiler, is a program which compiles the code into and “.exe” or “.dll” file. Thus, we will

use a separate program to write our code. Here is a table for C++ compilers for AutoCAD and

C++ versions. Sorry for users of versions before 2000, I started with R14

ARXWizard

Page 3: Components of ObjectARX Applications

It is included in ObjectARX™ SDK (Software Development Kit), which can be downloaded from

www.objectarx.com for different versions of AutoCAD. This wizard enables us to create our

ObjectARX™ projects, files and objects from default templates and add/modify commands (to

AutoCAD) that our application will handle. It is nearly impossible to create a working project

for a newbie without ARXWizard. When you install it, it adds a toolbar inside VS2002 and

adds itself to the other wizards of VS.

AutoCAD Libraries

They are also included in SDK. They are inside /inc and /lib folders. Actually, you do not need

to deal with these files personally. You just enter these directories into your project settings

and compiler. As I mentioned in my previous article, the main idea of ObjectARX™

programming is using AutoCAD’s own source code, but not limited to it, which is composed of

these libraries. These libraries include AutoCAD’s own object classes and global functions

(like shortcut functions to database related works; angle, distance measurement functions

and much more…). 

MFC (Microsoft Foundation Classes) Libraries

Libraries to use standard Microsoft dialog boxes, buttons etc… Note that, even if you can use

your external resources and MFC libraries, AutoCAD libraries also include objects derived

from MFC.

COM+ (Component Object Model) Connections

For those who used a VBA macro or any other program that enables AutoCAD to

communicate with other programs (like EXCEL), has already used COM without noticing it.

COM is an intermediate platform which enables different programs (even written in different

programming languages) to communicate with each other.

Your own Libraries

You can use your own libraries or any other library that is created with C++ or any other

programming language.

Web Server Connections

For now it’s just my imagination; who needs to include a web server inside an ObjectARX™

application? However, with the development of internet, it enters every field. It is possible to

Page 4: Components of ObjectARX Applications

implement some PHP, ASP, JAVA, AJAX whatever web language you want, through an

ObjectARX™ application, will run on a server and work as a part of your project.

As you see, I am just trying to enlarge your imagination, because there are no limits for the

components that can be added to an ObjectARX™ application. Those I mentioned are only

limited to my programming experiences, for more experienced and talented programmers

there may be much more…

Thanks for reading, and please stay tuned. In my next article, for those who are willing to

write their first program, I will explain the installation of basic components (Fig.1) for an

Object ARX application, so that shortly we can write our first “Hello World” program

A brief information about ObjectARX…1 February 2008, Friday 7:22  Print This Post

Hello everbody,

Today, I will give brief information about ObjectARX, which is one of the innovative steps in

history of AutoCAD. It is another way for programming in AutoCAD, just like AutoLISP and

VBA. Main difference of it is the programming languages it uses, which is C++ in versions up

to AutoCAD 2007® and C++.NET starting with this version.

However, as it uses C++ language and it requires knowledge of the programming structure

of AutoCAD, DLL (dynamically linked library) etc. it took interest of mainly software

developers who develop AutoCAD integrated software products, that are customized in

special subjects (i.e. plug-ins, add-ons, modules that are used to aid specific kinds of

drawings like reinforced concrete, steel detailing drawings, architectural drawings etc.).

Compared to other two customization tools AutoLISP and VBA, ObjectARX is the most

complicated one. For example, if you are about to write a code to draw one simple line you

can do it in AutoLISP and VBA with only a few lines, besides you can do this inside AutoCAD

through the relevant editor. But if you do it with ObjectARX, you will have to prepare a new

project in a C++ compiler like Visual Studio, and create up 1-5 (changing from the

experience of programmer) code files that needs be compiled together with the AutoCAD

libraries the and write up to 100 lines of code. This may sound annoying or just crazy. But the

point is, due to the fact that your ObjectARX application is using some part of the original

AutoCAD source with ObjectARX, you can control a huge part of run-time environment of

AutoCAD. You can manipulate/change the reactions of AutoCAD to specific actions, you can

Page 5: Components of ObjectARX Applications

add new reactions that AutoCAD does when predefined conditions occur, you can add

temporary graphics, drawing aids, dynamic objects, user interfaces, database connections,

communication with other software/hardware etc.. you can even change whatever you don’t

like in AutoCAD’s operation sequence or logic ; shortly whatever you can program in C++,

whatever you can imagine.

What you create with ObjectARX is a DLL file, which can be loaded into AutoCAD, similar to

loading AutoLISP or VBA applications. It is not different from any other DLL that AutoCAD

uses. This is achieved by using some part of the AutoCAD source code. When AutoDESK

introduced ObjectARX concept, what they did is simply to open some of their source code

(which is indeed a very precious commercial secret) so that third party software developers

could use this source code to develop their own applications that works as a part of AutoCAD.

This enabled developers to use AutoCAD only for the user interface of their own program or

they simply created some specific tools that work as a part of AutoCAD, help those who

already use AutoCAD to prepare their drawings. Main idea is that you can apply the “object-

oriented programming” with C++. This means that you can use AutoCAD’s basic objects to

create your own objects. When you are making a drawing what you are doing is simply to put

together the basic drawing objects like lines, texts, points etc. together in a systematic and

oriented manner . For example you are creating a signboard by putting together a line

object as post a text object as something written on it, and a circle, suppose that it is a

circular sign board. If you look into any drawing prepared with AutoCAD or any CAD tool, you

can such objects prepared in the same manner. What if you could have directly created a

signboard object. Up to this point, idea is same as writing a macro, or creating a block, or an

attribute. However idea of creating “custom objects” with ObjectARX is far beyond these.

While creating a block, you are limited to what AutoDESK has programmed for BLOCK

objects, but with ObjectARX you can take the already existing Block object that AutoDESK

has programmed inside AutoCAD and add properties or modify existing properties. You can

append your own objects, algorithms, combine different objects together and add dynamic

properties to the object that is affected by the things that change when you are drawing etc.

Here I could only give only a brief information about ObjectARX and what you can do with it.

However, due to the wide range of possibilities and control it gives to the programmer, its

capacity are limited to the capacity of the ObjectARX programmer . In my next article, I will

explain the components required for creating an ObjectARX application (C compiler and

AutoCAD libraries). Please stay tuned:)

Object ARX software development kit

Page 6: Components of ObjectARX Applications

6 October 2007, Saturday 7:21  Print This Post

Hello everybody,

Today I would like to introduce Object ARX Software Development Kit (SDK). You can

download your free copy of ARX SDK from www.objectarx.com or

www.autodesk.com/objectarx. Click on Samples and Documentation and download

executable achieves depending on the version of AutoCAD for which you want to develop

ObjectARX applications.

Extract them into your hard drive, and you will get the content as shown in Fig. 1.

Fig. 1 Contents of ObjectARX SDK

For different version contents of SDK changes, however general structure and usage is same

only some utilities, documentation and samples change depending on the new features

introduced in each version of AutoCAD and also in ObjectARX. Of course, the contents of lib

and inc folders also change, but you cannot already use them to develop applications for

other versions.

Now, let’s go over each of each folder in SDK.

ARXLABS

In this folder you will find the tutorial help file for developing ObjectARX applications. If you

are not familiar with concept of programming with C++ and Visual Studio, it will be hard to

follow these tutorials. However, if you follow the instructions one by one it would be a great

practice to develop your first ObjectARX application.

Page 7: Components of ObjectARX Applications

DOCS

In this folder you will find the other help files. The main file is arxdoc, which includes all of the

other help files. But I suggest you to create a shortcut to your desktop or elsewhere for

arxdev, which will be the main reference as it includes definitions of all of AutoCAD’s

components that can be used in development of ObjectARX applications.

LIB – INC

These two folders are where you can find the library and header files that Visual Studio will

be linked to, in order to create ObjectARX applications.

SAMPLES

Here you can find the samples for ObjectARX projects. They are also classified for different

subjects. Unfortunately they include only the files that make up the project, so they need to

be compiled with Visual Studio to create the ObjectARX application.

CLASSMAP

In this folder there is an AutoCAD drawing file that shows the classes included in the SDK and

their hierarchy. These classes are originally the real classes that are used in AutoCAD. What

the SDK does is, it gives the programmer access to these classes by the library files and

header files in inc and lib folders so that we can use these classes and their full functionality

to develop our applications or create our own classes from them.

REDISTRIB

In this folder there are some files that can be included in redistribution packages, so that we

can create our own installation files.

UTILS

In this folder, you can find utility files. Depending on the AutoCAD version, there are different

utility programs in this folder. The most important utility program to be used, especially if

you are new to ObjectARX programming, is ARXWizards. When you install ARXWizards, then

your Visual Studio will obtain the functionality to create ObjectARX applications from

templates and other wizards for implementing members and classes inside Visual Studio in a

very easy way.

Page 8: Components of ObjectARX Applications

That’s all for today. Have a nice day.

Programming languages in AutoCAD

20 August 2007, Monday 9:25  Print This Post

As Taliasoft team, we have been developing applications that work integrated wtih AutoCAD

for 16 years. Since the foundation of our company, we created applications for some of the

biggest companies in Turkey, like ABB, AEG, Mercedes Benz Türk, Eczacıbaşı Bath Kitchen

Ltd., Mood Ltd. We published many publications in various magazines regarding AutoCAD™

applications. And today, we are sharing our knowledge with you through this platform. And

from time to time, we are presenting some small applications to you in this web page. We

call some of the applications as programs that are AutoLISP, or .NET, or ObjectARX based

applications. Even now, I can hear you saying ‘I wonder which one of the programming

languages is more suitable for me?‘. In this article, I will try to explain and clarify more

details about this subject.

Perhaps, one of the best features of AutoCAD that is the reason why it is selected by many

users is that it is a customizable software program. Just like the difference between MAC and

PC, even though there are better drawing programs, due to the fact that it is customizable,

AutoCAD has been one of the most favourite programs of people who are working in CAD

works. Because, nearly all of the user interface of AutoCAD, including its menus, status bar,

command line, looking, inside outside…, can be customized. In this article, we will only deal

with the programming languages which are used for making parametric drawings. First of all

let’s see the summary list:

Page 9: Components of ObjectARX Applications

Table 1 - AutoCAD programming and macro languages

Now, let’s briefly go over each of the programming languages:

SCRIPT:

It creates text files that has SCR extension. It is used to execute simple AutoCAD (TM)

commands one after another. It is generally used for taking repeatedly print outs, slide shows

etc. However, even if it is still applicable in today’s versions of AutoCAD, SCR files are

replaced by modern commands.

DIESEL:

When it is first released, its aim was to give several information regarding coordinates and

angles through status bar. On the other hand, it is developed more and it can also be used to

create menu macros. It has limited areas of usage, however it can be used for very practical

purposes. Let’s have a look at the example together:

Command: modemacro

New value for MODEMACRO, or . for none <”">: $(getvar,clayer)

Page 10: Components of ObjectARX Applications

If you change the value of MODEMACRO variable with a DIESEL expression, then you can

see the result of this function through the status bar. Layer name that is used in the example

is being written on the status line.

AutoLISP:

Previously, we used to create LSP files by using any text editor and use these files as

AutoLISP programs. However, since AutoCAD™ 2000, we are using Visual LISP program. By

using this program, we can one or more LISP files under one project and can be compiled so

that they cannot be read. Compiled LISP file includes all of the LISP files and it takes FAS

extension. AutoLISP is a programming language which is very easy to learn. It has a very

high tolerance with respect to trial and error. Experienced programmers can make very

advanced operations by using AutoLISP.

Advantages : Easy to learn, it does not require any other additional programming tools

when Visual LISP that exists in AutoCAD is used. It has a very high tolerance with respect to

trial and error. Intermediate level complex jobs can be made with LISP in a parametric

manner.

Disadvantages : User interface is quite had to use. You have to learn the programming

language called DCL. It is not suitable for doing jobs that require speed and performance. It

cannot communicate with databases (Except special commands).

ADS ( AutoCAD Development System ):

First time AutoCAD™ meets a structural programming language that can be compiled like C,

was with ADS. However, lifetime of this language was not so long. Right after it, ObjectARX

came and ADS was no longer popular. You need to use compiler programs like Watcom C or

Metaware C. However, due to the fact that these compilers did not have IDE, you used to

create the C files in an external text editor. Extension of the files were ADS or EXE.

Advantages: Compiled code was used to run faster and it was more secure. It was nearly

possible to access all of the features that exist in AutoCAD (TM). Even it was very difficult, it

was also possible to connect to databases. Operation system file operations was much faster

and easier.

Disadvantages : It is very hard to learn C. Compilers that were used was a total headache.

User interface was possible again by using DCL. It was very hard to complete a project unless

you create your own library.

Page 11: Components of ObjectARX Applications

Object ARX ( AutoCAD Runtime Extensions ):

AutoCAD™ met Visual C++ ( Visual Studio 6.0 ( VS6 ) ) in R13 version. It was a revolutionary

new feature to create your own AutoCAD™ entities by using C++. In addition, these new

entities that you create was able to be edited by using the standard commands of AutoCAD

like MOVE, ERASE, COPY as if it is an original AutoCAD entity. Of course it is quite difficult to

make this definition. On the other hand, due to the fact that we were using VS6, it was now

available to access MFC libraries. This meant that we were now able to use Windows (TM)

windows and controls as our user interface, or directly connect to databases, network

communication, internet access etc… File extensions can be ARX or DBX. These files are

originally DLL files.

Advantages : It can create secure files that are very fast during execution. It is very easy to

create database connections and user interfaces. It works in the same level as the internal

commands of AutoCAD.

Disadvantages: It is very hard to learn. You can make the projects much faster by using

your own libraries

DCL ( Dialog Control Language ):

It is possible to create user interfaces while programming with AutoLISP and ADS by this

programming language. Main principle can be described as giving a key a label or a property

to each of dialog controls. By using this key, you can directly access to the dialog control. It is

still in use. File extension is DCL. You can examine the files under AutoCAD (TM) and have an

idea about it.

.NET :

By using Visual Studio 2002 or 2005 ( VS2005 ), you can create C#, VB.NET DLL projects.

MANAGED EXTENSION DLL which is prepared by AutoCAD as ‘ObjectARX wrapper are

assigned to the project as references. Extension of the file that was created is DLL and it is

loaded into AutoCAD by using NETLOAD command.

Advantages: It is easy to learn. It is quite simple to define a user interface. It is very easy o

connect to databases. You can very easily use the code that you have written in your other

projects.

Disadvantages: This system is very open to reverse engineering, which means that your

DLL files can easily be interpreted. Microsoft Co. Should work a little bit more about this

subject. It works quite slower when compared to Object ARX. You cannot define your own

Page 12: Components of ObjectARX Applications

custom entity. Due to the fact that the created application works in APPLICATION DOMAIN,

you cannot remove it from system memory before shutting down AutoCAD. Because of this it

creates a big headache during software development and debugging.

VBA ( Visual Basic for Applications ) :

This is a system that AutoDESK used to obtain Windows™ compatible certificate. You can

create simple VB projects similar to the way that you can create VB macros in EXCEL. Our

author Serkan ÖZANT is creating channel drawings programs by suing this system.

Advantages: It is very easy to learn. It is very easy to create user interfaces. It is very easy

to connect to databases.

Disadvantages: Those who use VBA knows very well that it is very hard to access DLLs and

may create different problems in different computers. In addition, as AutoDESK created this

system unwillingly, it is not very helpful for the user. It works relatively slowly. It is expected

anytime that it may break something in AutoCAD screen.

Technorati Tags: AutoCAD, C++, AutoLISP, Visual LISP, VBA for AutoCAD

Customization Methods in AutoCAD.

12 June 2007, Tuesday 7:55  Print This Post

General proggraming information

There are three different methods that can be used for customization, or in other words

programming your own applications in AutoCAD. Below, you can see these three methods as

sorted from less complicated to most complicated one.

-AutoLISP Macros (Programming language: VisualLISP)

-VBA Macros (Programming language: Visual Basic)

-ObjectARX and DBX modules (Programming language: C++)

Let’s examine this there methods together…

1-AutoLISP Macros:

VisualLISP is the oldest of programming languages used in AutoCAD. It might be a little bit

old fashioned when compared to today’s complicated programming languages. However, it is

extremely useful for custom applications that are developed to use AutoCAD’s own

Page 13: Components of ObjectARX Applications

commands and for purposed that are repeated several times. Compared to other

programming methods, it is the easier to learn and use.

Another one of its main advantages is that it can be used directly as AutoCAD’s original

environment and as if it is AutoCAD’s own commands.

2-VBA Macros:

Visual Basic is specially developed for those who do not require a complicated programming

language to develop large, complicated applications; but need less complicated and easy to

understand and use programming languages. Its usage and learning procedure is much more

easier compared to other programming languages.

When compared to LISP it provides wider ranges variations of applications.

Similar to LISP, it includes a VISUAL BASIC Editor which is integrated into AutoCAD. This

editor is the same editor that is integrated into Ms Office applications like word, excel that is

used for creating VBA macros in these applications.

Probably, it’s greatest advantage is that it can be programmed through other applications

like Word, Excel using the VBA editor of these applications and enable all these programs to

communicate with each other in a very easy manner.

3-OBJECT ARX DBX Modules:

When compared to others, this is the one that provides wider range of possibilities but on the

contrary, that most complicated one to learn and use. C++ programming language is more

complicated compared to LISP and Visual Basic languages that is used in other methods.

Other two programming languages are more like scripting languages. They are more efficient

to automate basic tasks that repeat themselves. On the other hand, ObjectARX

programming uses AutoCAD’s own source code to develop more sophisticated and

specialized applications. Due to the fact that, C++ is an object oriented programming

language, you can create your own objects that are specialized for special purposes, either

by using AutoCAD’s own objects or entirely new. They are more then a script or a macro. By

using ObjectARX, specialized programs that run under AutoCAD, which uses AutoCAD’s user

interface as its own graphical interface can be programmed.

Page 14: Components of ObjectARX Applications

But all these make ObjectARX applications more complicated. For example simple tasks like

drawing basic entities may require only 2-3 lines of code in AutoLISP and VBA, however same

task may be programmed by using 100 lines of code in ObjectARX.

Creating AcDbMaterial object 4: Creating a textured material17 January 2007, Wednesday 9:21  Print This Post

Author Erhan Toker

Profession Architect M.Sc.

  Autodesk Authorized Consultant

  Software Specialist

e-mail  

AutoCAD 2007

Now, we have enough information related to materials. So, we can create a general textured

material. We can define texture properties by creating another AcGiMaterialMap object

in addition to the standard color. Textures are made up of pictures that are already existing

in the drawing or saved as a file in hard drive. In our example function, we assume that

texture file ( tName ) is stored inside hard drive as a picture file. Here is our function ( Fig.

1):

Page 15: Components of ObjectARX Applications

Fig. 1.

To assign properties like Tile, Crop etc… to material definition, you can use AcGiMapper

object. However, I suggest tat you should do this operation by the mapping which will be

assigned to the material to be texturized. That will be the subject of our next article.

Creating an AcDbMaterial Object - 17 December 2006, Thursday 9:42  Print This Post

Page 16: Components of ObjectARX Applications

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

Input parameters:

Page 17: Components of ObjectARX Applications

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.

Creating AcDbMaterial Object 213 December 2006, Wednesday 9:33  Print This Post

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 )

Page 18: Components of ObjectARX Applications

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

Page 19: Components of ObjectARX Applications

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.

Creating AcDbMaterial object 311 January 2007, Thursday 9:19  Print This Post

Author Erhan Toker

Profession Architect M.Sc.

  Autodesk Authorized Consultant

  Software Specialist

e-mail  

AutoCAD 2007

After defining hasMaterial() and addMaterial() functions, from now on, we are

ready to create a simple texture material. Any AutoCAD material has one or more of diffuse,

bump, specular, refraction, opacitiy and reflection properties. At least, a simple material has

a diffuse color and in this article I will explain such a material.

A simple material only has the property of color diffusion. In ObjectARX library, color object is

AcGiMaterialColor. Let’s define a color now (Fig. 1):

Fig. 1.

Together with setMethod() method, we can use kInherit ( last used color from AcGi

stream ) or kOverride ( new color definition) options. And, by using setColor()

method, we are defining the color that the material is going to make diffused by using RGB

components. Besides, we are setting the diffusivity rate of the color by using

setFactor() method. Now, let’s create a material and define its diffusion properties (

Fig.2 ).

Page 20: Components of ObjectARX Applications

Fig. 2.

Our material definition is almost finished. However, diffusion property doesn’t spread enough

light by itself. We are adding the same color to our material by using setAmbient()

function (Fig. 3) as an environment property by using 0.5 factor.

Fig. 3.

Now, our material is ready to be added to the drawing. We are inserting the new material

that we have created into drawing data base by using addMaterial() method ( Fig.4 ).

Fig. 4.

I would like to finalize my article by noting that, pointer acdbWDB points to current drawing

database, and it is a macro definition.

#define acdbWDB acdbHostApplicationServices()->

workingDatabase().

Related articles

Creating an AcDbMaterial Object - 1 Creating AcDbMaterial Object 2