// profiles public Base ProfileToSpeckle(CivilDB.Profile profile) { var curve = CurveToSpeckle(profile.BaseCurve, ModelUnits) as Base; if (profile.DisplayName != null) { curve["name"] = profile.DisplayName; } if (profile.Description != null) { curve["description"] = profile.Description; } if (profile.StartingStation != null) { curve["startStation"] = profile.StartingStation; } if (profile.EndingStation != null) { curve["endStation"] = profile.EndingStation; } curve["profileType"] = profile.ProfileType.ToString(); curve["offset"] = profile.Offset; curve["units"] = ModelUnits; return(curve); }
public static Profile ByAlignmentAndSurface(Autodesk.AutoCAD.DynamoNodes.Document document, Alignment parentAlignment, Surface parentSurface, string name, Styles.ProfileStyle profileStyle, ProfileLabelSet profileLabelSet) { Autodesk.Civil.DatabaseServices.Profile newProfile = null; AcadApp.Document curDoc = document.AcDocument; Database db = curDoc.Database; Autodesk.Civil.DatabaseServices.Surface civilSurface = (Autodesk.Civil.DatabaseServices.Surface)parentSurface.InternalDBObject; using (Transaction trans = db.TransactionManager.StartTransaction()) { string oName = name; // need to assign these values based on the string inputs LayerTable lyrTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead); //ObjectId layerId = Utilities.GetLayerByName(db, layer.Name); // id of layer to add profile to // get the layer name defined in the settings ObjectId layerId = Utilities.GetLayerByName(db, CivilDynamoTools.Settings.Settings.GetLayerName(document, Autodesk.Civil.Settings.SettingsObjectLayerType.Profile, name)); ObjectId styleId = profileStyle.InternalObjectId; // id of style to assign the profile ObjectId labelSetId = profileLabelSet.InternalObjectId; // id of label set to assign CivilDocument civilDocument = Autodesk.Civil.ApplicationServices.CivilDocument.GetCivilDocument(document.AcDocument.Database); ObjectIdCollection alignIds = civilDocument.GetAlignmentIds(); // make sure the name doesn't already exist for any profile int copy = 1; foreach (ObjectId aId in alignIds) { Autodesk.Civil.DatabaseServices.Alignment civilAlignment = (Autodesk.Civil.DatabaseServices.Alignment)trans.GetObject(aId, OpenMode.ForRead); ObjectIdCollection profIds = civilAlignment.GetProfileIds(); foreach (ObjectId pId in profIds) { Autodesk.Civil.DatabaseServices.Profile civilProfile = (Autodesk.Civil.DatabaseServices.Profile)trans.GetObject(pId, OpenMode.ForRead); if (civilProfile.Name == name) { name = oName + " - " + copy; copy += 1; } } } ObjectId newProfileId = Autodesk.Civil.DatabaseServices.Profile.CreateFromSurface(name, parentAlignment.InternalObjectId, parentSurface.InternalObjectId, layerId, styleId, labelSetId); newProfile = (Autodesk.Civil.DatabaseServices.Profile)trans.GetObject(newProfileId, OpenMode.ForRead); trans.Commit(); } if (newProfile == null) { return(null); } else { return(new Profile(newProfile, true)); } }
public void SelectAlignment() { using (Transaction tr = db.TransactionManager.StartTransaction()) { try { PromptEntityOptions prEntOpts = new PromptEntityOptions("\nPlease select exsisting alignment: "); prEntOpts.AllowNone = true; prEntOpts.SetRejectMessage("\n Selected object must be an alignment type"); prEntOpts.AddAllowedClass(typeof(Alignment), true); PromptEntityResult prEntRes = ed.GetEntity(prEntOpts); if (prEntRes.Status != PromptStatus.OK) { MessageBox.Show("Please repeat selection", "Info", MessageBoxButtons.OK); } else { Alignment alig = tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead) as Alignment; ed.WriteMessage("\n You selected alignment: " + alig.Name); selectedALig = alig; ObjectIdCollection profIds = selectedALig.GetProfileIds(); foreach (ObjectId id in profIds) { Autodesk.Civil.DatabaseServices.Profile prof = tr.GetObject(id, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Profile; profiles.Add(prof); } tr.Commit(); } } catch (System.Exception ex) { ed.WriteMessage("Error encountered" + ex.Message); tr.Abort(); selectedALig = null; } } }
private void CreateProfileFromEntities(ProfileEntity pentity, Autodesk.Civil.DatabaseServices.Profile Eprofile, Autodesk.Civil.DatabaseServices.Profile Nprofile, Point2d startPoint, Point2d endPoint) { using (Transaction tr = db.TransactionManager.StartTransaction()) { switch (pentity.EntityType) { case ProfileEntityType.Tangent: ProfileTangent pTangent = Nprofile.Entities.AddFixedTangent(startPoint, endPoint); break; case ProfileEntityType.Circular: ProfileCircular pCircular = pentity as ProfileCircular; ProfilePVI pPVI = Eprofile.PVIs.GetPVIAt(pCircular.PVIStation, pCircular.PVIElevation); double circleLength = pCircular.Length; ProfileCircular pCircularNew = Nprofile.Entities.AddFreeCircularCurveByPVIAndLength(pPVI, circleLength); break; case ProfileEntityType.ParabolaSymmetric: ProfileParabolaSymmetric pParabolaSymetric = pentity as ProfileParabolaSymmetric; double parabolaRadius = pParabolaSymetric.Radius; VerticalCurveType vcType = pParabolaSymetric.CurveType; ProfileParabolaSymmetric pParabolaSymetricNew = Nprofile.Entities.AddFixedSymmetricParabolaByTwoPointsAndRadius(startPoint, endPoint, vcType, parabolaRadius); break; case ProfileEntityType.ParabolaAsymmetric: ProfileParabolaAsymmetric pParabolaAsymmetric = pentity as ProfileParabolaAsymmetric; ProfilePVI paPVI = Eprofile.PVIs.GetPVIAt(pParabolaAsymmetric.PVIStation, pParabolaAsymmetric.PVIElevation); double pLength1 = pParabolaAsymmetric.AsymmetricLength1; double pLength2 = pParabolaAsymmetric.AsymmetricLength2; ProfileParabolaAsymmetric pParabolaAsymmetricNew = Nprofile.Entities.AddFreeAsymmetricParabolaByPVIAndLengths(paPVI, pLength1, pLength2); break; case ProfileEntityType.None: ProfileTangent nTangent = Nprofile.Entities.AddFixedTangent(startPoint, endPoint); break; } tr.Commit(); } }
public static Point3dCollection Get3dPath(Polyline polyline, ACD.Profile profile) { Point3d point; double interval = 1.0; var points = new Point3dCollection(); var station = -interval; double elevation; do { station += interval; if (station > polyline.Length) { station = polyline.Length; } elevation = profile.ElevationAt(station); point = polyline.GetPointAtDist(station); point = new Point3d(point.X, point.Y, elevation); points.Add(point); } while (station < polyline.Length); return(points); }
private void CreateProfil(double station1, double station2) { using (Transaction tr = db.TransactionManager.StartTransaction()) { // gets the existing profile Autodesk.Civil.DatabaseServices.Profile profile = profiles.SingleOrDefault(x => x.Name == profileName); ProfilePVICollection pPviCollExist = profile.PVIs; ObjectId labelSetId = CivilApplication.ActiveDocument.Styles.LabelSetStyles.ProfileLabelSetStyles["_No Labels"]; ObjectId profileStyleId = CivilApplication.ActiveDocument.Styles.ProfileStyles["Design Profile"]; ObjectId oProfileId = Autodesk.Civil.DatabaseServices.Profile.CreateByLayout("Copied profile", newAlig.ObjectId, newAlig.LayerId, profileStyleId, labelSetId); Autodesk.Civil.DatabaseServices.Profile newProfile = tr.GetObject(oProfileId, OpenMode.ForWrite) as Autodesk.Civil.DatabaseServices.Profile; if (pPviCollExist.Count <= 3) { Point2d point1 = new Point2d(station1, profile.ElevationAt(station1)); Point2d point2 = new Point2d(station2, profile.ElevationAt(station2)); CreateProfileFromEntities(profile.Entities[0], profile, newProfile, point1, point2); tr.Commit(); } else { // finding values near our start station for copied alignment ProfilePVI pPviExistStart = pPviCollExist.GetPVIAt(station1, profile.ElevationAt(station1)); ProfilePVI pPviExistEnd = pPviCollExist.GetPVIAt(station2, profile.ElevationAt(station2)); ProfileEntity pEntitiyAfter = profile.Entities.EntityAtId(pPviExistStart.EntityAfter); Point2d pviEndPoint = new Point2d(pEntitiyAfter.StartStation, pEntitiyAfter.StartElevation); ProfileEntity pEntitiyBefore = profile.Entities.EntityAtId(pPviExistEnd.EntityBefore); Point2d pviStartPoint = new Point2d(pEntitiyBefore.EndStation, pEntitiyBefore.EndElevation); ProfileEntity pStartEntity = pPviExistStart.VerticalCurve; ProfileEntity pEndEntity = pPviExistEnd.VerticalCurve; ProfileEntityCollection pEntities = profile.Entities; uint index = pEntities.FirstEntity; Point2d firstPoint = new Point2d(station1, profile.ElevationAt(station1)); CreateProfileFromEntities(pStartEntity, profile, newProfile, firstPoint, pviEndPoint); int counter = 0; try { while (true) { ProfileEntity pEntity = pEntities.EntityAtId(index); if (pEntity.StartStation >= station1 && pEntity.EndStation <= station2) { Point2d StartPoint = new Point2d(pEntity.StartStation, pEntity.StartElevation); Point2d EndPoint = new Point2d(pEntity.EndStation, pEntity.EndElevation); CreateProfileFromEntities(pEntity, profile, newProfile, StartPoint, EndPoint); counter++; } if (pEntity.StartStation <= station1 && pEntity.EndStation >= station2) { oneEntity = pEntity; } index = pEntity.EntityAfter; } } catch { if (counter == 0) { Point2d point1 = new Point2d(station1, profile.ElevationAt(station1)); Point2d point2 = new Point2d(station2, profile.ElevationAt(station2)); CreateProfileFromEntities(oneEntity, profile, newProfile, point1, point2); } else { Point2d endPoint = new Point2d(station2, profile.ElevationAt(station2)); CreateProfileFromEntities(pEndEntity, profile, newProfile, pviStartPoint, endPoint); } } tr.Commit(); } } }