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

lisp into c# (command : fastsel)

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
samiranjith1
882 Views, 11 Replies

lisp into c# (command : fastsel)

here is my question :

 

I want to access FASTSEL command from c# , to find connected entities from given input , 

double x = (entity as Arc).StartPoint.X;
double y = (entity as Arc).StartPoint.Y;

doc.SendStringToExecute($"Select touching object: {x},{y}" + " ", true, false, true);

 

but following above code ,this is behaving asynchronous way , I want synchronous way answer

so I tried below mentioned code,

 

ResultBuffer pa = new ResultBuffer();
pa.Add(new TypedValue(5005, "c:fastsel"));
pa.Add(new TypedValue(5002, new Point2d(ent.StartPoint.X, ent.StartPoint.Y)));

ResultBuffer rb = Application.Invoke(pa);

 

here am facing issue like error too many arguments , may I know what is the correct format for passing the arguments for fastsel command?  kindly help me out from this 

 

thanks in advance

Labels (3)
11 REPLIES 11
Message 2 of 12
_gile
in reply to: samiranjith1

Hi,

 

The LISP function c:fastsel have to be called with none argument.

 

Most of the times, mixing LISP and .NET is more difficult than doing things in plain LISP or plain .NET.

Implement what FASTSEL does in plain .NET wouldn't be so difficult.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 12
samiranjith1
in reply to: _gile

thanks for the response ,

.NET based logic derivation seems like take some time , that's why i approached this way  , is there any other way to achieve connected entity selection ? that would be better for me , can you share your thought on this ? 

Message 4 of 12
_gile
in reply to: samiranjith1

Here's a quick and dirty you can start from.

        static ObjectIdCollection FastSel(Editor ed, ObjectId sourceId)
        {
            var ids = new ObjectIdCollection { sourceId };
            var db = sourceId.Database;
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var sourceEntity = (Entity)tr.GetObject(sourceId, OpenMode.ForWrite);
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                        var points = new Point3dCollection();
                using (var view = ed.GetCurrentView())
                {
                    var plane = new Plane(view.Target, view.ViewDirection);
                    foreach (ObjectId id in curSpace)
                    {
                        var entity = (Entity)tr.GetObject(id, OpenMode.ForRead);
                        points.Clear();
                        sourceEntity.IntersectWith(entity, Intersect.OnBothOperands, plane, points, IntPtr.Zero, IntPtr.Zero);
                        if (0 < points.Count)
                        {
                            ids.Add(entity.ObjectId);
                        }
                    }
                }
            }
            return ids;
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 12
samiranjith1
in reply to: _gile

Thanks gile , surely this will help me ,in this case i have to replicate same logic behind FASTSEL command in .NET, i have analyzed fastsel.lsp file which is available in express folder but am not familiar with lisp ,so i could not understand the logic which is wrote behind the FASTSEL , can you give me brief description what are the logic steps followed for each entity ?  

Message 6 of 12
_gile
in reply to: samiranjith1

The logic is to check for projected intersections on the current view plane between the "touch object" and the other entities in the current space (as done in the upper snippet).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 12
mttlp
in reply to: samiranjith1

how can i make the above code to select all like fastsel

Message 8 of 12
samiranjith1
in reply to: mttlp

we have to do recursion until all the touched object added in list , if i am wrong correct me _gile

Message 9 of 12
samiranjith1
in reply to: _gile

thank you gile , I'll develop along with above mentioned code 

Message 10 of 12
_gile
in reply to: mttlp


@mttlp  a écrit :

how can i make the above code to select all like fastsel


        [CommandMethod("TEST")]
        public void Test()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var per = ed.GetEntity("\nSelect touch entity: ");
            if (per.Status != PromptStatus.OK) 
                return;
            var ids = FastSel(ed, per.ObjectId);
            var array = new ObjectId[ids.Count];
            ids.CopyTo(array, 0);
            ed.SetImpliedSelection(array);
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 12
mttlp
in reply to: _gile

Thank you

Message 12 of 12
samiranjith1
in reply to: _gile

Hi ,

Here all the DB entities are looping for single entity, when it is comes in large models , lot of time will take here , instead of using intersect i have used SelectFence in autocad api , it gives exact result for line entity , it does not work for ARC's , is there any efficient way to achieve the connected element identification in AutoCAD ?  

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report