We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to render cad block in converted svg

My Company is currently working on Dwg to Svg process mainly, but we found that using what Aspose provided as a sample(Dwg to Svg) the dwg’s layer names don’t apply to svg tag.

First, Is there a way to maintain dwg’s layer information when converting to svg using Aspose?

Second, Because the reference that Aspose provides doesn’t get the layers from dwg when converting to svg, we are making a loop.

We are currently making a loop

which

takes layers(+layouts) from CadImag, 
applies each layers to CadRasterizationOptions(while converting svg), 
sets highest grade of <g>'s element id as layer name,
finally merges svgs what we converted.

However the Cad Blocks doesn’t render while converting each layers to svg.
Is there a way to render the Blocks?

(Using System.Xml Because When I used Aspose.SVG, some “tags” disappeared.)

				foreach (var layer in layers)
				{
					using (MemoryStream memoryStream = new MemoryStream())
					{
						string layerName = layer.Replace(" ", "");
						SvgOptions options = new SvgOptions();
						rasterizationOptions.Layers = new string[] { layer.Trim() };
						options.TextAsShapes = false;
						options.VectorRasterizationOptions = rasterizationOptions;
						image.Save(memoryStream, options);
						memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
						using (var reader = new StreamReader(memoryStream))
						{
							var contents = reader.ReadToEnd();
							XmlDocument svg = new XmlDocument();
							svg.LoadXml(contents);
							var root = svg.SelectSingleNode("descendant::svg:g", manager);
							if (root == null)
							{
								Console.WriteLine(svg.OuterXml);
								continue;
							}
							((XmlElement)root).SetAttribute("id", layerName);
							XmlNode importNode = svgTag.OwnerDocument.ImportNode(root, true);
							svgTag.AppendChild(importNode);
						}
					}
				}
				origin.Save(Path.Combine(distPath, $"{dwg.FileName}-merged.svg"));

Hello @dvpron

May you kindly provide mentioned source file for further investigation?