I cant access CANTCurves in an Alignment. I get messages like : "Alignment cannot be opened for write successfully."
When I try : "trans.GetObject(al.ObjectId, _AcDb.OpenMode.ForWrite)" I get "Autodesk.AutoCAD.Runtime.Exception: eLockViolation"
When I try :"myAlignment.UpgradeOpen()" I get "eInvalidOpenState"
How can I access cant informations of an alignment?
public ArrayList TEST_cant(Alignment al)
{
ArrayList lstTest = new ArrayList();
_AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
_AcDb.Database db = doc.Database;
using (_AcDb.Transaction trans = db.TransactionManager.StartTransaction())
{
//Alignment al_bis = trans.GetObject(al.ObjectId, _AcDb.OpenMode.ForWrite) as _AcCDb::Alignment;
//Autodesk.AutoCAD.Runtime.Exception: eLockViolation
ArrayList lstStations = GetStartStations(al);
al.UpgradeOpen(); // eInvalidOpenState
CANTCurveCollection cantCurveCollection = al.CANTCurves; //Alignment cannot be opened for write successfully.
MessageBox.Show("CANTcurveCollection retrived");
foreach (CANTCurve CANTcurve in cantCurveCollection)
{
lstTest.Add("CANTcurve");
lstTest.Add(CANTcurve.StartStation);
MessageBox.Show(CANTcurve.Name);
foreach (CANTCriticalStation CANTcrtclStn in CANTcurve.CANTCriticalStations)
{
lstTest.Add("CANTcrtclSTN");
lstTest.Add(CANTcrtclStn.CANTCurveName);
MessageBox.Show(CANTcrtclStn.CANTCurveName);
}
lstTest.Add("CANTcurve");
}
al.Update();
trans.Commit();
}
return lstTest;
}
Is your code being run from a command method, or from a button click handler on a dialog, palette, or other UI?
The problem is most likely that you are running your code from the latter, and you are not locking the document before trying to access it.
Document doc = Application.DocumentManager.MdiActiveDocument
using(doc.LockDocument())
{
// Ok to access document contents here
}
Hi,
My code is run from a command method that opens a windows form from which I can select an alignment and a method. I do this to test methods that takes an alignment as argument and check if they are working.
A lot of them are working fine like :
public ArrayList GetEntities(Alignment al)
{
ArrayList lstEntity = new ArrayList();
foreach (_AcCDb::AlignmentEntity entity in al.Entities)
{
lstEntity.Add(entity);
}
return lstEntity;
}
I tried a bit messing around with :
using(doc.LockDocument())
but I get the same errors.
You don't mention how the Windows Form is shown. It can be shown as a modal window or a modeless window. Also as far as your attempts to use the lock document code you need to show the entire code not just one line.
Hi,
I think I have modeless forms as I am able to draw in the model space.
As for the document locking I tried, 2 position of "using (doc.LockDocument())" inside the method to get ant information, each time I tried with or without ".UpgradeOpen()".
public ArrayList TEST_cant_CANTCurve(Alignment al) //not ok
{
ArrayList lstTest = new ArrayList();
ArrayList lstStations = GetStartStations(al);
_AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
using (doc.LockDocument()) ;
{
_AcDb.Database db = doc.Database;
using (_AcDb.Transaction trans = db.TransactionManager.StartTransaction())
{
//using (doc.LockDocument()) ;
//al.UpgradeOpen(); //Autodesk.AutoCAD.Runtime.Exception: eInvalidOpenState
CANTCurveCollection cantCurveCollection = al.CANTCurves; //Alignment cannot be opened for write successfully.
MessageBox.Show("CANTcurveCollection retrived");
Can't find what you're looking for? Ask the community or share your knowledge.