Problem when import point file usin C3D COM programming

Problem when import point file usin C3D COM programming

Anonymous
Not applicable
1,159 Views
8 Replies
Message 1 of 9

Problem when import point file usin C3D COM programming

Anonymous
Not applicable

please if any one can help me ... i wiring an application for import the csv files to civil 3d automatically but come an error i do not know the reason. the image in the attachment

this my code:

Dim AcadApp As AcadApplication = GetObject(, "AutoCAD.Application")
Dim CivilApp As AeccApplication = AcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.11.0")
Dim Document As AeccDocument = CivilApp.ActiveDocument
Dim Points As AeccPoints = Document.Points
'Import File
Dim Opt As New AeccPointImportOptions
Dim FileFormat As String = "PNEZD (comma delimited)"

Opt.PointDuplicateResolution = AeccPointDuplicateResolutionType.aeccPointDuplicateOverwrite
Points.ImportPoints(""C:\points_data.csv"", FileFormat, Opt)

 

 

0 Likes
Accepted solutions (1)
1,160 Views
8 Replies
Replies (8)
Message 2 of 9

Jeff_M
Consultant
Consultant
Make sure you have these Imports:
Imports Autodesk.AECC.Interop
Imports Autodesk.AECC.Interop.Land
Imports Autodesk.AECC.Interop.UiLand

The example I posted years ago worked fine:
https://forums.autodesk.com/t5/civil-3d-customization/accessviolationexception-with-aeccpointimporto...

Why not use .NET instead of COM?
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 9

Anonymous
Not applicable

Thanks a lot for your replay ... but I already imported

Imports Autodesk.AECC.Interop
Imports Autodesk.AECC.Interop.Land
Imports Autodesk.AECC.Interop.UiLand

still not working and also I I tried to use the code you mentioned in your old post but the same result.

 

I am using the COM instead of .Net because I am working to build a standard alone exe (separate application).

0 Likes
Message 4 of 9

norman.yuan
Mentor
Mentor

Have you stepped through your code to determine which line of code generate the error (that is very simple thing to do and very critical information for anyone, who might want to help, to know, and you should always do before asking for help).

 

If I had to guess, it is this line:

 

Dim CivilApp As AeccApplication = AcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.11.0")

 

that causes the said error, assume a Civil3D session is running while your code executes. Beside the debugging information you need to provides, the couple of key information you also need provide:

 

1. Which version of Civil3D you are using? the version number you used in the ProgramID (xxx.11.0) must match your Civil3D version. 11.0 here means Civil3D 2017, if I recall it correctly.

 

2. How the EXE is executed: does it run as regular desktop app by the current log-in user, or run as unattended app for batch processing?

 

