Select to view content in your preferred language

ArcGIS Pro corehost standalone Program issue

562
6
09-07-2023 05:00 AM
gaofangwan
New Contributor II

I have a console application created with  "ArcGIS Pro CoreHost application" template, if I open a .dwg file inside it with below function:

 

 public static Geometry GetBoundary(string inProjectBoudaryPath, string cadFile)
        {
            try
            {
                var connectionPath = new FileSystemConnectionPath(new Uri(inProjectBoudaryPath),
                    FileSystemDatastoreType.Cad);

                using (var dataStore = new FileSystemDatastore(connectionPath))
                {
                    string fileName = Path.GetFileName(cadFile);
                    using (var dataset = dataStore.OpenDataset<CadDataset>(cadFile))
                    {
                        using (var polygonFeatCls = dataset.OpenDataset<FeatureClass>("Polygon"))
                        {
                            QueryFilter filter = new QueryFilter();
                            filter.WhereClause = $"Layer='Project Boundary'";

                            using (var cursor = polygonFeatCls.Search(null, false))
                            {
                                Geometry boudary = null;
                                while (cursor.MoveNext())
                                {
                                    using (var feature = (Feature)cursor.Current)
                                    {
                                        if (GeometryEngine.Instance.IsSimpleAsFeature(feature.GetShape(), true))
                                        {
                                            if (boudary == null) boudary = feature.GetShape();
                                            else boudary = GeometryEngine.Instance.Union(boudary, feature.GetShape());
                                        }
                                        else
                                        {
                                            var fixedGeometry = GeometryEngine.Instance.SimplifyAsFeature(feature.GetShape());
                                            if (boudary == null) boudary = fixedGeometry;
                                            else boudary = GeometryEngine.Instance.Union(boudary, fixedGeometry);
                                        }
                                    }
                                }
                                return Convert3DTo2D(boudary);
                            }
                        }
                    }
                }                
            }
            catch (Exception ex)
            {
                
                Console.Write($"Error when extract boudary from CAD, ex: {ex}");
                return null;
            }
            return null;
        }

        public static Geometry Convert3DTo2D(Geometry inputGeo)
        {
            Console.WriteLine("Start to remove Z in feature");            
            if (inputGeo == null) return null;
            SpatialReference hkProj = null;
            using (SpatialReferenceBuilder srBuilder = new SpatialReferenceBuilder(2326))
            {
                // do something with the builder
                hkProj = srBuilder.ToSpatialReference();
            }

            PolygonBuilderEx polygonBuilder = new PolygonBuilderEx(hkProj);
            polygonBuilder.HasZ = false;

            if (inputGeo.HasZ)
            {
                Polygon inPolygon = (Polygon)inputGeo;
                for (int i = 0; i < inPolygon.PartCount; i++)
                {
                    ReadOnlySegmentCollection segCol = inPolygon.Parts[i];
                    polygonBuilder.AddPart(segCol);
                }
                Console.WriteLine("Remove Z in feature successfully");                
                return polygonBuilder.ToGeometry();
            }
            else
            {
                Console.WriteLine("No Z found.");
                
                return inputGeo;
            }


        }

 The program will not exit normally like below screenshot:

gaofangwan_0-1694087831611.png

when debug in Visual studio 2022, it will display after finished:

gaofangwan_1-1694087925638.png

And there is below error in output window of Visual Studio:

gaofangwan_2-1694087983441.png

 

By the way, I use ArcGIS Pro 3.1 and related SDK for .Net and Visual Studio 2022.

 

Who can tell me if it is the bug of SDK?

 

 

Tags (1)
0 Kudos
6 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Depending on your screenshots issue is outside code you have added. There is no code with Console.WriteLine("Finished"); or Console.WriteLine("Completed");

0 Kudos
gaofangwan
New Contributor II

Yes, I do not paste all code here. I have attached the vs project file.

0 Kudos
GKmieliauskas
Esri Regular Contributor

I have tested your solution. One thing I have changed was path to dwg and dwg file name. It finished with code 0.

GintautasKmieliauskas_0-1694091934799.png

 

0 Kudos
gaofangwan
New Contributor II

Could you tell me which Visual studio and SDK version you use?

My Visual studio 2022: 17.6.1

ArcGIS.CoreHost.dll: 13.1.0.41833

ArcGIS.Core.dll: 13.1.0.41833

 

gaofangwan_2-1694093050653.png

 

gaofangwan_0-1694092980294.pnggaofangwan_1-1694093002367.png

 

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

VS: Version 17.4.3

ArcGIS.CoreHost.dll: 13.1.0.41833

ArcGIS.Core.dll: 13.1.0.41833

Check which ArcGIS Pro extensions for Visual Studio you use.

I use 3.1.0.48133

 

0 Kudos
gaofangwan
New Contributor II

Very thanks!

0 Kudos