how to select a specific line

how to select a specific line

mecoman6GF27
Advocate Advocate
3,315 Views
13 Replies
Message 1 of 14

how to select a specific line

mecoman6GF27
Advocate
Advocate

Hello everybody.
Can anyone explain to me how I can select a specific line that is on a certain layer?
I specify that the layer was used to draw a lot of lines.
Thanks a lot, bye.

0 Likes
3,316 Views
13 Replies
Replies (13)
Message 2 of 14

devitg
Advisor
Advisor

@mecoman6GF27  For better understanding, and maybe get further help, please upload such sample.dwg

 

What condition shall the LINE comply. ?

 

 

0 Likes
Message 3 of 14

mecoman6GF27
Advocate
Advocate

Hi devitg, thanks for the reply.
The line to be selected has no particular conditions to be respected. I can tell you that it is on a layer called "A1" but on the same layer there are many other lines. I would like to select only one of these lines to change the coordinates of the end point.

0 Likes
Message 4 of 14

SEANT61
Advisor
Advisor

Explore this thread for any pertinent information:

https://forums.autodesk.com/t5/net/selecting-based-on-layer/m-p/6696802

 


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 5 of 14

devitg
Advisor
Advisor

@mecoman6GF27 , please apologize me , i did not notice that it was a no lisp question . I handle lisp 

0 Likes
Message 6 of 14

mecoman6GF27
Advocate
Advocate

Hello everyone and thanks for the replies.
I have read the information on the link that @SEANT61  recommended me but it talks about all the objects that are on a specific layer. I would like to select only one object of a layer and not all.

0 Likes
Message 7 of 14

SEANT61
Advisor
Advisor

@mecoman6GF27 wrote:

Hello everyone and thanks for the replies.
I have read the information on the link that SEANT61 recommended me but it talks about all the objects that are on a specific layer. I would like to select only one object of a layer and not all.


Re-read the thread and test the code sample.  Using specific properties of PromptSelectionOptions the Editor.GetSelection method can be set up to limit selection to one entity, using filtered criteria.


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 8 of 14

mecoman6GF27
Advocate
Advocate

Hello everybody. I apologize if I re-open this discussion after several months.
With the following code I have selected the line. Now how do I change the coordinates of the end point of the line?
Hi, thank you very much.

    Private Sub B_Select_Click(sender As Object, e As EventArgs) Handles B_Select.Click
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor

        Dim tvs() As TypedValue

        tvs = New TypedValue() {
            New TypedValue(DxfCode.Operator, "<or"),
            New TypedValue(DxfCode.Operator, "<and"),
            New TypedValue(DxfCode.Start, "CIRCLE"),
            New TypedValue(DxfCode.Operator, ">="),
            New TypedValue(DxfCode.Real, 10.0),
            New TypedValue(DxfCode.Operator, "and>"),
            New TypedValue(DxfCode.Operator, "or>")
            }

        Dim sf As SelectionFilter = New SelectionFilter(tvs)
        Dim psr As PromptSelectionResult = ed.SelectAll(sf)

        ed.WriteMessage("Id Object: " & psr.Value.GetObjectIds(0).ToString)
    End Sub
0 Likes
Message 9 of 14

_gile
Consultant
Consultant

The code you posted select all the circles with a radius greater or equal to 10.0 units.

Circles are not lines and do not have end point.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 10 of 14

mecoman6GF27
Advocate
Advocate

Sorry, in the code I posted I selected all the circles instead of the lines. If in that code I wanted to change the radius of the circles what should I do?
Thanks a lot, bye.

0 Likes
Message 11 of 14

_gile
Consultant
Consultant

It's the same process for editing any DBObject:

  1. Start a Transaction.
  2. Open the object for write from its ObjectId.
  3. Edit its properties.
  4. Commit the Transaction to save the changes.

You should read this section of the documentation and all the related topics.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 12 of 14

mecoman6GF27
Advocate
Advocate

Hello.
Can you write an example that I can take inspiration from? I would be very grateful to you.

0 Likes
Message 13 of 14

_gile
Consultant
Consultant
        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // Selection filter to select all the circles with a radius greater or equal to 10.0.
            var filter = new SelectionFilter(new[] 
            {
                new TypedValue(0, "CIRCLE"),
                new TypedValue(-4, ">="),
                new TypedValue(40, 10.0)
            });

            var selection = ed.SelectAll(filter);
            if (selection.Status == PromptStatus.OK)
            {
                // Start a transaction
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    // Loop for each selected object
                    foreach (var id in selection.Value.GetObjectIds())
                    {
                        // Open the circle for write
                        var circle = (Circle)tr.GetObject(id, OpenMode.ForWrite);

                        // Change the radius to 15.0.
                        circle.Radius = 15.0;
                    }
                    // Save the changes
                    tr.Commit();
                }
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 14 of 14

mecoman6GF27
Advocate
Advocate

Hi _gile, thank you very much for your help. You helped me a lot.
Bye.

0 Likes