<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Opening a Civil 3D drawing for edit in C# .Net in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/8327085#M41506</link>
    <description>&lt;P&gt;There needs to be levels of Kudos ... Jeff deserves Uber Kudos&lt;/P&gt;</description>
    <pubDate>Thu, 11 Oct 2018 09:52:00 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-10-11T09:52:00Z</dc:date>
    <item>
      <title>Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5490349#M41492</link>
      <description>&lt;P&gt;Here's a code snippet from a project I'm working on (processing a large number of surfaces from&amp;nbsp;point files&amp;nbsp;in Civil 3D):&lt;/P&gt;&lt;PRE&gt; // Create and open a new drawing, from the specified template
 Document doc = AcApplication.DocumentManager.Add(templateFileName);
 AcApplication.DocumentManager.MdiActiveDocument = doc;
 Database db = doc.Database;

 // need to wait for Civil 3D to catch up!
 MessageBox.Show(surfacename);

 // Create the surface
 using (Transaction trans = db.TransactionManager.StartTransaction())
 {
    // get the point file format object, required for import:
    PointFileFormatCollection ptFileFormats = PointFileFormatCollection.GetPointFileFormats(db);
    PointFileFormat ptFormat = ptFileFormats[ptFileFormat];
    ObjectId styleId = GetStyleId(surfaceStyleName);

    ObjectId surfaceId = TinSurface.Create(filename, styleId);
    TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;&lt;/PRE&gt;&lt;P&gt;What's odd, is that this works, pretty much the way I want it to, except for the &lt;EM&gt;MessageBox.Show(surfacename);&lt;/EM&gt; &amp;nbsp;line.&lt;/P&gt;&lt;P&gt;If I remove this line, or replace it with &lt;EM&gt;Thread.Sleep(30000);&lt;/EM&gt; or &lt;EM&gt;for (int i=0; i&amp;lt;1000000; i++) {}&lt;/EM&gt;, the program crashes on the &lt;EM&gt;TinSurface.Create(filename, styleId);&lt;/EM&gt; line with a "Fail to create surface" error. &amp;nbsp;I've tried using &lt;EM&gt;TinSurface.Create(db, surfacename);&lt;/EM&gt; and it still crashes. &amp;nbsp;I've also tried creating all of the drawing files first, then coming back and using&amp;nbsp;DocumentManager.Open(). &amp;nbsp;I can access existing surfaces using this technique, but I can't create them without the MessageBox.Show() statement. &amp;nbsp;When I simply add the surfaces to the active drawing, the program&amp;nbsp;works perfectly, but I want to put the surfaces into separate drawings for performance reasons.&lt;/P&gt;&lt;P&gt;Does anyone know what the MessageBox.Show() statement is doing that could be replicated without actually stopping the program to request input from the user? &amp;nbsp;What part of the process did I miss? &amp;nbsp;Do I need to reset the UI, or something along those lines, and how would I go about doing so?&lt;/P&gt;</description>
      <pubDate>Sat, 31 Jan 2015 08:56:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5490349#M41492</guid>
      <dc:creator>JohnDutz</dc:creator>
      <dc:date>2015-01-31T08:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5491853#M41493</link>
      <description>John, not sure if you know about it or not, but there is a forum specifically for Civil3D customization: &lt;A href="http://forums.autodesk.com/t5/autocad-civil-3d-customization/bd-p/190" target="_blank"&gt;http://forums.autodesk.com/t5/autocad-civil-3d-customization/bd-p/190&lt;/A&gt;&lt;BR /&gt;It looks like you are opening each drawing in the editor? I would suggest just creating a new side database, create the TinSurface in it (this is the reason for the TinSurface.Create(db, name) method), add the Pointfile, then save the db. I don't have an example right now, but if needed I think I could get one put together later on.</description>
      <pubDate>Mon, 02 Feb 2015 16:34:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5491853#M41493</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-02-02T16:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492292#M41494</link>
      <description>There seems to be an issue with that method. I was sure that I had it working at one time, though. Will keep trying....</description>
      <pubDate>Mon, 02 Feb 2015 21:24:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492292#M41494</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-02-02T21:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492353#M41495</link>
      <description>&lt;P&gt;Thanks Jeff,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really appreciate you looking into this.&amp;nbsp; I was under the (possibly mistaken) understanding that the Civil namespaces didn't load unless you open the drawing in the editor and I wasn't able to find an example (except for &lt;A target="_self" href="http://through-the-interface.typepad.com/through_the_interface/2007/07/accessing-dwg-f.html"&gt;Kean Walsley's discussion on the topic&lt;/A&gt;).&amp;nbsp; I haven't worked with a side database before.&amp;nbsp; I certainly don't need the UI, so I think approach would work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I create the new file from a template, and then open it as a side database?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp; Document doc = AcApplication.DocumentManager.Add(templateFileName​);  // &amp;lt;-- Need to change this line&lt;BR /&gt;  //  AcApplication.DocumentManager.MdiActiveDocument = doc;           // &amp;lt;-- No longer required&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; // Create a database and try to load the file&amp;nbsp; &lt;BR /&gt;  Database db = new Database(false, true);
  using (db)
  {
    try
    {
      db.ReadDwgFile(
      filename,
      System.IO.FileShare.Read,
      false,   
      ""
       );
    }

    catch (System.Exception)
    {
      ed.WriteMessage("\nUnable to read drawing file.");
      return;
    }

  // ... do some stuff

  }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2015 21:54:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492353#M41495</guid>
      <dc:creator>JohnDutz</dc:creator>
      <dc:date>2015-02-02T21:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492376#M41496</link>
      <description>&lt;P&gt;I suppose I could just copy the template file on the server, rename it and open it.&amp;nbsp; Or open the template and do a CloseAndSave.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again, for your feedback.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2015 22:03:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492376#M41496</guid>
      <dc:creator>JohnDutz</dc:creator>
      <dc:date>2015-02-02T22:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492596#M41497</link>
      <description>&lt;P&gt;John, sorry for the delayed response. Was researching some other things and lost track of time. The following code works quite well and fast:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Select PointFiles to import";
            ofd.CheckFileExists = true;
            ofd.Multiselect = true;
            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            dynamic prefs = Autodesk.AutoCAD.ApplicationServices.Application.Preferences;
            dynamic files = prefs.Files;
            string qnew = files.QNewTemplateFile;

            foreach (string file in ofd.FileNames)
            {
                string path = Path.GetDirectoryName(file);
                string filename = Path.GetFileNameWithoutExtension(file);
                string newname = path + "\\" + filename + ".dwg";
                using (Database db = new Database(false, true))
                {
                    db.ReadDwgFile(qnew, FileOpenMode.OpenForReadAndWriteNoShare, false, "");
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        CivilDocument civdoc = CivilDocument.GetCivilDocument(db);
                        ObjectId styleId = civdoc.Styles.SurfaceStyles["TDG - Border Only"];
                        ObjectId surfId = TinSurface.Create(db, filename);
                        TinSurface surf = (TinSurface)surfId.GetObject(OpenMode.ForWrite);
                        PointFileFormatCollection ptFileFormats = PointFileFormatCollection.GetPointFileFormats(db);
                        PointFileFormat ptFormat = ptFileFormats["PNEZD (comma delimited)"];
                        surf.StyleId = styleId;
                        surf.PointFilesDefinition.AddPointFile(file, ptFormat);
                        tr.Commit();
                    }
                    db.SaveAs(newname, DwgVersion.Current);
                }
            }
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Feb 2015 01:00:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492596#M41497</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-02-03T01:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492599#M41498</link>
      <description>One thing that took a bit to figure out was that the help for the TinSurface.Create(db, name) constructor says that the surface is created using the Default style name. Well, it doesn't. I went into my DWT, setup the Drawing defaults just as I wanted, and it still created it with what I think is the first Style in the SurfaceStyles collection. So i just added the bit to get the style I wanted to use and set the surface's StyleId property to that.</description>
      <pubDate>Tue, 03 Feb 2015 01:05:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492599#M41498</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-02-03T01:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492720#M41499</link>
      <description>&lt;P&gt;That worked amazingly well, Jeff.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Feb 2015 04:30:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5492720#M41499</guid>
      <dc:creator>JohnDutz</dc:creator>
      <dc:date>2015-02-03T04:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5833934#M41500</link>
      <description>&lt;P&gt;I have some problems with creating of new surfaces. I tryed with this code, and it works if I type command "create"'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; public class Commands&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;[CommandMethod("create")]&lt;/P&gt;&lt;P&gt;&amp;nbsp;public void CreateTinSurfaceTest()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;Document m_Doc = Application.DocumentManager.MdiActiveDocument;&lt;/P&gt;&lt;P&gt;Database db = m_Doc.Database;&lt;BR /&gt;Editor ed = m_Doc.Editor;&lt;BR /&gt;CivilDocument civilDoc = CivilApplication.ActiveDocument;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;using (Transaction m_Tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;//1. Variant: defintion styleproperties- and SurfaceName&lt;BR /&gt;m_SurfaceStyleId = civilDoc.Styles.SurfaceStyles["Rutnät och gräns"];&lt;BR /&gt;m_SurfaceId = TinSurface.Create("TIN_Surface_From_Contours", m_SurfaceStyleId);&lt;/P&gt;&lt;P&gt;//2. Variant definition SurfaceName&lt;BR /&gt;//m_SurfaceId = Autodesk.Civil.DatabaseServices.TinSurface.Create(db, "m_NewSurfaceName");&lt;BR /&gt;m_Surface = m_SurfaceId.GetObject(OpenMode.ForWrite) as TinSurface;&lt;BR /&gt;ed.WriteMessage("Import succeeded: {0} \n {1}", m_SurfaceId.ToString(), db.Filename);&lt;BR /&gt;}&lt;BR /&gt;catch (System.Exception e)&lt;BR /&gt;{&lt;BR /&gt;ed.WriteMessage("Import failed: {0}", e.Message);&lt;BR /&gt;}&lt;BR /&gt;m_Tr.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if I call metod (CreateTinSurfaceTest()) from annother class like so&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Commands cmd = new Commands();&lt;BR /&gt;cmd.CreateTinSurfaceTest();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it doesn´t work. Anybody know why?&lt;/P&gt;</description>
      <pubDate>Sat, 26 Sep 2015 12:59:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5833934#M41500</guid>
      <dc:creator>DRossger</dc:creator>
      <dc:date>2015-09-26T12:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5835987#M41501</link>
      <description>How doesn't it work? Error? Nothing happens?</description>
      <pubDate>Mon, 28 Sep 2015 20:14:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5835987#M41501</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-09-28T20:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5836011#M41502</link>
      <description>&lt;P&gt;Is your call to "CreateTinSurfaceTest()"? &amp;nbsp;"create" is an acad command - not the same as the name of the method.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2015 20:22:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5836011#M41502</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2015-09-28T20:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5836904#M41503</link>
      <description>&lt;P&gt;Thanx!&lt;/P&gt;&lt;P&gt;Problem is solved, it hade to do with implemented winformDialog. I could click button_ok and than TinSurface.Create()-metod was running. But the problem was I didn´t get a SurfaceId. The problem was, the dialog was open and so the metod couldn´t work right.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 13:48:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/5836904#M41503</guid>
      <dc:creator>DRossger</dc:creator>
      <dc:date>2015-09-29T13:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/7906797#M41504</link>
      <description>&lt;P&gt;How did you get reference to Autodesk.AutoCAD.ApplicationServices.Application.Preferences ?&lt;/P&gt;&lt;P&gt;When I include a reference to ACMGD.DLL ... although it creates a DLL, ACCORE crashes on NETLOAD&amp;nbsp; : (&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 08:09:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/7906797#M41504</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-04T08:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/7908394#M41505</link>
      <description>Kevin, make sure you have references to AcCoreMgd, AcDbMgd, &amp;amp; AcMgd</description>
      <pubDate>Wed, 04 Apr 2018 17:08:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/7908394#M41505</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2018-04-04T17:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Opening a Civil 3D drawing for edit in C# .Net</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/8327085#M41506</link>
      <description>&lt;P&gt;There needs to be levels of Kudos ... Jeff deserves Uber Kudos&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 09:52:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-a-civil-3d-drawing-for-edit-in-c-net/m-p/8327085#M41506</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-11T09:52:00Z</dc:date>
    </item>
  </channel>
</rss>

