Author Topic: esc key to end loop?  (Read 4166 times)

0 Members and 1 Guest are viewing this topic.

jcoon

  • Newt
  • Posts: 157
esc key to end loop?
« on: August 24, 2011, 09:36:33 AM »


I have a simple sta/off mtext label test that I can't seem to get to ESCAPE KEY or space bar to reload form.
The test labels selected picked points from an alignment. what I can't get to work is how to hit the escape key or scape bar to exit the loop and reload the form so I can label new points from another alignment.

does anyone have a link that show how I can hit an esc key or space bar to end the loop and  show the form.

I've 'If Chr(vbKeyEscape) = 27 Then
'ThisDrawing.SendCommand "ESC" & vbCr
'Exit Do
'UserForm1.Show
'End If



Thanks

John Coon



Do
   
basePnt = ThisDrawing.Utility.GetPoint(, "Select Location to Label: ")
oAlignment.PointLocation basePnt(0), basePnt(1), testStax, testStay
oAlignment.StationOffset basePnt(0), basePnt(1), StaValue, OffValue
       
strOFF = Format(OffValue, strFormat)
strStation = oAlignment.GetStationStringWithEquations(StaValue)
   
strText = "STA: " & (strStation) & "\P" _
           & "OFF: " & (strOFF) & "\P" _

If StaValue <> 0 Then
Set mtxtLabel = ThisDrawing.ModelSpace.AddMText(basePnt, dblWidth, strText)
mtxtLabel.Height = dblHeight
mtxtLabel.Rotation = dblRot
End If
mtxtLabel.Update
       
 
Loop

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: esc key to end loop?
« Reply #1 on: August 24, 2011, 09:50:40 AM »
Maybe something like this will get you going in the right direction...

Code: [Select]
Public Sub GetPointLoop()
    Dim SomePoint As Variant
   
    On Error Resume Next
    Do
        SomePoint = ThisDrawing.Utility.GetPoint(, "Select a point...")
        If Err.Number <> 0 Then
            Exit Do
        Else
            ThisDrawing.Utility.Prompt "Do something here..."
        End If
    Loop
   
    MsgBox "Show form"
End Sub
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

jcoon

  • Newt
  • Posts: 157
Re: esc key to end loop?
« Reply #2 on: August 24, 2011, 10:33:37 AM »
Matt,

Thanks for the help. 

if I add the
If Err.Number <> 0 Then
            Exit Do
end if

it labels one label then reloads the form, before it labeled as many picked location but nevered exited the loop without crashing.

John



jcoon

  • Newt
  • Posts: 157
Re: esc key to end loop?
« Reply #4 on: August 24, 2011, 11:09:19 AM »
I'll see if I can incorporate Matt's or jgr's post

just looking at jgr's I think that might be out of my league for a while


Thanks guys

John

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: esc key to end loop?
« Reply #5 on: August 24, 2011, 11:43:17 AM »
Code: [Select]
Option Explicit

Dim SomePoint As Variant


Public Sub GetPointLoop()
    On Error Resume Next
    Do
        SomePoint = ThisDrawing.Utility.GetPoint(, "Select a point...")
        If Err.Number <> 0 Then
            Exit Do
        Else
            AddText
        End If
    Loop
   
    MsgBox "Show form"
End Sub


Private Sub AddText()
    Dim ptEN(0 To 2) As Double
    Dim objText As AcadText
   
    ptEN(0) = SomePoint(0)
    ptEN(1) = SomePoint(1)
    ptEN(2) = 0
   
    Set objText = ThisDrawing.ModelSpace.AddText("THIS IS A TEST", ptEN, "12")
    objText.Update
End Sub
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

jcoon

  • Newt
  • Posts: 157
Re: esc key to end loop?
« Reply #6 on: August 24, 2011, 11:56:56 AM »
Matt,

Ok ...I think I git it from this post.  Funny....I found an old land desktop routine that did basically the same thing as the C3D and it works fine, and all it has was the On Error GoTo Bye.

I'll make the change to add format from your last post.

Thanks for all your help!

John


' old land desktop

    On Error GoTo Bye
  Do
   Dim varDataPnt1 As Variant
  varDataPnt1 = ThisDrawing.Utility.GetPoint(Prompt:=vbCrLf & "Select Next Point to Label: ")
  objAlign.StationOffset varDataPnt1(0), varDataPnt1(1), dblSta, dblOff, dblDir
 
 
    strStaFormat = "#0.00"
    strOffFormat = "#0.00"
    strSta = Left(Format(dblSta, strStaFormat), Len(Format(dblSta, strStaFormat)) - 5) _
           & "+" & Right(Format(dblSta, strStaFormat), 5)
   
    If dblOff > 0 Then
      strOff = Format(dblOff, strOffFormat) & "' RT"
    Else
      strOff = Right(Format(dblOff, strOffFormat), (Len(Format(dblOff, strOffFormat)) - 1)) _
        & "' LT"
    End If
     
   strText = "STA: " & (strSta) & "\P" _
            & "OFF: " & (strOff) & "\P" _
   
    Set mtxtLabel = ThisDrawing.ModelSpace.AddMText(varDataPnt1, dblWidth, strText)
    mtxtLabel.Height = dblHeight
    mtxtLabel.Rotation = dblRot
    mtxtLabel.Update
Loop
Bye:
Show


jcoon

  • Newt
  • Posts: 157
Re: esc key to end loop?
« Reply #7 on: August 30, 2011, 04:33:45 PM »
I was able to add some of the info from Matt's post to work with my small routine. I adjusted a existing simple x,y label routine that worked fine and generated an error on the right click or esc and reloaded the form just as I wanted, however I still couldn't get the civil 3D alignment routine to esc to the userform on an error without crashing the drawing. I looked at it again this morning after returning back to work from the hurricane.

I added 
If StaValue = 0 Then
GoTo Bye
End If

which generates the error becuase the selected location was not within the alignment and it reloaded the form just like I needed

Thanks for all your help Matt W

John