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

Select an Object (Point)

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
dynamicscope
1423 Views, 7 Replies

Select an Object (Point)

I have a DataGridView that lists "point coordinates" in a row (the points are drawn on the drawing).

When I click a row of the DataGridView, I want to select that point refering to the coordinate. (deselect any other selection before selecting a point)

Below is what I have implented, but it does not select the point.

 

internal static void SelectPoint(double x, double y)
{
	Document doc = Application.DocumentManager.MdiActiveDocument;
	Editor ed = doc.Editor;

	Point3d p1 = new Point3d(x - 0.01, y - 0.01, 0);
	Point3d p2 = new Point3d(x + 0.01, y + 0.01, 0);

	TypedValue[] values = { new TypedValue((int)DxfCode.Start, "POINT") };
	SelectionFilter sf = new SelectionFilter(values);
	PromptSelectionResult psr = ed.SelectCrossingWindow(p1, p2, sf);
	SelectionSet ss = psr.Value;

	doc.SendStringToExecute("select p  ", true, false, false);
}

 

Note that the arguments x and y are the coordinate of the point.

What could be wrong?

 

Thanks

7 REPLIES 7
Message 2 of 8
amanero
in reply to: dynamicscope

You could select the objects with the editor this way:

 

        internal static void SelectPoint(double x, double y)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            Point3d p1 = new Point3d(x - 0.01, y - 0.01, 0);
            Point3d p2 = new Point3d(x + 0.01, y + 0.01, 0);

            TypedValue[] values = { new TypedValue((int)DxfCode.Start, "POINT") };
            SelectionFilter sf = new SelectionFilter(values);
            PromptSelectionResult psr = ed.SelectCrossingWindow(p1, p2, sf);
            SelectionSet ss = psr.Value;

            //doc.SendStringToExecute("_select p  ", true, false, false);
            ed.SetImpliedSelection(psr.Value.GetObjectIds());

        }

 

 

Luis Alberto Manero, Geograma.com
Message 3 of 8

this does not work for me can you see anything wrong with mine. The issue is on the 2nd promptselectionresult not finding anything and returning and error status

 

Public Shared Sub removePoles()
On Error GoTo errorHandle

'' Get the current Document & Database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database

'' Get the current document editor
Dim acDocEd As Editor = acDoc.Editor

'' Create a TypedValue array to define the filter criteria
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "PLOH*"), 0)

'' Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)

'' Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.SelectAll(acSelFtr)

'' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then

'' Get the selected objects
Dim acSSet1 As SelectionSet
acSSet1 = acSSPrompt.Value

'' Make a second Selection Set
Dim acSSet2 As SelectionSet

'' Append the selected objects to the ObjectIDCollection
Dim acObjIDColl As ObjectIdCollection = New ObjectIdCollection
acObjIDColl = New ObjectIdCollection(acSSet1.GetObjectIds())

Dim acObjIDColl2 As ObjectIdCollection = New ObjectIdCollection

'' Iterate through all poles
For i = acObjIDColl.Count - 1 To 0 Step -1

Dim p1 As Point3d
Dim p2 As Point3d
Dim acEnt As Entity

'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction

'' Get the objectID from found object collection id's
Dim acObjID As ObjectId = acObjIDColl.Item(i)

'' Get the entity from object id
acEnt = acTrans.GetObject(acObjID, OpenMode.ForRead)

'' Dispose Transaction
End Using

'' Check if type of entity is a block reference
If TypeOf (acEnt) Is BlockReference Then

'' Cast to block reference
Dim acBlkRef As BlockReference = DirectCast(acEnt, BlockReference)

'' Get Crossing window of block reference
p1 = New Point3d(acBlkRef.Position.X - 0.01, acBlkRef.Position.Y - 0.01, acBlkRef.Position.Z)
p2 = New Point3d(acBlkRef.Position.X + 0.01, acBlkRef.Position.Y + 0.01, acBlkRef.Position.Z)

End If

'' Select anything found at the sampe points
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "*"), 0)

'' Create a filter from type value
acSelFtr = New SelectionFilter(acTypValAr)

'' Get all objects in cross window using filter and select anything at the same point
acSSPrompt = acDocEd.SelectCrossingWindow(p1, p2, acSelFtr)

'' Check if prompt is good and items were found
If acSSPrompt.Status = PromptStatus.OK Then

