.NET

.NET

Reply
Member
salty8
Posts: 4
Registered: ‎08-17-2013
Message 1 of 4 (322 Views)

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

322 Views, 3 Replies
08-17-2013 09:42 AM

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

*Expert Elite*
norman.yuan
Posts: 1,064
Registered: ‎04-27-2009
Message 2 of 4 (267 Views)

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

08-19-2013 07:00 AM in reply to: salty8

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.

 

 

Employee
artc2
Posts: 229
Registered: ‎06-08-2010
Message 3 of 4 (259 Views)

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

08-19-2013 09:18 AM in reply to: norman.yuan

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.

Member
salty8
Posts: 4
Registered: ‎08-17-2013
Message 4 of 4 (221 Views)

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

08-22-2013 09:51 AM in reply to: norman.yuan

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.