jason907238
2004-09-23, 04:42 PM
How do you pull an entity if you know it's handle?
ex.
dim myArc as AcadArc
set myArc = ????
or it it is not possible, I have actually trimmed a circle and I am now trying to find out it's end points. "myEntity.EndPoint" does not work.
Ed Jobe
2004-09-23, 04:48 PM
ThisDrawing.HandleToObject()
It would be helpful if you were to show a little more code than "myEntity.EndPoint".
jason907238
2004-09-23, 06:26 PM
Below is a simple version of what I am trying to do. I am stuck at the bottom to Testing. I trimmed a circle and now I am trying to get the arc's end points.
'before running test, draw a closed Poly Line and a Circle centered at the end
Sub Testing()
Dim myCircle As AcadCircle, myPolyLine As AcadPolyline
Dim tempObj As AcadObject, basePt As Variant
'selectCircle lets the user select a existing circle
Set myCircle = selectCircle
'set the base point to the circle's center
basePt = myCircle.Center
'delete the circle because we do not need it
myCircle.Delete
Set tempObj = selectPolyLine(basePt)
On Error GoTo NO_POLYLINE
If tempObj.EntityName = "" Then GoTo NO_POLYLINE
On Error GoTo 0
'modify drawing
Dim circle1 As AcadCircle, circle2 As AcadCircle, circle3 As AcadCircle
Dim line1 As AcadLine, tempEntity As AcadEntity, arc1 As AcadArc
Dim TrimSide As Variant, trimString As String
TrimSide = ThisDrawing.Utility.GetPoint(, "Select outside of objects.")
Set circle3 = dCircle(basePt, 2#)
Set line1 = dLine(basePt, TrimSide)
trimString = Trim(Str(TrimSide(0))) & "," & _
Trim(Str(TrimSide(1))) & "," & _
Trim(Str(TrimSide(2)))
ThisDrawing.SendCommand "_trim" & vbCr & vbCr & trimString & vbCr & vbCr
TrimSide = line1.EndPoint
If TrimSide(0) = basePt(0) And _
TrimSide(1) = basePt(1) Then TrimSide = line1.StartPoint
trimString = Trim(Str(TrimSide(0))) & "," & _
Trim(Str(TrimSide(1))) & "," & _
Trim(Str(TrimSide(2)))
Set line1 = Nothing
'it will not let me use "line1.Delete" (because you just set line1 to Nothing) Therefore use undo
ThisDrawing.SendCommand "u u "
Set tempEntity = dCircle(basePt, 2#)
ThisDrawing.SendCommand "_trim" & vbCr & vbCr & trimString & vbCr & vbCr
'I need to get the endpoints of the circle which is now an arc and then delete the arc.
'debug.Print tempEntity.EndPoing(0) 'does not work
'debug.Print tempEntity.Center(0) 'does not work
'Once you trim the circle, there is no more circle, it gets deleted and an arc is created.
'Therefore, tempEntity is no longer set.
'You could use basept to select the arc like you selected the poly earlier or use Last.
Exit Sub
NO_POLYLINE:
MsgBox "Interior object is not a Poly Line. Program Haulted!!!"
End Sub
'***Select Commands
Public Function selectCircle() As AcadObject
Dim myCircle As AcadObject, basePnt As Variant
Set selectCircle = Nothing
On Error Resume Next
RETRY:
Err = 123
While Err <> 0
Err.Clear
ThisDrawing.Utility.GetEntity selectCircle, basePnt, "Select an Circle:"
Wend
If selectCircle.EntityName = "AcDbCircle" Then
'DO NOTHING
Else
MsgBox "The object is not a Circle. Please select a Circle."
GoTo RETRY
End If
On Error GoTo 0
End Function
Public Function selectPolyLine(basePnt As Variant) As AcadEntity ' AcadObject 'AcadPolyline
Dim SS As AcadSelectionSet, myObj As AcadEntity ' AcadObject
On Error Resume Next
Set SS = ThisDrawing.SelectionSets.Add("SS001")
SS.SelectAtPoint (basePnt)
Set selectPolyLine = SS.Item(0)
SS.Delete
' Set selectPolyLine = myObj
' selectPolyLine.Layer = "hello"
If Err = 0 Then
If selectPolyLine.EntityName = "AcDbPolyline" Then
'do nothing
Else
Set selectPolyLine = Nothing
Set selectPolyLine = SS
End If
End If
End Function
'***Drawing commands
Public Function dLine(FirstPoint As Variant, SecondPoint As Variant) As AcadLine
Set dLine = ThisDrawing.ModelSpace.AddLine(FirstPoint, SecondPoint)
End Function
Public Function dCircle(CenterPoint As Variant, CircleRadius As Double) As AcadCircle
Set dCircle = ThisDrawing.ModelSpace.AddCircle(CenterPoint, CircleRadius)
End Function
degrawmd
2004-09-23, 09:54 PM
Try using the following with the actual handle you have for the object. If you know the actual object type you can also dimension it as such.
Dim SomeObj As AcadObject
Set SomeObj = ThisDrawing.HandleToObject("3dch5")
This Will make SomeObj = to the object of the noted handle. So if the handle belongs to a circle SomeObj will be that circle etc. This is good because handles are good from session to session.
Ed Jobe
2004-09-23, 10:03 PM
See my comments in Red within your post.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.