'' Apply results to make a selection set
acSSet2 = acSSPrompt.Value

'' Get objects Id's from new Selection set
acObjIDColl2 = New ObjectIdCollection(acSSet2.GetObjectIds())

'' Check if one or more items were found
If acObjIDColl2.Count = 1 Then
'' Clear out block reference
acObjIDColl2.RemoveAt(0)
'' Delete itrm from selection set one
'acSSet1.Item(i).Delete()
Else
'' Clear selection Set 2
End If
End If
Next


'' Delete both selection setes
'acSSet1.Delete()
'acSSet2.Delete()
End If

Exit Sub
errorHandle:
MsgBox(Err.Description & vbCrLf & "Error number " & Err.Number, vbExclamation, "Error")
Resume Next
End Sub

Message 4 of 8
amanero
in reply to: dynamicscope

Hello,

 

My very first question is if the block is visible on screen when the selection is made because if it is outside the screen, that could be the problem.

 

Another question: What error do you get?

Luis Alberto Manero, Geograma.com
Message 5 of 8

error -5001 its the promptstatus error

so this code happens before i use "zoom e" command, I query an attached dwg before this and since the first prompt works why wouldn't the second? because its a cross window?
Message 6 of 8

so what do i do to fix the visibility on screen or is there another way to solve my issue?
Message 7 of 8
amanero
in reply to: dynamicscope

Hello,

 

Did you make a try after doing a "zoom e"?

 

If you can, attach a sample drawing with the problem to make some tests to see if I can see anything.

Luis Alberto Manero, Geograma.com
Message 8 of 8

i have attached a dwg and since this is done in the same command as a query the dwg then "zoom e" must be done after the command is over which is after i try to remove the layers with "PLOH*"

 

this is what i have so far, it removes some but does not completly remove them all

 

Public Shared Sub removePoles()
On Error GoTo errorHandle

'' Get the current Document, Editor, & Database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acDocEd As Editor = acDoc.Editor
Dim acCurDb As Database = acDoc.Database

'' Create a TypedValue array to define the filter criteria
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "PLOH*"), 0)

'' Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)

'' Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult = acDocEd.SelectAll(acSelFtr)

'' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then

'' Get the selected objects
Dim acSSet As SelectionSet = acSSPrompt.Value

'' Step through each layer and update those not connected to another device
For Each acObjId As ObjectId In acSSet.GetObjectIds()

'' Start Transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction

'' Get entity of object
Dim acEnt As Entity = acTrans.GetObject(acObjId, OpenMode.ForRead)

'' Check type of entity
If TypeOf (acEnt) Is BlockReference Then

'' Case Entity to Block Reference
Dim acBlkRef As BlockReference = DirectCast(acEnt, BlockReference)

'' Select anything found at the sampe points
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "*"), 0)

'' Create a filter from type value
acSelFtr = New SelectionFilter(acTypValAr)

'' Get all objects in cross window using filter and select anything at the same point
acSSPrompt = acDocEd.SelectCrossingWindow(acBlkRef.Position, acBlkRef.Position, acSelFtr)

'' Check if prompt is good and items were found
If acSSPrompt.Status = PromptStatus.OK Then

'' Apply results to make a selection set
Dim acSSet2 As SelectionSet = acSSPrompt.Value

'' Check if one or more items were found
If acSSet2.Count = 1 Then
'' Upgrade to Write-able
acBlkRef.UpgradeOpen()

'' Erase block reference from drawing
acBlkRef.Erase()
Else
For Each obj As ObjectId In acSSet2.GetObjectIds
Dim Ent As Entity = acTrans.GetObject(obj, OpenMode.ForRead)

Next
End If

'' Set selection set 2 to nothing
acSSet2 = Nothing

ElseIf acSSPrompt.Status = PromptStatus.Error Then
acDocEd.WriteMessage("FAILED to auto select * w/ PLOH* " & vbCrLf)
Exit Sub
End If
End If
acTrans.Commit()
End Using
Next


'' Delete both selection setes
'acSSet1.Delete()
'acSSet2.Delete()
End If

Exit Sub
errorHandle:
MsgBox(Err.Description & vbCrLf & "Error number " & Err.Number, vbExclamation, "Error")
Resume Next
End Sub

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost