C# Sortents

C# Sortents

Anonymous
Not applicable
1,047 Views
11 Replies
Message 1 of 12

C# Sortents

Anonymous
Not applicable
I am new to C# and am trying to access the sortents table.
Can anybody give me some help?
When I look in the help files (ObjectArx Referance) I see this:

Acad::ErrorStatus
getSortentsTable(
AcDbSortentsTable*& pSortents,
AcDb::OpenMode openMode,
bool createIfNecessary = false);

I can tell this is referance for C or C+ but how do I use this in C#?
0 Likes
1,048 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
The BlockTableRecord has a DrawOrderTableId property
that is the ObjectId of the associated DrawOrderTable
managed wrapper class.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5196672@discussion.autodesk.com...
I am new to C# and am trying to access the sortents table.
Can anybody give me some help?
When I look in the help files (ObjectArx Referance) I see this:

Acad::ErrorStatus
getSortentsTable(
AcDbSortentsTable*& pSortents,
AcDb::OpenMode openMode,
bool createIfNecessary = false);

I can tell this is referance for C or C+ but how do I use this in C#?
0 Likes
Message 3 of 12

Anonymous
Not applicable
Thank for a nudge in the right direction!
0 Likes
Message 4 of 12

Anonymous
Not applicable
Ok, I am stuck again.
I am trying to get the DrawOrderTable and this is what I have done

DrawOrderTable dot;
Transaction trans;
trans=HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();
dot=(DrawOrderTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId,OpenMode.ForWrite)

When I run this I get the following error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast object of type 'Autodesk.AutoCAD.DatabaseServices.BlockTable' to type 'Autodesk.AutoCAD.DatabaseServices.DrawOrderTable'.

What am I doing wrong?
0 Likes
Message 5 of 12

Anonymous
Not applicable
Look at your code.

You're trying to open a BlockTableRecord as
a DrawOrderTable.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5198186@discussion.autodesk.com...
Ok, I am stuck again.
I am trying to get the DrawOrderTable and this is what I have done

DrawOrderTable dot;
Transaction trans;
trans=HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();
dot=(DrawOrderTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId,OpenMode.ForWrite)

When I run this I get the following error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast object of type 'Autodesk.AutoCAD.DatabaseServices.BlockTable' to type 'Autodesk.AutoCAD.DatabaseServices.DrawOrderTable'.

What am I doing wrong?
0 Likes
Message 6 of 12

Anonymous
Not applicable
Yes, I noticed that after I posted.
But when I get to
HostApplicationServices.WorkingDatabase.????
I do not get the choice to select DrawTable.
I guess I am asking is how to open the DrawOrderTable, I am sure its in the help files but I am having a tough time finding the info I need in them.
0 Likes
Message 7 of 12

Anonymous
Not applicable
Please review my first post in this thread,
note what object has the DrawOrderTableId
property.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5199272@discussion.autodesk.com...
Yes, I noticed that after I posted.
But when I get to
HostApplicationServices.WorkingDatabase.????
I do not get the choice to select DrawTable.
I guess I am asking is how to open the DrawOrderTable, I am sure its in the help files but I am having a tough time finding the info I need in them.
0 Likes
Message 8 of 12

Anonymous
Not applicable
Yep, I did that.
Thanks for the patients!
Anyone else who is following this extreemly painfull learning curve, heres what I did to get this to work.

Transaction trans=HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();

DrawOrderTable dot;
BlockTableRecord btr;

btr=BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId,OpenMode.ForWrite);

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

Just like Tony said.
If this is still not tech correct please correct for the rest of us.

Thanks again
0 Likes
Message 9 of 12

Anonymous
Not applicable
Ok, More problems.
I have been trying for 2 day and I cant figure out what I am doing wrong.

I have a list of blocks names in a listview
I want to get the ObjectId's of the blocks
Then put them in a ObjectId Collection
Then pass the collection through the MoveToTop function(in the draworder table)

Heres what I did.
ObjectIdCollection Idcollection = new ObjectIdCollection();
//cycle throught the listview
foreach (ListViewItem item in lvwXrefs.Items)
{
//cycle through current space block record table
foreach(ObjectId objId in btr)
{
DBObject dbObj = trans.GetObject(objId,OpenMode.ForRead);
BlockReference blkRef = dbObj as BlockReference;
if (blkRef!=null)
{
BlockTableRecord blkDef=(BlockTableRecord)trans.GetObject(blkRef.BlockTableRecord,OpenMode.ForRead);
if (blkDef.Name == item.Text)
{
Idcollection.Add(blkDef.ObjectId);
}
}
}

}
dot.MoveToTop(Idcollection);
trans.Commit();
trans.Dispose();
}

Now I do get all the Object Id's and can print them to the editor.
But as soon as I try to pass them to the "movetotop" fuction, autocad crashs badly

any help?
0 Likes
Message 10 of 12

Anonymous
Not applicable
>> Idcollection.Add(blkDef.ObjectId);

Your code appears to be adding the object ids
of block table records to the id collection, rather
than the ids of block references.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5203828@discussion.autodesk.com...
Ok, More problems.
I have been trying for 2 day and I cant figure out what I am doing wrong.

I have a list of blocks names in a listview
I want to get the ObjectId's of the blocks
Then put them in a ObjectId Collection
Then pass the collection through the MoveToTop function(in the draworder table)

Heres what I did.
ObjectIdCollection Idcollection = new ObjectIdCollection();
//cycle throught the listview
foreach (ListViewItem item in lvwXrefs.Items)
{
//cycle through current space block record table
foreach(ObjectId objId in btr)
{
DBObject dbObj = trans.GetObject(objId,OpenMode.ForRead);
BlockReference blkRef = dbObj as BlockReference;
if (blkRef!=null)
{
BlockTableRecord blkDef=(BlockTableRecord)trans.GetObject(blkRef.BlockTableRecord,OpenMode.ForRead);
if (blkDef.Name == item.Text)
{
Idcollection.Add(blkDef.ObjectId);
}
}
}

}
dot.MoveToTop(Idcollection);
trans.Commit();
trans.Dispose();
}

Now I do get all the Object Id's and can print them to the editor.
But as soon as I try to pass them to the "movetotop" fuction, autocad crashs badly

any help?
0 Likes
Message 11 of 12

Anonymous
Not applicable
As a somewhat related question,
Doesn’t the DrawOrderTable contain ObjectIds of block references?
As a last resort I tried taking the ObjectIds from the DrawOrderTable and putting them in the “MovetoTop” function and that also failed.

I guess I am really off the mark in terms of figuring out the logic of this. Message was edited by: Techno Destructo
0 Likes
Message 12 of 12

Anonymous
Not applicable
The DrawOrderTable contains the ids of any visible entity
(any object derived from AcDbEntity) which includes block
references.

Your code isn't adding block references to the DOT, it is
adding block definitions, which are not visible entities.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5205008@discussion.autodesk.com...
As a somewhat related question,
Doesn’t the DrawOrderTable contain ObjectIds of block references?
As a last resort I tried taking the ObjectIds from the DrawOrderTable and putting them in the “MovetoTop” function and that also failed.

I guess I am really of the mark in terms of figuring out the logic of this.
0 Likes