Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Civil3D Drawing slow after running API .Net Commands

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
822 Views, 6 Replies

Civil3D Drawing slow after running API .Net Commands

 Hi,

 

What am I doing: basically what i'm doing is creating a culvert network from an excel table: in which i have the coordinates + elevs for the inlet/Outlet, diameters, Culverts names and at the same time im creating the Sample Lines from some alignments i have in the drawing.

 

First to process the hole command takes about 30mins. and after the command is finished if I Save the drawing and try to open it again takes around 25 mins to open and is barely usable.

 

any ideas in why could the performance could be so slow?

 

Drawing Size: 11 mb

Civil 3D 2017

Visual Studio 2017 -C#

# of culverts 73

# of surfaces to be sampled 2

 

6 REPLIES 6
Message 2 of 7
hippe013
in reply to: Anonymous

You might have to post your code before anyone could say one or the other.

Message 3 of 7
Civil3DReminders_com
in reply to: Anonymous

Without seeing the code, I"d guess you are creating the culverts and then creating a sample line group for each culvert and then adding sample lines for each culvert to the groups. So you'd end up with 73! (4.47011546E105) sample lines. Probably less, but something like it.

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
Message 4 of 7
Anonymous
in reply to: Anonymous

Thanks for replying, see my code below:

 

[CommandMethod("Makesample")]
public void Makesample()
{

 


var doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
Document doc1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc1.Database;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
using (Transaction ts = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{


//int yes;
//int no;
int l = 0;
int m = 0;
double variablex = 524700.00;
int n = 0;

PromptStringOptions cnet = new PromptStringOptions("\nCreate culvert network? ");
PromptResult yn = ed.GetString(cnet);

string cc = "culnet";
if (yn.StringResult.Equals("yes"))
{
Network.Create(doc, ref cc);
}
else
{

}

//begins the excel opening + table read


var xlApp = new Microsoft.Office.Interop.Excel.Application();
var wb = xlApp.Workbooks.Open(@"C:\CULVNET\CULVNET.XLSX");

//Workbook wb = xlApp.Workbooks.Open(@"C:\CULVNET\CULVNET.XLSX");

if (xlApp == null)
{
ed.WriteMessage("open the culvert table excel file (Name the sheet to CULVERTNET, and close all other excel files");
return;
}
xlApp.Visible = true;
Workbook xlwb = xlApp.ActiveWorkbook;
Worksheet xlws = (Worksheet)xlwb.Worksheets["CULVERTNET"];
Dictionary<string, char> dictpipes = new Dictionary<string, char>();

int number = 5;

for (int i = 3; i < number; i++)
{
string pipename = xlws.Cells[i, "A"].Value;
double diam = xlws.Cells[i, "B"].Value;
string align = xlws.Cells[i, "c"].Value;
double lenght = xlws.Cells[i, "D"].Value;
double inletelev = xlws.Cells[i, "I"].Value;
double outletelev = xlws.Cells[i, "M"].Value;
double inletnorth = xlws.Cells[i, "N"].Value;
double inleteast = xlws.Cells[i, "O"].Value;
double outletnorth = xlws.Cells[i, "P"].Value;
double outleteast = xlws.Cells[i, "Q"].Value;
double inletmindia = inletelev + ((diam / 2) / 1000);
double outletmindia = outletelev + ((diam / 2) / 1000);

 


int alnmun = 0;

string alnn = "none";

 


while (align != alnn)

{

//System.Diagnostics.Debugger.Break();
ObjectId alincol = doc.GetAlignmentIds()[alnmun];

//var conv = xlws.Cells[i, "S"].Value;


//long ln = Convert.ToInt64(conv, 16);
//Handle hn = new Handle(ln);
//ObjectId alincol = db.GetObjectId(false,hn, 0);

//var aa = xlws.Cells[i,"S"].value;
//IntPtr hh = aa;


//ObjectId bb = new ObjectId(hh);
//ObjectId alincol = bb;

ObjectId nullin = ObjectId.Null;
if (alincol.Equals(nullin))
{ goto case1; }
else { }
Alignment alnam = ts.GetObject(alincol, OpenMode.ForRead) as Alignment;
alnmun = alnmun + 1;

alnn = alnam.Name;
ed.WriteMessage("\n alinemientos: " + alincol + " nombre: " + alnn);
Console.WriteLine(alnn);

if (align == alnn)
{
// System.Diagnostics.Debugger.Break();


var gname = "New Group" + m;
ObjectId samplegid = SampleLineGroup.Create(gname, alincol);

//System.Diagnostics.Debugger.Break();
SampleLineGroup sampleLg = ts.GetObject(samplegid, OpenMode.ForWrite) as SampleLineGroup;
SectionSourceCollection sectionsourc = sampleLg.GetSectionSources();
ed.WriteMessage("Number of section sources: {0}\n", sectionsourc.Count);
ObjectId surfid = ObjectId.Null;
ObjectId pipesurid = ObjectId.Null;
foreach (SectionSource sectiosource in sectionsourc)
{
if (sectiosource.SourceType == SectionSourceType.TinSurface)
{
surfid = sectiosource.SourceId;
sectiosource.IsSampled = true;
}
if (sectiosource.SourceType == SectionSourceType.PipeNetwork)
{
pipesurid = sectiosource.SourceId;
sectiosource.IsSampled = true;
}
}

Point2dCollection samp2dcol = new Point2dCollection();
Point2d inlp2d = new Point2d(inleteast, inletnorth);
samp2dcol.Add(inlp2d);
Point2d outp2d = new Point2d(outleteast, outletnorth);
samp2dcol.Add(outp2d);

var sname = "newsamp" + l;
ObjectId sampleid = SampleLine.Create(sname, samplegid, samp2dcol);
SampleLine sampli = ts.GetObject(sampleid, OpenMode.ForRead) as SampleLine;
//System.Diagnostics.Debugger.Break();

//var secname = "xsec" + n;
//Point3d secor = new Point3d(variablex, 5599320, 0);
//ObjectId nsec = SectionView.Create(secname, sampleid, secor);

 

l = l + 1;
m = m + 1;
n = n + 1;
variablex = variablex + 50;
}
else { }

}


case1:;

//}
//else
//{

//}


}

ts.Commit();

}


}

 

 

 

Message 5 of 7
Anonymous
in reply to: Civil3DReminders_com

Hi!

 

yes that is pretty much what i want to do, grab the culvert info from my table y the finish goal is to create cross sections from there, actually is working but after i create the sample lines the drawing gets very laggy and im not even able to do the cross sections because the drawing crashes (After running the code) 

 

I'm trying to do some things to make it better for example to avoid creating multiple samplegroups per alignment, or making the sample lines from objects ids extracted to my table (But i havent been able yet to bring back the objectid) to see if this makes it faster. please see my code in the other reply. I still need to clean it a little bit because i havent erased a quick tries i have been doing.

 

Thanks!


@Civil3DReminders_com wrote:

Without seeing the code, I"d guess you are creating the culverts and then creating a sample line group for each culvert and then adding sample lines for each culvert to the groups. So you'd end up with 73! (4.47011546E105) sample lines. Probably less, but something like it.


 

Message 6 of 7
Civil3DReminders_com
in reply to: Anonymous

Why not get the alignments once and store it in a Dictionary? The name of the alignment would be the key and the alignment object would be the stored value. 

 

For checking for the source type you are doing two checks, if you change it to an else if then you would be removing one operation. I've changed it to switch in the code below. 

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.DatabaseServices;
using System.Collections.Generic;

[CommandMethod("Makesample")]
public void Makesample()
{
    var doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
    Document doc1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
    Database db = doc1.Database;
    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
    using (Transaction ts = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
    {
        //int yes;
        //int no;
        int l = 0;
        int m = 0;
        double variablex = 524700.00;
        int n = 0;

        PromptStringOptions cnet = new PromptStringOptions("\nCreate culvert network? ");
        PromptResult yn = ed.GetString(cnet);

        string cc = "culnet";
        if (yn.StringResult.Equals("yes"))
        {
            Network.Create(doc, ref cc);
        }
        else
        {

        }

        //begins the excel opening + table read

        var xlApp = new Microsoft.Office.Interop.Excel.Application();
        var wb = xlApp.Workbooks.Open(@"C:\CULVNET\CULVNET.XLSX");

        //Workbook wb = xlApp.Workbooks.Open(@"C:\CULVNET\CULVNET.XLSX");

        if (xlApp == null)
        {
            ed.WriteMessage("open the culvert table excel file (Name the sheet to CULVERTNET, and close all other excel files");
            return;
        }
        xlApp.Visible = true;
        Workbook xlwb = xlApp.ActiveWorkbook;
        Worksheet xlws = (Worksheet)xlwb.Worksheets["CULVERTNET"];
        Dictionary<string, char> dictpipes = new Dictionary<string, char>();

        int number = 5;

        var alignDict = new Dictionary<string, Alignment>();

        foreach (ObjectId alignObjId in doc.GetAlignmentIds())
        {
            var alignDct = alignObjId.GetObject(OpenMode.ForRead) as Alignment;
            alignDict.Add(alignDct.Name, alignDct);
        }

        for (int i = 3; i < number; i++)
        {
            string pipename = xlws.Cells[i, "A"].Value;
            double diam = xlws.Cells[i, "B"].Value;
            string align = xlws.Cells[i, "c"].Value;
            double lenght = xlws.Cells[i, "D"].Value;
            double inletelev = xlws.Cells[i, "I"].Value;
            double outletelev = xlws.Cells[i, "M"].Value;
            double inletnorth = xlws.Cells[i, "N"].Value;
            double inleteast = xlws.Cells[i, "O"].Value;
            double outletnorth = xlws.Cells[i, "P"].Value;
            double outleteast = xlws.Cells[i, "Q"].Value;
            double inletmindia = inletelev + ((diam / 2) / 1000);
            double outletmindia = outletelev + ((diam / 2) / 1000);

            Alignment alnam;
            if (alignDict.TryGetValue(align, out alnam))
            {
                var gname = "New Group" + m;
                ObjectId samplegid = SampleLineGroup.Create(gname, alnam.ObjectId);

                //System.Diagnostics.Debugger.Break();
                SampleLineGroup sampleLg = ts.GetObject(samplegid, OpenMode.ForWrite) as SampleLineGroup;
                SectionSourceCollection sectionsourc = sampleLg.GetSectionSources();
                ed.WriteMessage("Number of section sources: {0}\n", sectionsourc.Count);
                ObjectId surfid = ObjectId.Null;
                ObjectId pipesurid = ObjectId.Null;
                foreach (SectionSource sectiosource in sectionsourc)
                {
                    switch (sectiosource.SourceType)
                    {
                        case SectionSourceType.TinSurface:
                            surfid = sectiosource.SourceId;
                            sectiosource.IsSampled = true;
                            break;
                        case SectionSourceType.PipeNetwork:
                            pipesurid = sectiosource.SourceId;
                            sectiosource.IsSampled = true;
                            break;
                        case SectionSourceType.GridSurface:
                        case SectionSourceType.Grading:
                        case SectionSourceType.Material:
                        case SectionSourceType.CorridorSurface:
                        case SectionSourceType.Corridor:
                            break;
                        default:
                            break;
                    }
                }

                Point2dCollection samp2dcol = new Point2dCollection();
                Point2d inlp2d = new Point2d(inleteast, inletnorth);
                samp2dcol.Add(inlp2d);
                Point2d outp2d = new Point2d(outleteast, outletnorth);
                samp2dcol.Add(outp2d);

                var sname = "newsamp" + l;
                ObjectId sampleid = SampleLine.Create(sname, samplegid, samp2dcol);
                SampleLine sampli = ts.GetObject(sampleid, OpenMode.ForRead) as SampleLine;

                l = l + 1;
                m = m + 1;
                n = n + 1;
                variablex = variablex + 50;
            }
        }

        ts.Commit();
    }
}
Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
Message 7 of 7
Anonymous
in reply to: Anonymous

Thank you very much for your answer I will try this code first thing in the morning, this is my second week only using c# and the civil 3D API guess there a long way to go.

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report