@m.chavet7MJRB wrote:
All the features are not imported with the "map import", and I guess it's what this code does.
With this code, I don't find the function ImportShape I created when I import it in C3D with netload:
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.Civil;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.Settings;
using System.Diagnostics;
using System.IO;
using Autodesk.Gis.Map.ImportExport;
using Autodesk.Gis.Map;
namespace import_shapefile
{
public class Class1
{
#region IExtensionApplication Members
public void Initialize()
{
// throw new System.Exception("The method or operation is not implemented")
}
public void Terminate()
{
// throw new System.Exception("The method or operation is not implemented")
}
#endregion
[CommandMethod("ImportShape")]
private void ImportShape(FileInfo file)
{
Stopwatch sw = new Stopwatch();
sw.Start();
MapApplication mapApp = HostMapApplicationServices.Application;
using (Importer importer = mapApp.Importer)
{
importer.Init("SHP", file.FullName);
string fileName = Path.GetFileNameWithoutExtension(file.FullName).Replace(" ", "");
foreach (InputLayer inputLayer in importer)
{
inputLayer.SetLayerName(LayerNameType.LayerNameDirect, fileName);
inputLayer.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fileName);
inputLayer.Dispose();
}
importer.ImportPolygonsAsClosedPolylines = true;
ImportResults result = importer.Import(true);
sw.Stop();
//Quest_Common.ed.WriteMessage(string.Format("\n{0} object(s) imported in {1} sec(s)", result.EntitiesImported.ToString(), sw.Elapsed.Seconds));
importer.Dispose();
}
file.Delete();
}
}
}
Moreover, I get a problem when I launch this code to create profile with no surface, because of the style and the label style are not recognized, it says "Name no exists", I tried "Basic" and "Standard":
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.Civil;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.Settings;
using Autodesk.AutoCAD.Geometry;
namespace CreateProfileView
{
public class MyCommands
{
#region IExtensionApplication Members
public void Initialize()
{
// throw new System.Exception("The method or operation is not implemented")
}
public void Terminate()
{
// throw new System.Exception("The method or operation is not implemented")
}
#endregion
[CommandMethod("CreateProfileNoSurface")]
public void CreateProfileNoSurface()
{
CivilDocument doc = CivilApplication.ActiveDocument;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
// Ask the user to select an alignment
PromptEntityOptions opt = new PromptEntityOptions("\nSelect an Alignment");
opt.SetRejectMessage("\nObject must be an alignment.\n");
opt.AddAllowedClass(typeof(Alignment), false);
ObjectId alignID = ed.GetEntity(opt).ObjectId;
Alignment oAlignment = ts.GetObject(alignID, OpenMode.ForRead) as Alignment;
// use the same layer as the alignment
ObjectId layerId = oAlignment.LayerId;
// get the standard style and label set
// these calls will fail on templates without a style named "Standard"
ObjectId styleId = doc.Styles.ProfileStyles["Basic"];
ObjectId labelSetId = doc.Styles.LabelSetStyles.ProfileLabelSetStyles["Basic"];
ObjectId oProfileId = Profile.CreateByLayout("My Profile", alignID, layerId, styleId, labelSetId);
// Now add the entities that define the profile.
Profile oProfile = ts.GetObject(oProfileId, OpenMode.ForRead) as Profile;
Point3d startPoint = new Point3d(oAlignment.StartingStation, -40, 0);
Point3d endPoint = new Point3d(758.2, -70, 0);
ProfileTangent oTangent1 = oProfile.Entities.AddFixedTangent(startPoint, endPoint);
startPoint = new Point3d(1508.2, -60.0, 0);
endPoint = new Point3d(oAlignment.EndingStation, -4.0, 0);
ProfileTangent oTangent2 = oProfile.Entities.AddFixedTangent(startPoint, endPoint);
oProfile.Entities.AddFreeSymmetricParabolaByLength(oTangent1.EntityId, oTangent2.EntityId, VerticalCurveType.Sag, 900.1, true);
ts.Commit();
}
}
}
}
excatly these codes, appart the correction you mentionned before