.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

When do we need to use 'SetDatabaseDefaults()'?

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
2457 Views, 3 Replies

When do we need to use 'SetDatabaseDefaults()'?

Anonymous
Not applicable

The first thing I want to sorry because maybe my question is too silly. But I'm only at beginner-level. I read some examples in Autocad.net development documents (in C#) and found that sometimes using SetDatabaseDefaults() on object. I read information in help but didn't understand clearly. Anybody can help me to explain when I need to use it. And use it for what?

Thank you so much

0 Likes

When do we need to use 'SetDatabaseDefaults()'?

The first thing I want to sorry because maybe my question is too silly. But I'm only at beginner-level. I read some examples in Autocad.net development documents (in C#) and found that sometimes using SetDatabaseDefaults() on object. I read information in help but didn't understand clearly. Anybody can help me to explain when I need to use it. And use it for what?

Thank you so much

3 REPLIES 3
Message 2 of 4
norman.yuan
in reply to: Anonymous

norman.yuan
Mentor
Mentor

Have you looked at AutoCAD ObjectARX document for this method? It has 2 overloaded method signatures, one has no argument and the other one has an Database object as argument. Here is the description from the document:

 

For Entity.SetDatabaseDefault():

This function sets the entity's

  • Color
  • Layer
  • Linetype
  • Linetype scale
  • Visibility
  • Plot style name
  • Line weight

to the default values of the database in which the entity currently resides or, if the entity is not part of a database yet, the current database in the AutoCAD editor is used.

 

For Entity.SetDocumentDefault(Database sourceDatabase):

 

This function sets the entity's

  • Color
  • Layer
  • Linetype
  • Linetype scale
  • Visibility
  • Plot style name
  • Line weight

to the default values of the database in which the entity currently resides or, if the entity is not part of a database yet, the current database in the AutoCAD editor is used.

 

In reality, if you create an entity for current drawing database, there may not even have to call SetDatabaseDefault(). In this case, for example, before you add the entity into database, its layer is not set (LayerId=ObjectId.Null. But when you add the entity into database, AutoCAD will set layer to current layer, which is the same as SetDatabaseDefault() does.

 

With this said, though, I'd say it is good practice to call SetDatabaseDefault() any way. One possible situation that you need to call SetDatabaseDefault() might be that you may want to refer one of the properties before the entity being added into database.

 

It might also make your code a bit safe against future AutoCAD API change/update. Just imagine, Autodesk decides to do something more behind the SetDatabaseDefault() in future for whatever possible reason, if your code called this method, your code will no miss the boat; if your code does not call it and relies on your own code to set these properties, then in future, you might have to update your code to do the extra things the updated SetDatabaseDefault() will do then. This is a sort of unlikely, but no one wuold promise you it will never happen.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Have you looked at AutoCAD ObjectARX document for this method? It has 2 overloaded method signatures, one has no argument and the other one has an Database object as argument. Here is the description from the document:

 

For Entity.SetDatabaseDefault():

This function sets the entity's

  • Color
  • Layer
  • Linetype
  • Linetype scale
  • Visibility
  • Plot style name
  • Line weight

to the default values of the database in which the entity currently resides or, if the entity is not part of a database yet, the current database in the AutoCAD editor is used.

 

For Entity.SetDocumentDefault(Database sourceDatabase):

 

This function sets the entity's

  • Color
  • Layer
  • Linetype
  • Linetype scale
  • Visibility
  • Plot style name
  • Line weight

to the default values of the database in which the entity currently resides or, if the entity is not part of a database yet, the current database in the AutoCAD editor is used.

 

In reality, if you create an entity for current drawing database, there may not even have to call SetDatabaseDefault(). In this case, for example, before you add the entity into database, its layer is not set (LayerId=ObjectId.Null. But when you add the entity into database, AutoCAD will set layer to current layer, which is the same as SetDatabaseDefault() does.

 

With this said, though, I'd say it is good practice to call SetDatabaseDefault() any way. One possible situation that you need to call SetDatabaseDefault() might be that you may want to refer one of the properties before the entity being added into database.

 

It might also make your code a bit safe against future AutoCAD API change/update. Just imagine, Autodesk decides to do something more behind the SetDatabaseDefault() in future for whatever possible reason, if your code called this method, your code will no miss the boat; if your code does not call it and relies on your own code to set these properties, then in future, you might have to update your code to do the extra things the updated SetDatabaseDefault() will do then. This is a sort of unlikely, but no one wuold promise you it will never happen.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 4
artc2
in reply to: norman.yuan

artc2
Autodesk
Autodesk

One thing to be aware of is that once you've called SetDatabaseDefaults, you should only add the entity to the database whose defaults it was set to because SetDatabaseDefaults() sets the entity to reference objects in that database.

One thing to be aware of is that once you've called SetDatabaseDefaults, you should only add the entity to the database whose defaults it was set to because SetDatabaseDefaults() sets the entity to reference objects in that database.

Message 4 of 4
Anonymous
in reply to: norman.yuan

Anonymous
Not applicable

Thank you so much. Really I did not read the AutoCAD ObjectARX document. I will find it. Thanks agian

0 Likes

Thank you so much. Really I did not read the AutoCAD ObjectARX document. I will find it. Thanks agian

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report