Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add Points to TopographySurface Error: Not permitted to start

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
1574 Views, 2 Replies

Add Points to TopographySurface Error: Not permitted to start

Hello

 

I am attempting to add points/vertices to an existing TopographySurface(TS) element. I understand that in order to add points to an existing TS I need to start a TopographyEditScope. But when I start my TopographyEditScopeI get the following runtime error:

 

Revit encountered a Autodesk.Revit.Exceptions.InvalidOperationException: TopographyEditScope is not permitted to start at this moment for 1 of the following possible reasons: The document is in read-only state, or the document is crrently modifiable, or there already is a topography surface edit mode active in the document.

 

How can I overcome this error? You'll see below that my very simple code is not running another TopographyEditScope so thats not the cause. Also I am correctly running my TopographyEditScope from within a Transaction (which is what is required). Also my Revit project is of the type Construction if that helps.

 

Any solutions and advice would be extremely helpful:

 

[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class MyGroup : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        UIApplication uiApp = commandData.Application;
        Document doc = uiApp.ActiveUIDocument.Document;

        Transaction trans = new Transaction(doc);
        trans.Start("Lab");
        
        List<XYZ> pnts = new List<XYZ>();
        pnts.Add(new XYZ(-5, -5, 0));
        pnts.Add(new XYZ(0, 5, 5));
        pnts.Add(new XYZ(2, 2, 2));
        TopographySurface surface = TopographySurface.Create(doc, pnts);

        TopographyEditScope scope = new TopographyEditScope(doc, "blah");
        scope.Start(surface.Id);  // Runtime error occurs at this line
        List<XYZ> pList = new List<XYZ>();
        pList.Add(new XYZ(5, 5, 5));
        pList.Add(new XYZ(5, 0, 0));
        pList.Add(new XYZ(3, 3, 3));
        surface.AddPoints(pList);
		MyFailureProcessor failProc = new MyFailureProcessor();
        scope.Commit(failProc);

        trans.Commit();

        return Result.Succeeded;
    }

    class MyFailureProcessor : IFailuresPreprocessor
    {
        public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
        {
// TODO: implement code return FailureProcessingResult.Continue; } } }

 

 

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Hello Sam,

 

The error you get is because there is a problem with transaction order. I changed the code like this and it works like a charm 🙂

 

List<XYZ> pnts = new List<XYZ>();
pnts.Add(new XYZ(-5, -5, 0));
pnts.Add(new XYZ(0, 5, 5));
pnts.Add(new XYZ(2, 2, 2));
Transaction trans = new Transaction(doc);
trans.Start("Lab");
TopographySurface surface = TopographySurface.Create(doc, pnts);
trans.Commit();

TopographyEditScope scope = new TopographyEditScope(doc, "blah");
scope.Start(surface.Id); // Runtime error occurs at this line

trans = new Transaction(doc);  // added an extra transaction here
trans.Start("Lab2");

List<XYZ> pList = new List<XYZ>();
pList.Add(new XYZ(5, 5, 5));
pList.Add(new XYZ(5, 0, 0));
pList.Add(new XYZ(3, 3, 3));
surface.AddPoints(pList);
MyFailureProcessor failProc = new MyFailureProcessor();
trans.Commit(); // close it and then commit the scope, otherwise you'll get the same error.
scope.Commit(failProc);

 

Looks like TopographyEditScope is threated by Revit the same way as a transaction.

 

Good luck with your program,

Remy.

 

Message 3 of 3
Anonymous
in reply to: Anonymous

It works now. Thanks 🙂 Its greatly appreciated

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community