ResultBuffer error eInvalidResBuf

ResultBuffer error eInvalidResBuf

Anonymous
Not applicable
2,833 Views
9 Replies
Message 1 of 10

ResultBuffer error eInvalidResBuf

Anonymous
Not applicable

Hi There I have been converting an ARX application into C# and I have a method is giving me this error and am not sure why.

 

The original function is somthing like this

 

ResbufList clsList;
if(isTextFromXData)
clsList.append_list(RTDXF0, (char *)PILOT_CONSTANT_ENTITY_POLYLINE);
else
clsList.append_list(RTDXF0, (char *)PILOT_CONSTANT_ENTITY_POLYLINE1);
clsList.append_list(8, (char *)(LPCTSTR)(strLayerFilter));
clsList.append_list(67, (long)0);

 

I converted that to something like 

List<TypedValue> tvs = new List<TypedValue>();
if (isTextFromXData)
tvs.Add(new TypedValue(5020, "POLYLINE,LWPOLYLINE")); //RTDXF0
else
tvs.Add(new TypedValue(5020, "POLYLINE,LWPOLYLINE,LINE,ARC,CIRCLE,ELLIPSE,3DFACE"));//RTDXF0
tvs.Add(new TypedValue(8, strLayerFilter));
tvs.Add(new TypedValue(67, (long)0));
// Define space boundary filter
ResultBuffer rb = new ResultBuffer(tvs.ToArray()) -------------> Here I get the error eInvalidResBuf

Initially I was trying to add the TypedValue to the result buffer and I was getting the same error on the first typed value.

 

Not sure if is because of the value 5020 is not permitted or it may be something else?

 

Also I'm not sure if this is OK but I don't have the drawing open on the editor. I was trying to just access the data from the database without having to open the drawing but this function eventually is using the ResultBuffer to call the acedSSGet function.

 

Thank in advance for the help.

0 Likes
Accepted solutions (1)
2,834 Views
9 Replies
Replies (9)
Message 2 of 10

ActivistInvestor
Mentor
Mentor
Accepted solution

In managed code, you would create an array of TypedValue[] and pass that to the SelectionFilter's constructor.

 

The value 5020 is wrong. It should be 0 or DxfCode.Start.

 

   if(isTextFromXData)
      dxftypes = "POLYLINE,LWPOLYLINE";
   else
      dxftypes = "POLYLINE,LWPOLYLINE,LINE,ARC,CIRCLE,ELLIPSE,3DFACE";
   SelectionFilter filter = new SelectionFilter(new TypedValue[]
   {
      new TypedValue((int) DxfCode.Start, dxftypes),
      new TypedValue((int) DxfCode.LayerName, strLayerFilter),
      new TypedValue(67, 0)
   });

Secondly, you can't do object selection via managed or native ObjectARX on a DWG that's not open in the editor.

 


@Anonymous wrote:

Hi There I have been converting an ARX application into C# and I have a method is giving me this error and am not sure why.

 

The original function is somthing like this

 

ResbufList clsList;
if(isTextFromXData)
clsList.append_list(RTDXF0, (char *)PILOT_CONSTANT_ENTITY_POLYLINE);
else
clsList.append_list(RTDXF0, (char *)PILOT_CONSTANT_ENTITY_POLYLINE1);
clsList.append_list(8, (char *)(LPCTSTR)(strLayerFilter));
clsList.append_list(67, (long)0);

 

I converted that to something like 

List<TypedValue> tvs = new List<TypedValue>();
if (isTextFromXData)
tvs.Add(new TypedValue(5020, "POLYLINE,LWPOLYLINE")); //RTDXF0
else
tvs.Add(new TypedValue(5020, "POLYLINE,LWPOLYLINE,LINE,ARC,CIRCLE,ELLIPSE,3DFACE"));//RTDXF0
tvs.Add(new TypedValue(8, strLayerFilter));
tvs.Add(new TypedValue(67, (long)0));
// Define space boundary filter
ResultBuffer rb = new ResultBuffer(tvs.ToArray()) -------------> Here I get the error eInvalidResBuf

