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

AcDb.Table and Merged Cells

7 REPLIES 7
Reply
Message 1 of 8
jbooth
789 Views, 7 Replies

AcDb.Table and Merged Cells

I've been messing with the managed wrappers for AcDbTable objects lately, and have hit a snag.

Dim tbr As AcDb.TableRegion = myTable.IsMergedCell(i, j)

The above line of code throws an exception if the cell at i,j is not merged. I need to look up the table's set of merged cells (if there are any), and this function seems to be the only option I have. What bothers me is that I don't want to resort to using a try/catch block in this case.

I am using the .NET wrappers for R17. Also note that myTable is a valid AcDb.Table object that was retrieved through an active transaction.


Is there a workaround I haven't found, or should I wait for the next release before I try to get this part of my application working?
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: jbooth

I am not very sure, because of the lack of documentation, but I guess the
Table.IsMergedCell() returns either TableRagion object (if the cell is
within merged cells, or it raises error (if not within merged cells) instead
retuening null/Nothing, as common OO programming supposed to do.

I found many classes' methods in Acad ObjectARX NET API (or Acad verticle
siblings' ObjectARX .NET API, such as Map) does the same thing. That is,
normally you would expect a method returns an object or null/Nothing, but
the API actually returns either an object, or raise error. It must be some
difficulties for the .NET developers to do the normal thing when wrapping
C++ code into .NET API.

So, if it is this case, "Try...Catch..." probably is the only way to go.


wrote in message news:5611589@discussion.autodesk.com...
I've been messing with the managed wrappers for AcDbTable objects lately,
and have hit a snag.

Dim tbr As AcDb.TableRegion = myTable.IsMergedCell(i, j)

The above line of code throws an exception if the cell at i,j is not merged.
I need to look up the table's set of merged cells (if there are any), and
this function seems to be the only option I have. What bothers me is that I
don't want to resort to using a try/catch block in this case.

I am using the .NET wrappers for R17. Also note that myTable is a valid
AcDb.Table object that was retrieved through an active transaction.


Is there a workaround I haven't found, or should I wait for the next release
before I try to get this part of my application working?
Message 3 of 8
Anonymous
in reply to: jbooth

I have not got the time, to play with this object yet in C#, but, have a
look into this sample of mine done in arx:

http://www.theswamp.org/index.php?topic=9730.msg125087#msg125087


might help...



wrote in message news:5611589@discussion.autodesk.com...
I've been messing with the managed wrappers for AcDbTable objects lately,
and have hit a snag.

Dim tbr As AcDb.TableRegion = myTable.IsMergedCell(i, j)

The above line of code throws an exception if the cell at i,j is not merged.
I need to look up the table's set of merged cells (if there are any), and
this function seems to be the only option I have. What bothers me is that I
don't want to resort to using a try/catch block in this case.

I am using the .NET wrappers for R17. Also note that myTable is a valid
AcDb.Table object that was retrieved through an active transaction.


Is there a workaround I haven't found, or should I wait for the next release
before I try to get this part of my application working?
Message 4 of 8
jbooth
in reply to: jbooth

Unfortunately, the IsMergedCell() function in arx is very different than the one exposed by the AcDb.Table class definition.

In this case, Norman is correct. the function throws an exception when common practice would normally return a null reference (or something similar to note that selected cell is not merged with another cell).

Therefore in the meantime, a try/catch block is my only option.

Thanks for the help,
JB
Message 5 of 8
Anonymous
in reply to: jbooth

Norman, I don't think so.

A function that returns a bool that answers a question,
doesn't throw an exception to answer the question, it
returns true or false to answer it.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Norman Yuan" wrote in message news:5611610@discussion.autodesk.com...
I am not very sure, because of the lack of documentation, but I guess the
Table.IsMergedCell() returns either TableRagion object (if the cell is
within merged cells, or it raises error (if not within merged cells) instead
retuening null/Nothing, as common OO programming supposed to do.

I found many classes' methods in Acad ObjectARX NET API (or Acad verticle
siblings' ObjectARX .NET API, such as Map) does the same thing. That is,
normally you would expect a method returns an object or null/Nothing, but
the API actually returns either an object, or raise error. It must be some
difficulties for the .NET developers to do the normal thing when wrapping
C++ code into .NET API.

So, if it is this case, "Try...Catch..." probably is the only way to go.


wrote in message news:5611589@discussion.autodesk.com...
I've been messing with the managed wrappers for AcDbTable objects lately,
and have hit a snag.

Dim tbr As AcDb.TableRegion = myTable.IsMergedCell(i, j)

The above line of code throws an exception if the cell at i,j is not merged.
I need to look up the table's set of merged cells (if there are any), and
this function seems to be the only option I have. What bothers me is that I
don't want to resort to using a try/catch block in this case.

I am using the .NET wrappers for R17. Also note that myTable is a valid
AcDb.Table object that was retrieved through an active transaction.


Is there a workaround I haven't found, or should I wait for the next release
before I try to get this part of my application working?
Message 6 of 8
Anonymous
in reply to: jbooth

Sorry Norman, but I assumed that IsMergedCell was a
predicate that returns a bool.

It is not. It returns a TableRegion, which is a struct.
Since it is a struct rather than a reference type, it
can't return null, so it does throw an exception.

However, that is absolutely crappy API design. In
that case, the right thing to do would have been to
use an out parameter that receives the TableRegion,
and return a bool.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Norman Yuan" wrote in message news:5611610@discussion.autodesk.com...
I am not very sure, because of the lack of documentation, but I guess the
Table.IsMergedCell() returns either TableRagion object (if the cell is
within merged cells, or it raises error (if not within merged cells) instead
retuening null/Nothing, as common OO programming supposed to do.

I found many classes' methods in Acad ObjectARX NET API (or Acad verticle
siblings' ObjectARX .NET API, such as Map) does the same thing. That is,
normally you would expect a method returns an object or null/Nothing, but
the API actually returns either an object, or raise error. It must be some
difficulties for the .NET developers to do the normal thing when wrapping
C++ code into .NET API.

So, if it is this case, "Try...Catch..." probably is the only way to go.


wrote in message news:5611589@discussion.autodesk.com...
I've been messing with the managed wrappers for AcDbTable objects lately,
and have hit a snag.

Dim tbr As AcDb.TableRegion = myTable.IsMergedCell(i, j)

The above line of code throws an exception if the cell at i,j is not merged.
I need to look up the table's set of merged cells (if there are any), and
this function seems to be the only option I have. What bothers me is that I
don't want to resort to using a try/catch block in this case.

I am using the .NET wrappers for R17. Also note that myTable is a valid
AcDb.Table object that was retrieved through an active transaction.


Is there a workaround I haven't found, or should I wait for the next release
before I try to get this part of my application working?
Message 7 of 8
Anonymous
in reply to: jbooth

Ya, I did not notice TableRegion is a value type at first.

However, if the result of a method (return value or output value) is within
expected scope, throwing an exception as an negetive answer, this seems an
quite common practice in Acad ObjectARX .NET API, as I mentioned in previous
post.

When I first ran into this in Acad Map 2006, I was puzzled, wondering what
was wrong with my code: I user
Claasification.ClassificationManager.GetClassifiedEntities() method, which
returns an ObjectIdCollection. Naturally and logically, you'd think, if
classified entities are found, you'd get a collection containing ObjectIds;
if not found, you'd get an empty collection, or you could get a
null/Nothing. However, that method actually throws an excecption if no
classified entity found. I only found out after repeated degugging and
finally turned to the sample code coming with the SDK.

So, the lesson leared here is, if you could not figure why the code throw
exception at you, it could be by design (good or bad) in .NET API.


"Tony Tanzillo" wrote in message
news:5612160@discussion.autodesk.com...
Sorry Norman, but I assumed that IsMergedCell was a
predicate that returns a bool.

It is not. It returns a TableRegion, which is a struct.
Since it is a struct rather than a reference type, it
can't return null, so it does throw an exception.

However, that is absolutely crappy API design. In
that case, the right thing to do would have been to
use an out parameter that receives the TableRegion,
and return a bool.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Norman Yuan" wrote in message
news:5611610@discussion.autodesk.com...
I am not very sure, because of the lack of documentation, but I guess the
Table.IsMergedCell() returns either TableRagion object (if the cell is
within merged cells, or it raises error (if not within merged cells) instead
retuening null/Nothing, as common OO programming supposed to do.

I found many classes' methods in Acad ObjectARX NET API (or Acad verticle
siblings' ObjectARX .NET API, such as Map) does the same thing. That is,
normally you would expect a method returns an object or null/Nothing, but
the API actually returns either an object, or raise error. It must be some
difficulties for the .NET developers to do the normal thing when wrapping
C++ code into .NET API.

So, if it is this case, "Try...Catch..." probably is the only way to go.


wrote in message news:5611589@discussion.autodesk.com...
I've been messing with the managed wrappers for AcDbTable objects lately,
and have hit a snag.

Dim tbr As AcDb.TableRegion = myTable.IsMergedCell(i, j)

The above line of code throws an exception if the cell at i,j is not merged.
I need to look up the table's set of merged cells (if there are any), and
this function seems to be the only option I have. What bothers me is that I
don't want to resort to using a try/catch block in this case.

I am using the .NET wrappers for R17. Also note that myTable is a valid
AcDb.Table object that was retrieved through an active transaction.


Is there a workaround I haven't found, or should I wait for the next release
before I try to get this part of my application working?
Message 8 of 8
Anonymous
in reply to: jbooth

If you look at the .NET API functions TryParse()
they shows the correct approach for that kind of
problem.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Norman Yuan" wrote in message news:5612337@discussion.autodesk.com...
Ya, I did not notice TableRegion is a value type at first.

However, if the result of a method (return value or output value) is within
expected scope, throwing an exception as an negetive answer, this seems an
quite common practice in Acad ObjectARX .NET API, as I mentioned in previous
post.

When I first ran into this in Acad Map 2006, I was puzzled, wondering what
was wrong with my code: I user
Claasification.ClassificationManager.GetClassifiedEntities() method, which
returns an ObjectIdCollection. Naturally and logically, you'd think, if
classified entities are found, you'd get a collection containing ObjectIds;
if not found, you'd get an empty collection, or you could get a
null/Nothing. However, that method actually throws an excecption if no
classified entity found. I only found out after repeated degugging and
finally turned to the sample code coming with the SDK.

So, the lesson leared here is, if you could not figure why the code throw
exception at you, it could be by design (good or bad) in .NET API.


"Tony Tanzillo" wrote in message
news:5612160@discussion.autodesk.com...
Sorry Norman, but I assumed that IsMergedCell was a
predicate that returns a bool.

It is not. It returns a TableRegion, which is a struct.
Since it is a struct rather than a reference type, it
can't return null, so it does throw an exception.

However, that is absolutely crappy API design. In
that case, the right thing to do would have been to
use an out parameter that receives the TableRegion,
and return a bool.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Norman Yuan" wrote in message
news:5611610@discussion.autodesk.com...
I am not very sure, because of the lack of documentation, but I guess the
Table.IsMergedCell() returns either TableRagion object (if the cell is
within merged cells, or it raises error (if not within merged cells) instead
retuening null/Nothing, as common OO programming supposed to do.

I found many classes' methods in Acad ObjectARX NET API (or Acad verticle
siblings' ObjectARX .NET API, such as Map) does the same thing. That is,
normally you would expect a method returns an object or null/Nothing, but
the API actually returns either an object, or raise error. It must be some
difficulties for the .NET developers to do the normal thing when wrapping
C++ code into .NET API.

So, if it is this case, "Try...Catch..." probably is the only way to go.


wrote in message news:5611589@discussion.autodesk.com...
I've been messing with the managed wrappers for AcDbTable objects lately,
and have hit a snag.

Dim tbr As AcDb.TableRegion = myTable.IsMergedCell(i, j)

The above line of code throws an exception if the cell at i,j is not merged.
I need to look up the table's set of merged cells (if there are any), and
this function seems to be the only option I have. What bothers me is that I
don't want to resort to using a try/catch block in this case.

I am using the .NET wrappers for R17. Also note that myTable is a valid
AcDb.Table object that was retrieved through an active transaction.


Is there a workaround I haven't found, or should I wait for the next release
before I try to get this part of my application working?

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost