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.
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
@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.
@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.
Be sure to Unblock the ZIP file before extracting the dll.
@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.
@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();
}
}
}
}
Can't find what you're looking for? Ask the community or share your knowledge.