.NET

Reply
Contributor
mleslie00
Posts: 12
Registered: ‎08-22-2012
Message 1 of 3 (6,231 Views)

Error in definition of Drawable.Bounds

6231 Views, 2 Replies
07-25-2013 09:00 AM

 

I just ran into an odd problem with the Bounds method (inherited by all DBObjects).  I was attempting to us it like:

 

Dim bounds As Extents3d = txt.Bounds

 

but VB stated:

 

Error    3    Option Strict On disallows implicit conversions from 'Autodesk.AutoCAD.DatabaseServices.Extents3d?' to 'Autodesk.AutoCAD.DatabaseServices.Extents3d'. 

I looked to see where that question mark was coming from and if there was another class that I hadn't heard of.  It turns out that in the type library, it is defined as:

 

Public Overridable ReadOnly Property Bounds As Autodesk.AutoCAD.DatabaseServices.Extents3d?
     Member of Autodesk.AutoCAD.GraphicsInterface.Drawable

 

This really seems like an error in the type library, how do I ask Autodesk to fix it?

 

Dim bounds As Extents3d = DirectCast(txt.Bounds, Extents3d)

 

does not work since there is not a inheritance or implementation relationship to the typo.

 

Dim bounds As Extents3d = CType(txt.Bounds, Extents3d)

 

seems to work, but how do I get someone to fix the underlying problem?  I think it effects every entity in the database since they all inherit from Drawable.  Or did they do this on purpose for reasons that are beyond me?

 

 

 

 

 

*Expert Elite*
norman.yuan
Posts: 987
Registered: ‎04-27-2009
Message 2 of 3 (6,228 Views)

Re: Error in definition of Drawable.Bounds

07-25-2013 09:24 AM in reply to: mleslie00

mleslie00 wrote:
...

 

This really seems like an error in the type library, how do I ask Autodesk to fix it?

 ...

 


There is nothing to fix in AutoCAD API. DbObject.Bounds is a Nullable<T> type, where T is Extents3d, which is not the same as type Extents3d., that is why you get error when in VB.NET you set "Strict On" and when you cannot DirectCats(...) it. if you use C#, you get the same error.

You get a Extents3d value from Extents3d? (or any Nullable<T> types) by Nullable<T>.Value, only if the Nullable<T>.HasValue is true.

Contributor
mleslie00
Posts: 12
Registered: ‎08-22-2012
Message 3 of 3 (6,209 Views)

Re: Error in definition of Drawable.Bounds

07-25-2013 12:16 PM in reply to: norman.yuan

Ah, thank you.  I have not used nullable much myself and much of the sample code I read when it first came out used the "Nullable(Of" or Nullable<T> syntax, rather than the ? thus I did not recognise the operator.  Not surprisingly "?" does not work well in search engines.

 

I can see why it would be useful to be nullable on a Text object since if the text string is empty, there would be no bounding box.

 

I am now using the following construction in my code:

 

If txt.Bounds.HasValue Then
    bounds = txt.Bounds.Value

Else

   

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.