Initially I was trying to add the TypedValue to the result buffer and I was getting the same error on the first typed value.

 

Not sure if is because of the value 5020 is not permitted or it may be something else?

 

Also I'm not sure if this is OK but I don't have the drawing open on the editor. I was trying to just access the data from the database without having to open the drawing but this function eventually is using the ResultBuffer to call the acedSSGet function.

 

Thank in advance for the help.




0 Likes
Message 3 of 10

Juergen_Becker
Advocate
Advocate

Hi @ActivistInvestor,

 

you wrote: Secondly, you can't do object selection via managed or native ObjectARX on a DWG that's not open in the editor.

 

That is not true, yes we can using LINQ.

 

Regards Jürgen

 

I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

0 Likes
Message 4 of 10

ActivistInvestor
Mentor
Mentor

@Juergen_Becker wrote:

Hi @ActivistInvestor,

 

you wrote: Secondly, you can't do object selection via managed or native ObjectARX on a DWG that's not open in the editor.

 

That is not true, yes we can using LINQ.

 

Regards Jürgen

 


Yes, that is true, and once again you are mistaken.

 

Object selection means creating a selection set, and requires the use of acedSSGet() or the managed wrappers for it, along with selection filters.

 

It's not possible to create or use selection sets on a DWG that's not open in the editor.  Everyone knows already that objects can be accessed in DWGs that are not open in the editor, and collections of them can be made using various criteria with or without LINQ, but that is not "object selection".

 

Do not try to change the definition of English words or AutoCAD terminology only so that you can try to make a point.

 

 

 

Message 5 of 10

Juergen_Becker
Advocate
Advocate

@ActivistInvestor

 

what do you think I'm doing here? My codes are working fine at the customers and I dont telling any rubbish.

LINQ make an object selection. 

Following code select all MTexts on specific layer.

 

var m_ObjectCollection = from m_ObjectId in m_BlockTableRecord.Cast<ObjectId>()
     select new
           {
               m_DBObject = (DBObject)m_Tr.GetObject(m_ObjectId, OpenMode.ForRead, false)
           };
                    
IEnumerable<MText> m_dbMText = from m_OBJECT in m_ObjectCollection
     where (m_OBJECT.m_DBObject.GetType() == typeof(MText))
     select (MText)m_OBJECT.m_DBObject;

m_dbMText = from m_Mtext in m_dbMText
           let Layer = m_ACADSettings.COSTextLayer
           where (m_Mtext.Layer == Layer)
           select (MText)m_Mtext;

Albert Szilvasy who I met in San Francisco  - One Market Street - (Autodesk Office in SF) is the developer of the Linq stuff in AutoCAD. It's implemented in AutoCAD since Version 2012 Shows me how it work correctly. 

Albert told me he is sad that no one (except me) uses LINQ so far.

 

The Linq stuff is really, really fast. 

The above Code works in an application which searches MTEXT in drawings. The code needs for 4 drawings - each 5-6MB - under one second.

 

BTW: This works also fine in AutoCAD Core Console.

 

What you saying is quibbling.

 

No Regards

 

I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

0 Likes
Message 6 of 10

ActivistInvestor
Mentor
Mentor

@Juergen_Becker wrote:

@ActivistInvestor

 

what do you think I'm doing here?


What you are doing here is trying to change the meaning of English words that you don't understand the meaning of, like 'object selection'.

 

LINQ does not make a 'object selection'.  It is just another way to find objects in a database.

 

An 'object selection' is a SelectionSet of objects, selected by the user or by code, that can be used directly with AutoCAD commands. 

 

I and many others have been using LINQ with AutoCAD since it was first introduced in .NET 2.0.  You can search this discussion groups and find plenty of LINQ code right here, written by myself and many others.

 

