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.
|
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.
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.
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
Try this.
Code: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