CAD/CAM discussion forum > CAD > DrawOrderTable error

DrawOrderTable error

    
  Subscribe Topic

Rank: 4

Goran

Senior Engineer

posts: 89

Registered: 2011-7-16

Message 1 of 9

 DrawOrderTable error
14-10-2016 04:13 . am   |   View his/her posts only
In Zwcad 2014+ or 2015+

DrawOrderTable dot = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;

works well, returning DrawOrderTable.


In VERNUM = "2016.09.30(10203)_x64", this line returns error, or btr.DrawOrderTableId is == 0 (zero) if dwg is empty (DrawOrderTableId.IsValid returns false)
After I draw anything and set that anything to bottom or top... voila, works again.

Rank: 5Rank: 5

Jeffrey_ZWCAD

posts: 460

Registered: 2015-6-9

Message 2 of 9

14-10-2016 03:03 . pm   |   View his/her posts only
Reply 1# goranP

I tested with the following code, and when debugging, I draw a circle and a line without setting the draw order, for example, bring the circle to front, and run it. It stops at the statement DrawOrderTable drawOrder = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;(The Exception happens in ZwDatabaseMgd.dll) And if I set the draw order before I run it, it is OK. So is this the problem same as your code?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Collections;
using System.Data;
using System.Diagnostics;
using ZwSoft.ZwCAD.ApplicationServices;
using ZwSoft.ZwCAD.Runtime;
using ZwSoft.ZwCAD.DatabaseServices;
using ZwSoft.ZwCAD.Geometry;


namespace TEST
{
public class Main
{
[CommandMethod("TEST1")]
public static void TEST()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
foreach (ObjectId objId in bt)
{
BlockTableRecord btr = objId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId btrObjId in btr)
{
Entity ent = btrObjId.GetObject(OpenMode.ForWrite) as Entity;

DrawOrderTable drawOrder = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
ObjectIdCollection ids = new ObjectIdCollection();
ids.Add(ent.ObjectId);
drawOrder.MoveToBottom(ids);
}
}
}
}
}
}

Rank: 4

Goran

Senior Engineer

posts: 89

Registered: 2011-7-16

Message 3 of 9

15-10-2016 06:19 . pm   |   View his/her posts only
Something like this, I insert image and send it to bottom.
Code is just like yours.

Rank: 5Rank: 5

Jeffrey_ZWCAD

posts: 460

Registered: 2015-6-9

Message 4 of 9

17-10-2016 02:18 . pm   |   View his/her posts only
Reply 3# goranP


We reported it to R&D to fix, any update, will let you know. Thanks.

Rank: 5Rank: 5

Jeffrey_ZWCAD

posts: 460

Registered: 2015-6-9

Message 5 of 9

30-11-2016 11:48 . am   |   View his/her posts only
Reply 3# goranP


Hi, ZWCAD 2017 has updated to SP1.2 now, is this issue solved?

Rank: 4

Goran

Senior Engineer

posts: 89

Registered: 2011-7-16

Message 6 of 9

01-12-2016 03:24 . am   |   View his/her posts only
Post Last Edit by goranP at 2016-12-1 03:30

No, it is not solved, same thing as before.

Part of the code that set's Raster Image to bottom (this code was c/p from internet), works in zw20124, zw2015, acad 2012-2016:

DrawOrderTable dot = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
ObjectId oid = ri.ObjectId;
ObjectIdCollection objToMove = new ObjectIdCollection();
objToMove.Add(oid);
dot.MoveToBottom(objToMove);

After I draw some elements, next thing is to insert image with WMS system. When I call:

DrawOrderTable dot = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;

btr.DrawOrderTableId is 0 (zero)
btr.Database is null ?!


Then, when I select any element in drawing, set that element to back/top/front/left/right and same code:

DrawOrderTable dot = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;

btr.DrawOrderTableId has value and btr.Database returns {ZwSoft.ZwCAD.DatabaseServices.BlockTableRecord}
oid is Id of Raster Image from WMS
objToMove is collection that will be filled with Id of elements that should be placed to bottom
then objToMove.Add(oid) moves raster image through Id to DrawOrderTable
and finally dot.MoveToBottom(objToMove) moves ri to bottom.

Nothing is/was/were happen with raster image! It stays in the same z-order!
***************************************************************************************
Conclusion:
If DrawOrderTable is not defined yet {null}, as is the case if none of the elements in drawing was set in any position, create new DrawOrderTable (btr.DrawOrderTableId is zero in your case), and depending on position in that table, set element front/back/above/under.

Simple as that!

EDIT:

Now I see that I have double one of the line's in code...

ObjectId oid = ri.ObjectId; -> oid is defined 5 lines up in code....

So, it should be like this:

DrawOrderTable dot = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
//ObjectId oid = ri.ObjectId;
ObjectIdCollection objToMove = new ObjectIdCollection();
objToMove.Add(riId); //riId is Raster Image ID
dot.MoveToBottom(objToMove);

Same things happens.

Rank: 4

Goran

Senior Engineer

posts: 89

Registered: 2011-7-16

Message 7 of 9

14-01-2017 05:49 . am   |   View his/her posts only
VERNUM = "2016.12.09(12354)_x64" (read only)

Bug is stil there, there is no DrawOrderTable in the dwg.
Same error: eInvalidObjectId.


And if I manualy create DrawOrderTable (put some elements in front/back), I have correct riId.

ObjectId riId = btr.AppendEntity(ri);
tr.AddNewlyCreatedDBObject(ri, true);

DrawOrderTable dot = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
ObjectIdCollection objToMove = new ObjectIdCollection();
objToMove.Add(riId);
dot.MoveToBottom(objToMove);

This last line does nothing, raster image is stil in front of everything..

Rank: 5Rank: 5

Jeffrey_ZWCAD

posts: 460

Registered: 2015-6-9

Message 8 of 9

03-02-2017 03:18 . pm   |   View his/her posts only
Reply 7# goranP


Hi, we will push it to be solved in SP3. Thanks.

Rank: 4

Goran

Senior Engineer

posts: 89

Registered: 2011-7-16

Message 9 of 9

08-03-2017 03:15 . am   |   View his/her posts only
VERNUM = "2017.01.23(13656)_x64" (read only)

Not solved.
See also
X