Select structure by coordinate

Select structure by coordinate

luiz.silvaNDFA2
Advocate Advocate
1,573 Views
10 Replies
Message 1 of 11

Select structure by coordinate

luiz.silvaNDFA2
Advocate
Advocate

Good Morning, first I'm sorry for English because I don't know how to speak. I am developing a routine in C # to build a network from data that is in .txt. The big problem is that I need to check if there is a structure before inserting a new one, if I have to pick it up. I've tried to use all forms of selection such as: SelectFence, electCrossingWindow ... and I can't get the structure that has already been launched. Does anybody know how to solve this?

0 Likes
Accepted solutions (1)
1,574 Views
10 Replies
Replies (10)
Message 2 of 11

hosneyalaa
Advisor
Advisor

Hi

Is this possible highlighting Each network operates in a loop

 

Then confirm the names of the manholes

 

http://docs.autodesk.com/CIV3D/2016/ENU/API_Reference_Guide/?topic=html/dbed0efc-c3f0-5727-ad82-84d3...

0 Likes
Message 3 of 11

luiz.silvaNDFA2
Advocate
Advocate

Good morning hosneyalaa, I didn’t understand how to explain how to do it?

I tried to make a lisp function with 4 arguments that would be to set up a start and end point and use (ssget "_F" '(ptstart ptend)) to get the entity, but when I call it with .NET I get the message "; error: bad point argument".

0 Likes
Message 4 of 11

hosneyalaa
Advisor
Advisor

Using c# to check manhole 

From page

http://docs.autodesk.com/CIV3D/2016/ENU/API_Reference_Guide/?topic=html/dbed0efc-c3f0-5727-ad82-84d3...

 

Lisp not working to building network pipe

 

For better help 

Attached codes 

 

0 Likes
Message 5 of 11

luiz.silvaNDFA2
Advocate
Advocate

In fact the lisp function would be to check if you have a structure at the point and if you have to return that entity.

How would you send a snippet of code showing how to use this function that you informed?

0 Likes
Message 6 of 11

hosneyalaa
Advisor
Advisor
Accepted solution

See this page can help you

///https://forums.autodesk.com/t5/civil-3d-customization/select-multiple-structures-by-name/td-p/7987765

 'db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CurrentDocument.Database
        Public Function GetStructureSelectionByNames(networkId As ObjectId, names As List(Of String)) As ObjectIdCollection
            Dim ids As New ObjectIdCollection
            Using tr As Transaction = db.TransactionManager.StartTransaction
                Dim network As Network = tr.GetObject(networkId, OpenMode.ForRead)
                Dim structids As ObjectIdCollection = network.GetStructureIds()
                For Each id As ObjectId In structids
                    Dim struct As Autodesk.Civil.DatabaseServices.Structure = tr.GetObject(id, OpenMode.ForRead)
                    If names.Contains(struct.Name) Then
                        ids.Add(id)
                    End If
                Next
                tr.Commit()
            End Using
            Return ids
        End Function
0 Likes
Message 7 of 11

hosneyalaa
Advisor
Advisor
http://docs.autodesk.com/CIV3D/2016/ENU/API_Reference_Guide/?topic=html/dbed0efc-c3f0-5727-ad82-84d382dfed29.htm&_ga=2.264522319.1168093511.1619474711-1722462025.1618516829

 

12.PNG

0 Likes
Message 8 of 11

hosneyalaa
Advisor
Advisor

 

 

 

//https://spiderinnet1.typepad.com/blog/2012/09/autocad-net-editorselectfence-pointcollector.html

[CommandMethod("FenceSelectionAndPointCollector", CommandFlags.Modal)]
public static void FenceSelectionAndPointCollector_Method()
{
    Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
    try
    {
        using (PointCollector pc = new PointCollector(PointCollector.Shape.Fence))
        {
            Point3dCollection points = pc.Collect();
            PromptSelectionResult prSelRes = ed.SelectFence(points);
            if (prSelRes.Status == PromptStatus.OK)
            {
                using (SelectionSet ss = prSelRes.Value)
                {
                    if (ss != null)
                        ed.WriteMessage("\nThe SS is good and has {0} entities.", ss.Count);
                    else
                        ed.WriteMessage("\nThe SS is bad!");
                }
            }
            else
                ed.WriteMessage("\nFence selection failed!");
        }
    }
    catch (System.Exception ex)
    {
        ed.WriteMessage(Environment.NewLine + ex.ToString());
    }
}

 

 

 

//http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a9193826455f5ff-3859b43c1209703a838778b.htm,topicNumber=d0e17554

 

0 Likes
Message 9 of 11

luiz.silvaNDFA2
Advocate
Advocate

I already tried the solution "https://spiderinnet1.typepad.com/blog/2012/09/autocad-net-editorselectfence-pointcollector.html" but for some reason I don't know he doesn't select the element of Civil only cad entity , for me it would be the best solution since I don't need a lot of interaction and the intention is to create 150km of network. I will try the solution "https://forums.autodesk.com/t5/civil-3d-customization/select-multiple-structures-by-name/td-p/798776..." and give feedback if it worked.

0 Likes
Message 10 of 11

Jeff_M
Consultant
Consultant

@luiz.silvaNDFA2 as @hosneyalaa has been describing, do not try to use a selection (I'm not sure why it's not working, but it is inefficient anyway). Instead, get all of the existing structures and check against those. I suggest not mixing lisp and c# code, do everything in c#.

I would create a list of Point2d, loop through the existing structures and add the 2d location to that list. Then when creating structures from the Excel file, see if the list contains the location of the structure to insert, if so, skip that point. I would actually have a small function that checks if the 2 points are the same within a specified tolerance, say 0.5 feet. When you add a structure, be sure to add it's location to the Point2d list.

Jeff_M, also a frequent Swamper
EESignature
Message 11 of 11

luiz.silvaNDFA2
Advocate
Advocate

hosneyalaa and Jeff thanks for the help, the function worked perfectly. Thank you very much.

0 Likes