Hi,
I need to convert the following line from VB to C#.
Set Surface = oSurfaces.(sXmlFileName)
Idea ?
Thanks
Solved! Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
Hi,
look to >>>this page<<< for translation.
HTH, - alfred -
Alfred hi,
I am familiar with that conversion web. Unfortunately it does not work --)
Thanks
Hi,
>> Unfortunately it does not work
What code do you get as a result, how do the code-lines above (especially the declaration of the var's) look like and what error-message do you get?
- alfred -
Alfred hi,
First, thank you.
The purpose of the program is to import Surface XML into the current DWG.
The program was supplied by Autodesk in 2011 and was written in VB.
I manage to change some lines but got stacked at the main task which is the import method.
The program looks as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Xml;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Civil.DatabaseServices.Styles;
using Autodesk.Civil.ApplicationServices;
using CivSuface = Autodesk.Civil.DatabaseServices.Surface;
using OpenFileDialog = System.Windows.Forms.OpenFileDialog;
using DialogResult = System.Windows.Forms.DialogResult;
using Exception = System.Exception;
using oSurfaces = Autodesk.Civil.DatabaseServices.SurfaceOperationAddXmlFile;
namespace ClassLibrary1
{
public class Class1
{
[CommandMethod("ESD_Surface_XML")]
//public void ESD_Surface_XML()
//{
// String surface = gbutton1_Click();
// if (surface == null) return;
//}
public void ESD_Surface_XML()
{
CivilDocument doc = CivilApplication.ActiveDocument;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ObjectIdCollection SurfaceIds = doc.GetSurfaceIds();
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "XML files (*.XML)|*.XML";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
//string path = openFileDialog1.Directory;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
String sXmlFileName = openFileDialog1.FileName;
ed.WriteMessage("\nFile Selected: " + sXmlFileName);
Set Surface = oSurfaces.(sXmlFileName) ;
Hi,
how is "Surface" declared? as Object and you are working with latebinding or as AeccSurface and you have referenced the AECC-lib's?
If that is the complete code-snippet then the base of your problem is that you want to import an XML, but before importing it you try to access the surface (that would exist after import, but not before). Am I right with the statement: when your red line get's executed the surface does not exist in the drawing? If so then the surface-collection has no item called <sXmlFileName>.
BTW: when you have the code in VBA, why not translating it to VB.NET then? 😉
- alfred -
Alfred,
The program up to the red line was converted from VB to C#.
The red line is still in VB because I do not know how to convert it.
sXmlFileName = string and is the name of the XML file chosen for import.
2013 does not support VBA, and I do not want to install the add on VBA,this is the reason for the whole conversion project.
Eitan
Hi,
>> The program up to the red line was converted from VB to C#
If it's the filename foro import, then my estimation that the surface does not exist in the drawing is correct. So you can't access the surface from a collection of surfaces if it does not exist.
There is some code lost during conversion I think, can you show the original VBA-code?
Is it possible that on top of the sub in VBA the statement
On Error Resume Next
is placed? If so then also VBA would have the problem/the exception, but with the above statement it ignores it. And that makes sense if the guy who wrote the code tried to verify if a surface already existis in the drawing with that name.
>> 2013 does not support VBA, and I do not want to install the add on VBA
If you are running on 64bit I understand that. But at the single machine where you do development it might be an advantage to compare the workflow at running/debugging situation.
- alfred -
Alfred,
This is the original VB from Autodesk (2011) In my C# I change it so I can browse and select an XML file.
'
' Create a surface from the file EG.xml.
'
' NOTE: This uses a hard coded dirercory.
'
Public Function CreateSurfaceByImportXML() As Boolean
Dim oSurfaces As AeccSurfaces
Set oSurfaces = g_oDocument.Surfaces
' Get a reference to the existing surface ("EG"). If
' it does not exist, try loading surface data from a
' XML file.
Dim oSurface As AeccSurface
Dim sXmlFileName As String
On Error Resume Next
Set oSurface = oSurfaces.Item("EG")
On Error GoTo 0
If (oSurface Is Nothing) Then
sXmlFileName = "d:\temp\EG.xml"
Set oSurface = oSurfaces.ImportXML(sXmlFileName)
If (oSurface Is Nothing) Then
Debug.Print "Error loading XML file: " & Err.Description
CreateSurfaceByImportXML = False
Err.Clear
End If
End If
' Fill the screen with the surface, and show the triangles
' that make up the surface.
ThisDrawing.Application.ZoomExtents
Call DisplayBorderTrianglesOnly
CreateSurfaceByImportXML = True
End Function
Hi,
>> On Error Resume Next
>> Set oSurface = oSurfaces.Item("EG")
>> On Error GoTo 0
Ok, it's the "On Error ..." option I mentioned to check if a surface with that name already exists in the drawing.
Now there are two options to continue:
try { oSurface = oSurfaces.Item("EG"); } catch (Exception ex) { oSurface = null; }
- alfred -
Just for reference, the SET is not used in vb.net as it was in vba.
try removing the SET statement before attempting conversion, hopefully it will work for you.
Can't find what you're looking for? Ask the community or share your knowledge.