[No Subject]

[No Subject]

Anonymous
Not applicable
227 Views
0 Replies
Message 1 of 1

[No Subject]

Anonymous
Not applicable


I am having trouble looping through my code until the
user is done with the command.  What this routine does is to ask the user
what axis is being halved (i.e. in which axis is the diameter) and then
continues to ask the user for the coordinates until the user escapes, or enters
a null value.


The code works fine the first time through, but on
the first loop (second time asking for the coordinates), I get an
eNotOpenForWrite error and AutoCAD crashes.  Can anyone point me in the
direction that's causing this?


Below is my code. Obviously, one would have to create
a CommandMethod before running this, but I figured I didn't have to supply it as
that code does is point to this code.


 


Imports acadApp =
Autodesk.AutoCAD.ApplicationServices


Imports acadDB =
Autodesk.AutoCAD.DatabaseServices


Imports acadED =
Autodesk.AutoCAD.EditorInput


Imports acadGo = Autodesk.AutoCAD.Geometry


Imports acadRT = Autodesk.AutoCAD.Runtime


Module Coordinates


Dim CurrentStack As
System.Diagnostics.StackTrace


Public Sub Coordinates()


' declare local variables


Dim doc As acadApp.Document = _



size=2>acadApp.Application.DocumentManager.MdiActiveDocument


Dim ed As acadED.Editor = doc.Editor


Dim db As acadDB.Database = doc.Database


Dim tr As Transaction =
db.TransactionManager.StartTransaction


Dim btr As BlockTableRecord


Dim docLock As acadApp.DocumentLock = _


doc.LockDocument(acadApp.DocumentLockMode.AutoWrite,
"Coords", "Coords", True)


'Dim docLock As acadApp.DocumentLock =
doc.LockDocument


Dim ValueEntered As Boolean


Dim pdMode As Integer =
ed.Document.Database.Pdmode


Dim pdSize As Double =
ed.Document.Database.Pdsize


Dim ptOrigin As acadGo.Point3d =
ed.Document.Database.Ucsorg


Dim UCSIcon As Object =
acadApp.Application.GetSystemVariable("UCSICON")


Try


acadApp.Application.SetSystemVariable("PDMODE",
35)


acadApp.Application.SetSystemVariable("PDSIZE",
0.25)


Begin:


acadApp.Application.SetSystemVariable("UCSICON",
1)


ValueEntered = True


btr = DirectCast( _


tr.GetObject(doc.Database.CurrentSpaceId,
acadDB.OpenMode.ForWrite), _


BlockTableRecord)


' Prompt the user to input any of the
keywords


Dim keyOptions As acadED.PromptKeywordOptions =
_


New acadED.PromptKeywordOptions(Environment.NewLine +
_


"Select the axis to be halved: ")


keyOptions.Keywords.Add("X")


keyOptions.Keywords.Add("Y")


keyOptions.Keywords.Add("None")


keyOptions.Keywords.Add("All")


keyOptions.Keywords.Add("Done")


keyOptions.Keywords.Default =
My.Settings.AxisToHalve


Dim HalfAxis As acadED.PromptResult =
ed.GetKeywords(keyOptions)


If (HalfAxis.Status = PromptStatus.Keyword) Or
_


(HalfAxis.Status = PromptStatus.OK) Then


If HalfAxis.StringResult <> "Done"
Then


' Store default AxisToHalve


My.Settings.AxisToHalve =
HalfAxis.StringResult


Do Until ValueEntered = False


' Get the X coordinate


Dim pointX As acadED.PromptDoubleResult =
_


ed.GetDouble(Environment.NewLine + "Enter X
coordinate: ")


If (pointX.Status <> PromptStatus.OK)
Then


ValueEntered = False


'Exit Do


End If


' Get the Y coordinate


Dim pointY As acadED.PromptDoubleResult =
_


ed.GetDouble(Environment.NewLine + "Enter Y
coordinate: ")


If (pointY.Status <> PromptStatus.OK)
Then


ValueEntered = False


'Exit Do


End If


Dim myPoint As acadGo.Point3d


Select Case HalfAxis.StringResult


Case "X"


myPoint = New acadGo.Point3d(pointX.Value / 2,
pointY.Value, 0)


Case "Y"


myPoint = New acadGo.Point3d(pointX.Value,
pointY.Value / 2, 0)


Case "All"


myPoint = New acadGo.Point3d(pointX.Value / 2,
pointY.Value / 2, 0)


Case Else


myPoint = New acadGo.Point3d(pointX.Value,
pointY.Value, 0)


End Select


Dim dbpt As acadDB.DBPoint = New
acadDB.DBPoint(myPoint)


'dbpt.SetDatabaseDefaults(db)


btr.AppendEntity(dbpt)


tr.AddNewlyCreatedDBObject(dbpt, True)


tr.Commit()


Loop


GoTo Begin


End If


End If


Catch acEx As acadRT.Exception


MsgBox(CurrentStack.GetFrame(0).GetFileLineNumber +
": " + acEx.Message, _


MsgBoxStyle.OkOnly + MsgBoxStyle.Critical,
_


acEx.ErrorStatus.ToString())


tr.Abort()


Catch nullEx As
System.NullReferenceException


Catch ex As System.Exception


MsgBox(CurrentStack.GetFrame(0).GetFileLineNumber +
": " + ex.Message, _


MsgBoxStyle.Critical + MsgBoxStyle.Critical,
_


ex.InnerException.ToString())


tr.Abort()


Finally


' reset variables to original state


acadApp.Application.SetSystemVariable("PDMODE",
pdMode)


acadApp.Application.SetSystemVariable("PDSIZE",
pdSize)


'acadApp.Application.SetSystemVariable("UCSICON",
sUCSIcon)


'acadApp.Application.SetSystemVariable("UCSORG",
ptOrigin)


docLock.Dispose()


End Try


End Sub


End Module

0 Likes
228 Views
0 Replies
Replies (0)