That you believe you are the only one that uses LINQ with AutoCAD is enough to make anyone who reads your post laugh, and I not need say any more than that.

 

Learn the English language before you try to quibble with me, because you will only end up making a fool of yourself.

 

 

 

 

 

 

 

 

0 Likes
Message 7 of 10

Juergen_Becker
Advocate
Advocate

@ActivistInvestor

 

I'm German and English is not my mother tonque. So be patient.

 

I do not want to be so turned on by you anymore. So just let it be.
 
 
I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

0 Likes
Message 8 of 10

_gile
Consultant
Consultant

@ActivistInvestor wrote:

I and many others have been using LINQ with AutoCAD since it was first introduced in .NET 2.0.

 


@ActivistInvestor If I remember correctly, it was. NET 3.0, but yes really, everyone who liked the functional programming features rushed on it.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 10

ActivistInvestor
Mentor
Mentor

@_gile wrote:

@ActivistInvestor wrote:

I and many others have been using LINQ with AutoCAD since it was first introduced in .NET 2.0.

 


@ActivistInvestor If I remember correctly, it was. NET 3.0, but yes really, everyone who liked the functional programming features rushed on it.


Yes you're right. I often forget what framework various features first appeared in.

0 Likes
Message 10 of 10

_gile
Consultant
Consultant

@Juergen_Becker wrote:

@ActivistInvestor

 

Following code select all MTexts on specific layer.

 

var m_ObjectCollection = from m_ObjectId in m_BlockTableRecord.Cast<ObjectId>()
     select new
           {
               m_DBObject = (DBObject)m_Tr.GetObject(m_ObjectId, OpenMode.ForRead, false)
           };
                    
IEnumerable<MText> m_dbMText = from m_OBJECT in m_ObjectCollection
     where (m_OBJECT.m_DBObject.GetType() == typeof(MText))
     select (MText)m_OBJECT.m_DBObject;

m_dbMText = from m_Mtext in m_dbMText
           let Layer = m_ACADSettings.COSTextLayer
           where (m_Mtext.Layer == Layer)
           select (MText)m_Mtext;

Albert Szilvasy who I met in San Francisco  - One Market Street - (Autodesk Office in SF) is the developer of the Linq stuff in AutoCAD. It's implemented in AutoCAD since Version 2012 Shows me how it work correctly. 

Albert told me he is sad that no one (except me) uses LINQ so far.

 


This is the way I and some other tend to write this for years now, using the Linq extension methods syntax instead of the SQL query one.

Note that filtering the type of a ObjectIds with ObjectClass before opening them is much more faster.

 

 

            var mtextClass = RXObject.GetClass(typeof(MText));
            m_dbMText = m_BlockTableRecord
                .Cast<ObjectId>()
                .Where(id => id.ObjectClass.IsDerivedFrom(mtextClass))
                .Select(id => (MText)tr.GetObject(id, OpenMode.ForRead))
                .Where(mt => mt.Layer == layer);

 

 

If you make a search for "GetObjects" in theSwamp .NET forum, you'll find discussions about the implementation of the GetObjects<T> generic extension method which allows to simply write the upper code this way:

 

m_dbMText = m_BlockTableRecord.GetObjects<MText>().Where(mt => mt.Layer == layer);

 

I don't know who is Albert Szilvasy, but as far as I know there's no specific implementation of Linq for AutoCAD as Linq for objects works with every collection type implementing IEnumerable<T>, and you can get an IEnumerable<T> from any collection of T implementing IEnumerable using Cast<T>. AutoCAD collections did implement IEnumerable yet before .NET 3.0 and Linq but not IEnumable<T> this is why we always need to use Cast<T>.

 

Personally, I started using Linq in AutoCAD as early as the 2010 version that installed the .NET 3.5 Framework (the main new features were specifically Linq and the extension methods).

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes