Message 1 of 6
Getting the insertion point of a text item

Not applicable
04-11-2001
08:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all!
I am trying to write some code to do the following:
This is the order they will happen as well!
1. Allow the user to select an existing text string in the
drawing.
drawing.
2. Allow the user to select a closed polyline.
3. Get the area of the closed polyline and send it to a string
variable.
variable.
4. Place a new line of text exactly one line of text below the one the user
picked. (this new line of text will match the properties of the previous
selected text. The contents of this new line of text will be from the
string variable noted in #3 above.
picked. (this new line of text will match the properties of the previous
selected text. The contents of this new line of text will be from the
string variable noted in #3 above.
I have almost all of this working except that I can not get the point to be
the text insertion point and I am not sure how to force the new line of text
onto the next line. I also have not messed with the text properties.
Everything else works though. As it is now it wont insert the new line of text
because of the insertion point problem.
the text insertion point and I am not sure how to force the new line of text
onto the next line. I also have not messed with the text properties.
Everything else works though. As it is now it wont insert the new line of text
because of the insertion point problem.
Here is the code:
Private Sub cmdRun_Click()
Dim Ent As AcadEntity
Dim Ent2 As AcadEntity
Dim Pt As Variant
Dim
Pt2 As Variant
Dim Cnt As Integer
Dim Cnt2 As Double
Dim strCnt As
String
Dim objText As acadText
Dim pointObj As AcadPoint
Dim objlayer
As AcadLayer
Dim strlayerName As String
Dim strText As String
Dim Ent2 As AcadEntity
Dim Pt As Variant
Dim
Pt2 As Variant
Dim Cnt As Integer
Dim Cnt2 As Double
Dim strCnt As
String
Dim objText As acadText
Dim pointObj As AcadPoint
Dim objlayer
As AcadLayer
Dim strlayerName As String
Dim strText As String
On Error Resume Next
oldlayer =
ThisDrawing.ActiveLayer.Name
strlayerName = "NG_TEXT"
Set objlayer =
ThisDrawing.Layers(strlayerName)
oldlayer =
ThisDrawing.ActiveLayer.Name
strlayerName = "NG_TEXT"
Set objlayer =
ThisDrawing.Layers(strlayerName)
If objlayer Is Nothing Then
MsgBox "Layer '" &
strlayerName & "' does not exist. Please create it before
continuing."
Exit Sub
Else
ThisDrawing.ActiveLayer = ThisDrawing.Layers("NG_TEXT")
End If
MsgBox "Layer '" &
strlayerName & "' does not exist. Please create it before
continuing."
Exit Sub
Else
ThisDrawing.ActiveLayer = ThisDrawing.Layers("NG_TEXT")
End If
Me.Hide
ThisDrawing.Utility.GetEntity Ent2, Pt2, "Select the matching Text: "
Ent2.Highlight
True
If Err
Then
Ent2.Highlight False
End
If
If
TypeOf Ent2 Is acadText Then
Set
objText = Ent2
Set Pt2 =
objText.insertionPoint 'HERE IS WHERE THE PROBLEM IS. i CAN NOT SEEM TO FIGURE
THIS OUT.
Debug.Print
Ent2.ObjectName 'THE OBJECT NAME COMES UP AS AcDcText, SO IT IS ASIGNING IT
CORRECTLY.
End If
True
If Err
Then
Ent2.Highlight False
End
If
If
TypeOf Ent2 Is acadText Then
Set
objText = Ent2
Set Pt2 =
objText.insertionPoint 'HERE IS WHERE THE PROBLEM IS. i CAN NOT SEEM TO FIGURE
THIS OUT.
Debug.Print
Ent2.ObjectName 'THE OBJECT NAME COMES UP AS AcDcText, SO IT IS ASIGNING IT
CORRECTLY.
End If
On Error Resume Next
Do
Me.Hide
ThisDrawing.Utility.GetEntity Ent,
Pt, "Select the desired polyline: "
Ent.Highlight
True
If Err
Then
Ent.Highlight
False
If
ThisDrawing.GetVariable("errno") = "7"
Then
Err.Clear
Else
Err.Clear
Exit Do
End If
End
If
If TypeOf Ent Is AcadLWPolyline
Then
Set ObjPly =
Ent
If
ObjPly.Closed = True
Then
If
ObjPly.area > 0
Then
Cnt2 =
ObjPly.area
Cnt2 = Round(Cnt2,
0)
strCnt =
Cnt2
strCnt = Format(strCnt,
"##.0")
strCnt = Round(strCnt /
9)
End
If
Else
'If the entity selected is not a closed polyline then send the following
message.
MsgBox "The Polyline you selected is not closed. Please close it before " &
_
"continuing. This command will exit.
"
Exit
Do
End
If
Else
'If the entity selected is not a roompoly then
send the following message.
MsgBox
"The object you selected is not a Polyline. This command will exit.
"
Exit Do
End If
Do
Me.Hide
ThisDrawing.Utility.GetEntity Ent,
Pt, "Select the desired polyline: "
Ent.Highlight
True
If Err
Then
Ent.Highlight
False
If
ThisDrawing.GetVariable("errno") = "7"
Then
Err.Clear
Else
Err.Clear
Exit Do
End If
End
If
If TypeOf Ent Is AcadLWPolyline
Then
Set ObjPly =
Ent
If
ObjPly.Closed = True
Then
If
ObjPly.area > 0
Then
Cnt2 =
ObjPly.area
Cnt2 = Round(Cnt2,
0)
strCnt =
Cnt2
strCnt = Format(strCnt,
"##.0")
strCnt = Round(strCnt /
9)
End
If
Else
'If the entity selected is not a closed polyline then send the following
message.
MsgBox "The Polyline you selected is not closed. Please close it before " &
_
"continuing. This command will exit.
"
Exit
Do
End
If
Else
'If the entity selected is not a roompoly then
send the following message.
MsgBox
"The object you selected is not a Polyline. This command will exit.
"
Exit Do
End If
Loop
strText = strCnt
Debug.Print strText
If optLeft.Value = True
Then
Set pointObj =
ThisDrawing.ModelSpace.AddPoint(Pt2)
pointObj.Color = acRed
Set objText
= ThisDrawing.ModelSpace.AddText(strText, pointObj,
8)
objText.Alignment =
acAlignmentLeft
objText.TextAlignmentPoint = pointObj
End If
Then
Set pointObj =
ThisDrawing.ModelSpace.AddPoint(Pt2)
pointObj.Color = acRed
Set objText
= ThisDrawing.ModelSpace.AddText(strText, pointObj,
8)
objText.Alignment =
acAlignmentLeft
objText.TextAlignmentPoint = pointObj
End If
If optMidCent.Value = True
Then
Set pointObj =
ThisDrawing.ModelSpace.AddPoint(Pt2)
pointObj.Color = acRed
Set objText
= ThisDrawing.ModelSpace.AddText(strText, pointObj,
8)
objText.Alignment =
acAlignmentMiddleCenter
objText.TextAlignmentPoint = pointObj
End If
Then
Set pointObj =
ThisDrawing.ModelSpace.AddPoint(Pt2)
pointObj.Color = acRed
Set objText
= ThisDrawing.ModelSpace.AddText(strText, pointObj,
8)
objText.Alignment =
acAlignmentMiddleCenter
objText.TextAlignmentPoint = pointObj
End If
End Sub
Any suggestions?
Thanx,
Rob