Following code (Console EXE in C#) works for me (Civil3D 2018), where the Civil3D App's ProgramId is "12.0":

    class Program
    {
        static void Main(string[] args)
        {
            var cadApp = CreateAcadSession();
            if (cadApp!=null)
            {
                Console.WriteLine("Press any key to continue...");
                Console.Read();

                var civilDoc = GetCivilApp(cadApp);
                Console.WriteLine("Press any key to exit...");
                Console.Read();
            }
            else
            {
                Console.WriteLine("Press any key to exit...");
                Console.Read();
            }
        }

        private static AutoCAD.AcadApplication CreateAcadSession()
        {
            try
            {
                var cadApp = new AutoCAD.AcadApplication();
                cadApp.Visible = true;
                cadApp.WindowState = AutoCAD.AcWindowState.acMax;
                Console.WriteLine("AutoCAD started.");

                return cadApp;
            }
            catch
            {
                Console.WriteLine("Cannot start AutoCAD!");
                return null;
            }
        }

        private static object GetCivilApp(AutoCAD.AcadApplication cadApp)
        {
object civilDoc = null; try { dynamic civilApp = cadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.12.0");
civilDoc = civilApp.ActiveDocument; Console.WriteLine("Connected to Civil Application successfully."); } catch { Console.WriteLine("Cannot get Civgil3D application!"); }
return civilDoc; } }

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 9

Anonymous
Not applicable

Hi Bro,

thanks a lot for your interest

i do not think the problem in Civil 3D ProgramID (xxx.11.0) . because i useing civil 3d 2017 already . also some codes working well like add cogo points,points group,point style .... or get any information from the currently drawing no any problem come ... but the problem only coming with import point file

exactly in (Dim Opt As New AeccPointImportOptions) as shown in the blow image.

* my EXE is executed  as regular desktop app by the current log-in user

Error.JPG

0 Likes
Message 6 of 9

Jeff_M
Consultant
Consultant

@Anonymous please try replacing this:

Dim CivilApp As AeccApplication = AcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.11.0")

with this:

Dim CivilApp As New AeccApplication()
CivilApp.Init(AcadApp)
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 7 of 9

norman.yuan
Mentor
Mentor
Accepted solution

Ah, I see what you mean. It is this line that generate the error:

 

Dim opt As New AeccPointImportOptions

 

The error message actually provided hint "...class not registered...", which I did not think too much and jumped to the usual suspect of 

 

... = AcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.11.0")

 

The reason of this error is that NOT ALL AEC/AECC classes can be instantiated from outside of AEC/AECC context by " As New xxxx" or "Set xxx = New ....". Just as you go with AeccApplication, which you cannot do

 

Set civilApp = New AeccApplication

 

You have to do 

 

Set civilApp = AcadApplication.GetInterfaceObject("xxxxxxx")

 

Because these objects are already instantiated in AutoCAD context as Aecc objects. The same applies to, you guess it, AeccPointImport/[Export]Options class. So, change your code to:

 

Dim opt As AeccPointImportOptions

Set opt=AcadApp.GetObjectInterface("AeccXLnad.AeccPointImportOptions.11.0")

 

Following code works form me (the same cope as my previous reply, plus on extra line in red):

 

    class Program
    {
        static void Main(string[] args)
        {
            var cadApp = CreateAcadSession();
            if (cadApp!=null)
            {
                Console.WriteLine("Press any key to continue...");
                Console.Read();

                GetCivilApp(cadApp);
                Console.WriteLine("Press any key to exit...");
                Console.Read();
            }
            else
            {
                Console.WriteLine("Press any key to exit...");
                Console.Read();
            }
        }

        private static AutoCAD.AcadApplication CreateAcadSession()
        {
            try
            {
                var cadApp = new AutoCAD.AcadApplication();
                cadApp.Visible = true;
                Console.WriteLine("AutoCAD started.");

                return cadApp;
            }
            catch
            {
                Console.WriteLine("Cannot start AutoCAD!");
                return null;
            }
        }

        private static object GetCivilApp(AutoCAD.AcadApplication cadApp)
        {
            try
            {
                dynamic civilApp = cadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.12.0");
                dynamic civilDoc = civilApp.ActiveDocument;
                Console.WriteLine("Connected to Civil Application successfully.");

                var points = civilDoc.Points;

                //var opt = new Autodesk.AECC.Interop.Land.AeccPointImportOptions();
                dynamic opt = cadApp.GetInterfaceObject("AeccXLand.AeccPointImportOptions.12.0");
                opt.PointDuplicateResolution = 4; // aeccPointDuplicateOverwrite

                //....//

                return (object)civilDoc;
            }
            catch
            {
                Console.WriteLine("Cannot get Civgil3D application!");
                return null;
            }         
        }
    }

Norman Yuan

Drive CAD With Code

EESignature

Message 8 of 9

norman.yuan
Mentor
Mentor

Just to clarify again, since I use Civil2018, thus "xxxxx.12.0". You would use "xxxx.11.0" for Civil2017, of course.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 9 of 9

Anonymous
Not applicable

Sincere thanks and appreciation to you ..

this solution already working well without any errors. really a lot of time spend to solve this problem more than three months.

 

Thanks again.❤️

0 Likes