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: 

Export Design Surfaces to individual LandXML files

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
CNinBC
1995 Views, 16 Replies

Export Design Surfaces to individual LandXML files

we have been asked by the client to export design surfaces to individual LandXML files, there are quite a few surfaces to be exported, is there an easy way to do so? 

is there a way to use script/action to export individually?

is there a software that can split LandXML into multiple files so that each file only contains one surface?

Thanks.

 

16 REPLIES 16
Message 2 of 17
Jeff_M
in reply to: CNinBC


@CNinBC wrote:

 

is there a software that can split LandXML into multiple files so that each file only contains one surface?

Thanks.

 


What I would do is copy the original file as many times as there are surfaces, then open each one with XMLNotepad, delete all but one surface, save.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 17
CNinBC
in reply to: Jeff_M

thanks @Jeff_M , I was hoping that can be automated by software. is that doable in C#?

Message 4 of 17
Jeff_M
in reply to: CNinBC

I've not been able to find anything for exporting to LandXML. I'm sure a tool could be written to create the xml, as all of the surface data is available in the .NET API. Or, after the creation of the master LandXML file in C3D a tool could be created to read the xml file and automate the removal/saving of the individual files.

Not sure how much time I could spend testing either of these options right now.
Jeff_M, also a frequent Swamper
EESignature
Message 5 of 17
Jeff_M
in reply to: CNinBC

@CNinBC , I was pulled off the project I was working on so decided to look into this. Attached is a ZIP file with a small dll you can load into C3D. Create the LandXML file with all of the surfaces you wish to export (if other objects are included, they will also be in the new XML files). The dll has a single command: SPLITSURFACESLANDXML which will prompt for the XML file with the surfaces. It will then save new XML files, in the same folder, having just one surface and the filename will be that of the surface it holds.

 

2020-08-13_14-55-28.png

 

Be sure to Unblock the ZIP file before extracting the dll.

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 17
CNinBC
in reply to: Jeff_M

awesome, thanks @Jeff_M . 

Message 7 of 17
imma
in reply to: Jeff_M

Hi @Jeff_M Jeff - it seems to be exactly the tool what I'm looking for.

But I was not able to get it working on C3D2022.

imma_0-1644309561785.png

 

could you help me to solve the issue?

Message 8 of 17
Jeff_M
in reply to: imma

@imma did you Unblock the Zip file prior to extracting the DLL?

Unblock ZIP file.png

Jeff_M, also a frequent Swamper
EESignature
Message 9 of 17
imma
in reply to: Jeff_M

Thanks! works. 

Message 10 of 17
imma
in reply to: imma

AND ITS SUPER USEFUL!
Message 11 of 17
ishaq03
in reply to: imma

Really It's awesome

Message 12 of 17
cyberflow
in reply to: Jeff_M

Nice love the idea !

Here's an updated link for XmlNotepad (The old link doesnt work anymore)
https://microsoft.github.io/XmlNotepad/

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
Message 13 of 17
Jordan_T1023
in reply to: Jeff_M

@Jeff_M 

 

Do you know if it is possible to split alignments and pipe networks as well? 

Message 14 of 17
Jeff_M
in reply to: Jordan_T1023

@Jordan_T1023 I'm sure it could be. I merely read the LandXML file and create news one using the original as a base for the new files, then loop through each of the surface nodes in each copy and delete the nodes whose name property doesn't match the current surface name.  I can post the .NET code if interested, it is fairly short.

Jeff_M, also a frequent Swamper
EESignature
Message 15 of 17
Jordan_T1023
in reply to: Jeff_M

@Jeff_M yes, could your provide the .net? Thank you!

Message 16 of 17
Jeff_M
in reply to: Jordan_T1023

@Jordan_T1023 here is the code:

//Tool to split all surfaces in a LandXML file to individual LandXML files.
//Could be modified to split out other object types.
//Created by Jeff Mishler (jeffm@quuxsoft.com) Aug. 2020

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace LandXMLSurfaceSplitter
{
    public class Class1
    {
        [CommandMethod("SplitSurfacesLandXML")]
        public void dothesplit()
        {
            XmlDocument xmldoc;
            string xmlfilename;
            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            //allow for both the new file format and the original XML file used by the Free version
            ofd.Filter = "Surfaces LandXML file (*.xml)|*.xml";
            ofd.DefaultExt = "xml";
            ofd.Title = "Surface LandXML Splitter";

            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            xmlfilename = ofd.FileName;
            FileStream fs = new FileStream(xmlfilename, FileMode.Open, FileAccess.Read,
               FileShare.ReadWrite);
            xmldoc = new XmlDocument();
            xmldoc.Load(fs);
            XmlNode rootnode = xmldoc.LastChild;
            Document doc = Application.DocumentManager.MdiActiveDocument;
            XmlNodeList nodes = xmldoc.GetElementsByTagName("Surface");
            if (nodes == null)
                return;
            List<string> namelist = new List<string>();
            for (int i = 0; i < nodes.Count; i++)
            {
                var n = nodes.Item(i);
                namelist.Add(n.Attributes["name"].Value);
            }
            Editor ed = doc.Editor;
            fs.Close();
            var path = Path.GetDirectoryName(xmlfilename) + @"\";
            foreach (var s in namelist)
            {
                var newfilename = path + s + ".xml";
                fs = new FileStream(xmlfilename, FileMode.Open, FileAccess.Read,
               FileShare.ReadWrite);
                var newdoc = new XmlDocument();
                newdoc.Load(fs);
                nodes = newdoc.GetElementsByTagName("Surface");
                List<XmlNode> nodestoremove = new List<XmlNode>();
                for (int i = 0; i < nodes.Count; i++)
                {
                    var n = nodes.Item(i);
                    if (n.Attributes["name"].Value != s)
                        nodestoremove.Add(n);
                }
                foreach (var n in nodestoremove)
                    n.ParentNode.RemoveChild(n);
                newdoc.Save(newfilename);
                fs.Close();
            }
        }
    }
}
Jeff_M, also a frequent Swamper
EESignature
Message 17 of 17
Jordan_T1023
in reply to: Jeff_M

@Jeff_M 

 

Thank you!

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report