Remove Civil 3D corridor region

Hi,
Can anyone please help me in removing corridor baseline region via dynamo.
I have tried looking for this kind of node in Civil 3D toolkit but it seems no node available to remove baseline region.

Thanks

Hi @hosneyalaa
Thanks for this information, it looks there is possibility.
But I don’t have much knowledge on dynamo scripting.
Can anyone one please create dynamo script?
Thanks and much appreciated.

Hi All,
I have tried the below code but getting errors can anyone please correct me

import clr

Add Assemblies for AutoCAD and Civil 3D APIs

clr.AddReference(‘acmgd’)
clr.AddReference(‘acdbmgd’)
clr.AddReference(‘accoremgd’)
clr.AddReference(‘AecBaseMgd’)
clr.AddReference(‘AecPropDataMgd’)
clr.AddReference(‘AeccDbMgd’)
clr.AddReference(‘AeccPressurePipesMgd’)
clr.AddReference(‘acdbmgdbrep’)
clr.AddReference(‘System.Windows.Forms’)
clr.AddReference(‘Civil3DNodes’)

Add standard Python references

import sys
sys.path.append(‘C:\Program Files (x86)\IronPython 2.7\Lib’)
import os
import math

Add references to manage arrays, collections and interact with the user

from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox

Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class

import Autodesk.AutoCAD.ApplicationServices.Application as acapp

Import references from AutoCAD

from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

Import references for Civil 3D

from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

Import references for Dynamo for Civil 3D

from Autodesk.Civil.DynamoNodes import Alignment as DynAlignment

adoc = acapp.DocumentManager.MdiActiveDocument
ed = adoc.Editor
civdoc = CivilApplication.ActiveDocument

corridor = IN[0]
baseline = IN[1]
baselineRegion = IN[2]

def removeRegion:

global adoc
global ed
global civdoc


	


    with adoc.LockDocument():
        with adoc.Database as db:
            with db.TransactionManager.StartTransaction() as t:
                
                corid = civdoc.CorridorCollection[corridor]
                cor = t.GetObject(corid, OpenMode.ForWrite)
                bl = cor.Baselines[baseline]
                blr = bl.BaselineRegions[baselineRegion]
				baselineRegionColl.Remove("RG - Ass_PRS - (78)");

                t.Commit()
except Exception() as ex:
    MessageBox.Show(ex.message)
return result

OUT = removeRegion.

Drop the semicolon on this line.

Also, this script would be a lot more useful if the region name was an input instead of being hard-coded.

Hi @mzjensen
Thank you so much for your help.
I am getting some indent error msg. as below
**Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. **
unexpected indent
also as per your advice, I have made little change, I am not sure I have coded correct or not can you please correct me if I am wrog somewhere.

corridor = IN[0]
baseline = IN[1]
baselineRegion = IN[2]

def removeRegion:

global adoc
global ed
global civdoc


	


    with adoc.LockDocument():
        with adoc.Database as db:
            with db.TransactionManager.StartTransaction() as t:
                
                corid = civdoc.CorridorCollection[corridor]
                cor = t.GetObject(corid, OpenMode.ForWrite)
                bl = cor.Baselines[baseline]
                blr = bl.BaselineRegions[baselineRegion]
				baselineRegionColl.Remove(baselineRegion)

                t.Commit()
except Exception() as ex:
    MessageBox.Show(ex.message)
return result

OUT = removeRegion

We’ve talked about this previously in a private message. I’ll repost that here for others to reference:

Python has special rules for the indentation of each line. In most other languages, you’ll see that the end of each line is indicated with a specific character. For example, in C# you always end a line with a ;. That’s how the computer knows to move from one line to the next in the execution process.

But as you can see with Python, there are no specific characters and the end of each line, so how does the computer know when to move from one line to the next? The answer is the indentation of each line. The official Python style guide calls to use 4 spaces for each indentation level, but you can also use the tab key. Here’s more to read:
https://www.scaler.com/topics/python/indentation-in-python/

I can’t tell what the issue is by glancing at it quickly, so all I can say is to check each line and make sure you aren’t mixing tabs and spaces, and that each line has the amount of indentation that it should. For example, the entire block starting at with adoc.LockDocument(): seems to be indented more than it should.

This can often be an issue when copying/pasting code from somewhere else.

4 Likes

@ansarimdnazir besides the indention rules that @mzjensen has mentioned, you also have an “except” clause without a “try” clause before. I don’t know if this is possible in Python (i’ve never seen a “try except” without the keyword “try”), but maybe you should also check for that. Additionally, all code that belongs to the removeRegion function should be indented

1 Like