PDA

View Full Version : Selecting Entities



jason907238
2004-09-22, 11:24 PM
How can I select an entity with out prompting the user if I know a point which the object crosses.

ThisDrawing.Utility.GetEntity selectObject, basePnt, "Select an object"

This prompts the user. I already know what the basePnt is.

RobertB
2004-09-23, 02:33 AM
You cannot, with VBA. Can you take another approach?

degrawmd
2004-09-23, 04:40 AM
You can create a selection set and then add to that selection set using the select method "SelectAtPoint" and then specify your point. This then will put your entity into the selection set as Item (0). you can then manipulate that entity by setting a dimensioned object as follows

Dim SS as AcadSelectionSet
Set SS = ThisDrawing.SelectionSets.Add("SS001")
SS.SelectAtPoint(P1)
Dim MyObj As AcadObject
Set MyObj = SS.Item(0)
SS.Delete

MyObj is now the entity you wanted without prompting anyone for input because you know where P1 is and can define it.

MyObj can now be moved, copies etc as an entity.
You actually can dimension MyObj as what it really is like an entity or a 3D solid or Polyline, but using the object allows some flexibility if the object type is not always the same.

jason907238
2004-09-23, 01:47 PM
That worked but now I have another issue. I am getting a mismatch type error when trying pull the AcadPolyLine out of the selection set.


Public Function selectPolyLine(basePnt As Variant) As AcadPolyline
Dim SS As AcadSelectionSet, myObj As AcadObject

Set SS = ThisDrawing.SelectionSets.Add("SS001")
SS.SelectAtPoint (basePnt)

'Set myObj = SS.Item(0)
'Set selectPolyLine = myObj
Set selectPolyLine = SS.Item(0)
SS.Delete
End Function

ntaylor
2004-09-23, 11:59 PM
Try this.


Public Function selectPolyLine(basePnt As Variant) As AcadPolyline
Dim SS As AcadSelectionSet, myObj As AcadObject
Set SS = ThisDrawing.SelectionSets.Add("SS001")
SS.SelectAtPoint (basePnt)
If SS.Count = 0 Then
MsgBox "Nothing was selected"
Else
Set myObj = SS.Item(0)
If TypeOf myObj Is AcadPolyline Then
Set selectPolyLine = myObj
Else
MsgBox "Object is a " & myObj.ObjectName
End If
End If
SS.Delete
End Function