I have refined this basic macro over years after I inherited it way back in V8 2004 and works almost perfectly but I cannot work out why/ how to get text to come out on the named level Grid.
The lines land on grid level even if grid level did not t exist before the macro ran as it creates the Grid level first but the text always ends up on level called default...
what do I need to add or change? ..as you can see I've added the active level Grid a few times in an attempt to get it to work..
===========================================================
Create & annotate N& E grid within a block element
' rebuilt by Lorys Lea so it now works
' with v8i and overrides and WPmode
'dimension shared variables
Dim point As MbePoint, point1 as MbePoint, point2 As MbePoint
Dim filepos as long
Dim eastint as Long, westint as long, northint as long, southint as long
Dim interval as string, prefix as string
Dim inter as Double
Dim i as Long
'sub routine to place line and text
Sub LineText()
'store file pointer of line for text placement
filepos = MbeDgninfo.endOfFile
MbeSendCommand "Level create Grid;LV=Grid"
MbeSendCommand "PLACE LINE "
MbeSendDataPoint point1
MbeSendDataPoint point2
MbeSettings.textJustification = MBE_LeftBottom
MbeSendCommand "LV=Grid"
MbeSendCommand "TEXTSTYLE ACTIVE none"
MbeSendCommand "LV=Grid;PLACE TEXT ABOVE"
mbesendkeyin Prefix & Format$(int(i/1000),"0000") & " " & Format$((i mod 1000),"000") & " "
MbeLocateElement filepos, filepos, 0, point1
MbeLocateElement filepos, filepos, 0, point2
MBeSettings.textJustification = MBE_RightBottom
MbeSenddataPoint point2
End Sub
Sub main
'dimesnion variables
Dim element as New MbeElement
Dim oldcolor as Integer
Dim oldfont as Integer
Dim oldangle as Integer
Dim oldtextht as Integer
Dim oldtextwd as Integer
Dim oldtextjust as Integer
Dim oldlevel as Integer
Dim oldlinestyle as long
Dim oldweight as Integer
Dim oldtolerance as Integer
Dim west as Double, east as Double, north as Double, south as Double
'store existing settings
oldColor = MbeSettings.color
oldlevel = MbeSettings.level
oldlinestyle = MbeSettings.lineStyle
oldweight = MbeSettings.weight
oldangle = MbeSettings.angle
oldtolerance = Mbestate.LocateTolerance
oldtextht = MbeSettings.textheight
oldtextwd = MbeSettings.textwidth
oldtextjust = MbeSettings.textJustification
'cancel existing command
MbeSendCommand "NULL"
'prompt user for first point
MbeWriteMessage "Define Grid Area by placing a DATA point on NW corner...(reset to exit)"
MbeGetInput MBE_DataPointInput,MBE_ResetInput
If MbeState.InputType = MBE_DataPointInput Then
If MbeState.getInputDatapoint (point) = MBE_SUCCESS Then
west = point.x
north = point.y
End if
Else 'exit if not Data Point
MbeSendCommand "CHOOSE ELEMENT "
mbeWritemessage "GRID ABORTED"
Exit sub
End if
'prompt user for second point
MbeWriteMessage "Place a DATA point on the SE corner...(reset to exit)"
MbeGetInput MBE_DataPointInput,MBE_ResetInput
If MbeState.InputType = MBE_DataPointInput Then
If MbeState.getInputDatapoint (point) = MBE_SUCCESS Then
east = point.x
south = point.y
if east < west then
MbeMessagebox "East Must be Greater Than West"
exit sub
end if
if north < south then
MbeMessageBox "North Must be Greater Than South"
Exit sub
end if
End if
Else 'exit if not Data Point
MbeSendCommand "CHOOSE ELEMENT "
mbeWritemessage "GRID ABORTED"
Exit sub
End if
MbeWriteMessage " "
interval = "100"
'prompt user for interval Remember use drawing scale divided by 10
interval = MbeInputBox ("What is the grid interval (in metres)?",interval,"GRID INTERVAL?")
inter = Val(Interval)
'check that greater than 0
if inter <= 0 Then
MbeMessageBox "Interval is Invalid!!!"
Exit sub
End if
westint = int(west)
southint = int(south)
northint = int(north)
eastint = int(east)
'change text to command input wpmode
MbeSetAppVariable "MGDSHOOK", "userPrefsP->textEditorStyle", 2#
MbeSendCommand "LV= Grid"
MbeSettings.color =14
Mbesettings.linestyle = 0
Mbesettings.weight = 0
MbeSettings.font =1028
MbeSettings.angle = 0
MbeSettings.textheight = inter/50
MbeSettings.textwidth = inter/50
MbeSettings.textLineSpacing = 0.66 * inter/50
'set variables for vertical lines
Point1.y = south
Point2.y = north
prefix = "E "
For i = westint to eastint
If i mod inter = 0 Then
Point1.x = i
point2.x = i
'call sub to place lines and text
call LineText
end if
Next i
'set variables for horizontal lines
Point1.x = west
Point2.x = east
prefix = "N "
For i = southint to northint
If i mod inter = 0 Then
Point1.y = i
point2.y = i
'call sub to place lines and text
call LineText
end if
Next i
'restore original settings
mbesendcommand "null"
MbeSetAppVariable "MGDSHOOK", "userPrefsP->textEditorStyle", 4#
Mbesettings.level = oldlevel
MbeSettings.color = oldcolor
MbeSettings.weight = oldweight
MbeSettings.linestyle = oldlinestyle
MbeSettings.angle = oldangle
MbeSettings.textheight = oldtextht
MbeSettings.textwidth = oldtextwd
MbeSettings.textJustification = oldtextjust
MbeState.noElementDisplay = 0
mbeWritemessage "Grid Done"
End Sub