Hello All,
I have developed a script that creates a new rectangle into an existing shapefile (lease_boundary) based on offsets the user enters in. The rectangle seems to draw correctly but I can not select it afterwards. I am also using another script to create a sample grid and it does not work on it because it lists the area as negative...
I am scratching my head on this one..... any help would be greatly appreciated.:)
The code is:
Sub CreateLease
Dim objNewPoly
Dim dblX
Dim dblY
Dim strOffSetTop
Dim objToolButton
Dim blnLyrExists
Dim pThePage
Dim objFrmNoffset
Dim objFrmSoffset
Dim objFrmWoffset
Dim objFrmEoffset
Dim objFrmRadioMeters
Dim objFrmRadioFeet
'Get a reference to the tool button object
Set objToolButton = ThisEvent.Object
'Initialize blnLyrExists flag to False
blnLyrExists = False
'If lease boundary layer exists, set the blnLyrExists flag to true
Dim objLyr
For Each objLyr in Map.Layers
If StrComp (objLyr.Name, "lease_boundary", 1) = 0 Then
blnLyrExists = True
Exit For
End If
Next
'If lease boundary layer does not exist:
'Notify the user, return the tool button to its original state, and exit.
If Not blnLyrExists Then
MsgBox "The lease boundary is not present in the current map.", vbExclamation, "Layer not present"
objToolButton.Click
Exit Sub
End If
'Check if the layer can be made editable
If Not Application.Map.Layers("lease_boundary").CanEdit Then
MsgBox "Lease boundary cannot be edited.",vbExclamation,"Error"
Exit Sub
End If
'If the layer is not already editable, make it editable
If Not Application.Map.Layers("lease_boundary").Editable Then
Application.Map.Layers("lease_boundary").Editable = True
End If
'Create a new rectangle object
Set objNewPoly = Application.CreateAppObject("rectangle")
Set objFrmRadioMeters = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("rdoMeters")
Set objFrmRadioFeet = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("rdoFeet")
'Populate the new polygon X and Y from current GPS X and Y
If objFrmRadioMeters.value = True Then
Set objFrmNoffset = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("txtNoffset")
objFrmSoffset = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("txtSoffset")
objFrmWoffset = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("txtWoffset")
objFrmEoffset = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("txtEoffset")
dblX = Map.PointerX
dblY = Map.PointerY
objNewPoly.center.X = dblX
objNewPoly.center.Y = dblY
objNewPoly.top = dblY+objFrmNoffset
objNewPoly.left = dblX+objFrmEoffset
objNewPoly.bottom = dblY-objFrmSoffset
objNewPoly.right = dblX-objFrmWoffset
Application.Map.AddFeature (objNewPoly), False
Application.ExecuteCommand ("zoomfullextent")
Set objnewPoly = Nothing
Else
Set objFrmNoffset = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("txtNoffset")
objFrmSoffset = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("txtSoffset")
objFrmWoffset = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("txtWoffset")
objFrmEoffset = Applets("DSA_Applet").Forms("frmLeaseBoundary").Pages("Page1").Controls("txtEoffset")
dblX = Map.PointerX
dblY = Map.PointerY
objNewPoly.center.X = dblX
objNewPoly.center.Y = dblY
objNewPoly.top = dblY+objFrmNoffset*0.3048
objNewPoly.left = dblX+objFrmEoffset*0.3048
objNewPoly.bottom = dblY-objFrmSoffset*0.3048
objNewPoly.right = dblX-objFrmWoffset*0.3048
Application.Map.AddFeature (objNewPoly), False
Application.ExecuteCommand ("zoomfullextent")
Set objnewPoly = Nothing
End If
End Sub