Is SelectionWindow went wrong or something ? Autocad .net C#

Is SelectionWindow went wrong or something ? Autocad .net C#

Anonymous
Not applicable
2,140 Views
6 Replies
Message 1 of 7

Is SelectionWindow went wrong or something ? Autocad .net C#

Anonymous
Not applicable
I iterate over BlockTableRecord Layout to get extents3d collection, and then get mtext and dbtext inside extents3d by function SelectWindow. 
But I dont get text collection approximately (Ex: I have 3 extents have 3 text "a", "b", "c", but the results i get only two texts randomly.)
I catch error by drawing line (pt1, pt2), pt1 and pt2 are bounds of extents, then it draws correct line is diagonal line of extents.
But text got was still incorrect. Was this is SelectionWindow's Error? Help me, please.


//Here the code of main class Extents3d acTxtExt3d = acSC.GetExtents3dFromInsertPointOfBlockReferenceAndTwoVectorsWithScale(acBlkRef1, acTxtVec3dOrgArr, acScl3dOrg); //Get extents3d area have text Line acLine = new Line(acTxtExt3d.MinPoint, acTxtExt3d.MaxPoint); acLine.SetDatabaseDefaults(); //Draw a line to catch error acBlkTblRecSpc.UpgradeOpen(); acBlkTblRecSpc.AppendEntity(acLine); acTrans.AddNewlyCreatedDBObject(acLine, true); acBlkTblRecSpc.DowngradeOpen(); //Append line to CurrentSpace // Get Mtext or Text from function of subclass (SelectWindow) DBObject acDbObj = acSC.GetTextInsideExtents3d(acDoc1, acTrans, acTxtExt3d); string txt = ""; // -> Get error here if (acDbObj is DBText) { Application.ShowAlertDialog(((DBText)acDbObj).TextString); txt = ((DBText)acDbObj).TextString; } if (acDbObj is MText) { Application.ShowAlertDialog(((MText)acDbObj).Contents); txt = ((MText)acDbObj).Contents; } // Here is the code of sub class to get Text or Mtext inside a SelectWindow // Only one text in SelectWindow is valid. public DBObject GetTextInsideExtents3d( Document acDoc,Transaction acTrans, Extents3d acExt3d) { Editor acDocEd = acDoc.Editor; TypedValue[] acTypValAr = new TypedValue[4]; acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "<OR"), 0); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), 1); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "MTEXT"), 2); acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "OR>"), 3); SelectionFilter acSFil = new SelectionFilter(acTypValAr); SelectionSet acSSet; Point3d acPt1 = new Point3d(acExt3d.MinPoint.X , acExt3d.MinPoint.Y , 0); Point3d acPt2 = new Point3d(acExt3d.MaxPoint.X, acExt3d.MaxPoint.Y, 0); PromptSelectionResult acPSRes = acDocEd.SelectWindow(acPt1, acPt2, acSFil); if (acPSRes.Status == PromptStatus.OK) { acSSet = acPSRes.Value; if (acSSet.Count == 1) { DBObject acDbObj = null; foreach (ObjectId item in acSSet.GetObjectIds()) { acDbObj = acTrans.GetObject(item, OpenMode.ForRead); } return acDbObj; } else return null; } else return null; }
0 Likes
Accepted solutions (1)
2,141 Views
6 Replies
Replies (6)
Message 2 of 7

_gile
Consultant
Consultant

Hi,

 

Perhaps a User Coordinate System issue?

 

SelectWindow() (as other Editor methods) works with UCS coordinates.

We don't know how the GetExtents3dFromInsertPointOfBlockReferenceAndTwoVectorsWithScale() method works, bu if it returns a WCS defined Extents3d, you have to transform it before use it with SelectWindow().



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi _Gile, thanks for replying my post.

 

I draw a Line which is the diagonal line of extents. When I run command, all lines of extents were drawn, but some texts weren't picked.

So I don't think my extents collection was wrong.

 

Line acLine = new Line(acTxtExt3d.MinPoint, acTxtExt3d.MaxPoint); 
acLine.SetDatabaseDefaults();
//Draw a line to catch error acBlkTblRecSpc.UpgradeOpen(); acBlkTblRecSpc.AppendEntity(acLine); acTrans.AddNewlyCreatedDBObject(acLine, true);
0 Likes
Message 4 of 7

Anonymous
Not applicable

@_gile wrote:

Hi,

 

Perhaps a User Coordinate System issue?

 

SelectWindow() (as other Editor methods) works with UCS coordinates.

We don't know how the GetExtents3dFromInsertPointOfBlockReferenceAndTwoVectorsWithScale() method works, bu if it returns a WCS defined Extents3d, you have to transform it before use it with SelectWindow().


What does "transform" mean? I dont get it, everything in the drawing are in 2D (Z=0). Please help me, thanks.

0 Likes
Message 5 of 7

hgasty1001
Advisor
Advisor

Hi,

 

If the objects are off screen at the moment of a graphic selection, they may not be select, so may be you need to zoom to the extent of the objects before select them.

And would help to know the code of GetExtents3dFromInsertPointOfBlockReferenceAndTwoVectorsWithScale.

 

Gaston Nunez

 

 

0 Likes
Message 6 of 7

_gile
Consultant
Consultant
Accepted solution

Hi,

 

If the current UCS can be different from WCS, you have to transform the points used to create the line which are WCS defined to UCS before using them with SelectWindow().

 

The Editor.CurrentCoordinateSystem property return the current transformation matrix from UCS to WCS. Thr Matrix3d.Inverse() method returns the inverse matrix.

 

So, using the code below insure the selection window will be the one defined by the Extents3d whatever the current UCS.

But as @hgasty1001 said, the window area must be vivsible on screen, doing a zoom extents before doing the selection insure this.

 

Matrix3d xform = acDocEd.CurrentCoordinateSystem.Inverse();
Point3d acPt1 = acExt3d.MinPoint.TransformBy(xform);
Point3d acPt2 = acExt3d.MaxPoint.TransformBy(xform);
dynamic acadApp = Application.AcadApplication;
acadApp.ZoomExtents(); PromptSelectionResult acPSRes = acDocEd.SelectWindow(acPt1, acPt2, acSFil);
acadApp.ZoomPrevious();


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 7

Anonymous
Not applicable

@_gile wrote:

Hi,

 

If the current UCS can be different from WCS, you have to transform the points used to create the line which are WCS defined to UCS before using them with SelectWindow().

 

The Editor.CurrentCoordinateSystem property return the current transformation matrix from UCS to WCS. Thr Matrix3d.Inverse() method returns the inverse matrix.

 

So, using the code below insure the selection window will be the one defined by the Extents3d whatever the current UCS.

But as @hgasty1001 said, the window area must be vivsible on screen, doing a zoom extents before doing the selection insure this.

 

Matrix3d xform = acDocEd.CurrentCoordinateSystem.Inverse();
Point3d acPt1 = acExt3d.MinPoint.TransformBy(xform);
Point3d acPt2 = acExt3d.MaxPoint.TransformBy(xform);
dynamic acadApp = Application.AcadApplication;
acadApp.ZoomExtents(); PromptSelectionResult acPSRes = acDocEd.SelectWindow(acPt1, acPt2, acSFil);
acadApp.ZoomPrevious();

Thank you very much, _gile. That works for me, you make a great save :).

0 Likes