getAlignmentPoly(Alignment align) { ObjectId id = align.GetPolyline(); Polyline poly = (Polyline)id.GetObject(OpenMode.ForRead); return(poly); }
getAlignmentPoly(ObjectId idAlign) { Alignment align = (Alignment)idAlign.GetObject(OpenMode.ForRead); ObjectId idPoly = align.GetPolyline(); return(idPoly); }
public static Polyline3d AlignmentToPolyline3d2(Alignment alignment, Profile profile) { Point3d point; Polyline3d p3d = null; var elevations = new Point3dCollection(); var station = 0d; double elevation; var db = alignment.Database; using (var tr = db.TransactionManager.StartTransaction()) { var polylineId = alignment.GetPolyline(); using (var polyline = tr.GetObject(polylineId, OpenMode.ForRead) as Polyline) { do { station += 0.001; if (station > polyline.Length) { station = polyline.Length; } elevation = profile.ElevationAt(station); point = polyline.GetPointAtDist(station); point = new Point3d(point.X, point.Y, elevation); elevations.Add(point); } while (station < polyline.Length); var fid = FeatureLine.Create("george", polylineId); var featureLine = tr.GetObject(fid, OpenMode.ForWrite) as FeatureLine; foreach (Point3d p in elevations) { featureLine.InsertElevationPoint(p); } var objs = new DBObjectCollection(); featureLine.Explode(objs); p3d = new Polyline3d(Poly3dType.SimplePoly, elevations, polyline.Closed); } } return(p3d); }
public static Polyline3d AlignmentToPolyline3d(Alignment alignment, Profile profile) { Point3d point; Polyline3d p3d = null; double interval = 1.0; var elevations = new Point3dCollection(); var station = -interval; double elevation; var db = alignment.Database; using (var tr = db.TransactionManager.StartTransaction()) { var polylineId = alignment.GetPolyline(); using (var polyline = tr.GetObject(polylineId, OpenMode.ForRead) as Polyline) { 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); elevations.Add(point); } while (station < polyline.Length); p3d = new Polyline3d(Poly3dType.SimplePoly, elevations, polyline.Closed); } } TotalDistance(elevations); foreach (var x in p3d) { var y = x; } return(p3d); }
changeAlignStartPoint() { //BEGIN: UPDATE PROFILE, TABLE, AND POIs AlgnData algnData = new AlgnData(); ObjectId idAlign = ObjectId.Null; Alignment objAlign = null; if (selectAlignment(idAlign)) { objAlign = fStake.ACTIVEALIGN; } else { return; } objAlign = fStake.ACTIVEALIGN; AlignmentEntityCollection objAlignEnts = objAlign.Entities; //BEGIN: UPDATE PROFILE, TABLE, AND POIs double dblLenAlign = objAlign.Length; PromptStatus ps; Point3d varPnt = UserInput.getPoint("Select Desired Start Point", out ps, osMode: 0); double dblStation = 0, dblOffset = 0; idAlign.getAlignStaOffset(varPnt, ref dblStation, ref dblOffset); double dblStationStart = objAlign.StartingStation; double dblStationDelta = dblStation - dblStationStart; // if varPnt is out of range then dblStation returns ZERO Profile profFLOWLINE = Prof.getProfile(idAlign, "FLOwLINE"); ProfilePVICollection pvis = profFLOWLINE.PVIs; List <POI> varPOI_Temp = new List <POI>(); foreach (ProfilePVI pvi in pvis) { POI poi = new POI { Station = Math.roundDown3(pvi.Station), Elevation = pvi.Elevation }; varPOI_Temp.Add(poi); } Debug.Print("varPOI_Temp Before"); for (int i = 0; i < varPOI_Temp.Count; i++) { Debug.Print(varPOI_Temp[i].Station + " " + varPOI_Temp[i].Elevation); } //adjust POI_Temp stationing for (int i = 0; i < varPOI_Temp.Count; i++) { POI poi = varPOI_Temp[i]; if (poi.Station < dblStationDelta + dblStationStart) { poi.Station = Math.roundDown3(dblLenAlign + varPOI_Temp[i].Station); } else { poi.Station = Math.roundDown3(varPOI_Temp[i].Station - dblStationDelta); } varPOI_Temp[i] = poi; } List <POI> poiTmp = new List <POI>(); var sortPOI_Temp = from t in varPOI_Temp orderby t.Station ascending select t; foreach (var t in sortPOI_Temp) { poiTmp.Add(t); } varPOI_Temp = poiTmp; int k = varPOI_Temp.Count; POI poitemp = varPOI_Temp[k - 1]; poitemp.Elevation = varPOI_Temp[0].Elevation; varPOI_Temp[k] = poitemp; Debug.Print("varPOI_Temp After"); for (int i = 0; i < k; i++) { Debug.Print(varPOI_Temp[i].Station + " " + varPOI_Temp[i].Elevation); } //END: UPDATE PROFILE, TABLE, AND POIs ObjectId idPoly = objAlign.GetPolyline(); Polyline poly = (Polyline)idPoly.getEnt(); string strAlignName = objAlign.Name; AlgnData aData; for (int j = 1; j < fStake.algnData.Count; j++) { aData = fStake.algnData[j]; if (aData.AlignHandle == objAlign.Handle) { break; } } objAlign.ReferencePointStation = 100.0; foreach (AlignmentEntity ent in objAlignEnts) { objAlignEnts.Remove(ent); } List <Vertex2d> v2ds = Conv.poly_Vertex2dList(idPoly); int p = 0; foreach (Vertex2d v in v2ds) { if (v.Position.IsEqualTo(varPnt, new Tolerance(0, 0))) { break; } p++; } List <Vertex2d> v2dsNew = new List <Vertex2d>(); for (int i = p; i < v2ds.Count; i++) { v2dsNew.Add(v2ds[i]); } for (int i = 1; i < p; i++) { v2dsNew.Add(v2ds[i]); } v2dsNew.Add(v2ds[p]); int lngID = 0; Point3d dblPntBeg = Pub.pnt3dO, dblPntEnd = Pub.pnt3dO, dblPntMid = Pub.pnt3dO; for (int i = 1; i < v2dsNew.Count; i++) { if (v2dsNew[i].Bulge == 0) { dblPntBeg = v2dsNew[i - 1].Position; dblPntEnd = v2dsNew[i = 0].Position; AlignmentLine objAlignEntTan = objAlign.Entities.AddFixedLine(lngID, dblPntBeg, dblPntEnd); lngID = objAlignEntTan.EntityId; } else { dblPntBeg = v2dsNew[i - 1].Position; dblPntEnd = v2dsNew[i = 0].Position; int intDir = 0; if (v2dsNew[i - 1].Bulge > 0) { intDir = 1; } else { intDir = -1; } Arc arc = (Arc)Arc.Create(IntPtr.Zero, true); arc.StartPoint = dblPntBeg; arc.EndPoint = dblPntEnd; Point3d pnt3dMidLC = dblPntBeg.getMidPoint3d(dblPntEnd); double lenLC = dblPntBeg.getDistance(dblPntEnd); double dirLC = dblPntBeg.getDirection(dblPntEnd); double lenM = System.Math.Abs(lenLC / 2 * v2dsNew[i - 1].Bulge); dblPntMid = pnt3dMidLC.traverse(dirLC + System.Math.PI / 2 * intDir, lenM); AlignmentArc objAlignEntArc = objAlign.Entities.AddFixedCurve(lngID, dblPntBeg, dblPntMid, dblPntEnd); lngID = objAlignEntArc.EntityId; } } objAlign.Update(); objAlign.ReferencePoint = varPnt.Convert2d(BaseObjs.xyPlane); objAlign.ReferencePointStation = System.Math.Round(100.0 + dblStationDelta, 3); //BEGIN: UPDATE PROFILE, TABLE, AND POIs List <POI> varpoi = fStake.POI_CALC; //POIs are updated when selectAlignment is executed //ADJUST POI STATIONING //need complete POIs for descriptions for (int i = 0; i < varpoi.Count; i++) { if (varpoi[i].Station < dblStationDelta + dblStationStart) { varpoi[i].Station = Math.roundDown3(dblLenAlign + varpoi[i].Station); } else { varpoi[i].Station = Math.roundDown3(varpoi[i].Station - dblStationDelta); } } varpoi = varpoi.sortPOIbyStation(); int n = varpoi.Count; varpoi[0].DescX = "BEG " + varpoi[0].Desc0; varpoi[n - 2].DescX = varpoi[n - 2].DescX.Replace("END", "").Trim(); varpoi[n - 1].DescX = varpoi[n - 1].DescX.Replace("BEG", "END").Trim(); if (fStake.ClassObj == "CURB") { Stake_AddProfile.makeProfile(idAlign, varPOI_Temp, "CURB", "ByLayout", true); } ObjectId idTable = Stake_Table.makeTable(idAlign, varpoi); Stake_Table.addTableData(idTable, varpoi); if (Stake_GetBC_EC.getBC_EC(idAlign, ref varpoi) == false) { return; } fStake.POI_CALC = varpoi; //END: UPDATE PROFILE, TABLE, AND POIs }
setBldgElevRef(Alignment objAlign) { TinSurface objSurface = null; bool exists = false; try { objSurface = Surf.getTinSurface("CPNT-ON", out exists); if (!exists) { Stake_GetSurfaceCPNT.getSurfaceFromXRef("STAKE", "STAKE"); objSurface = Surf.getTinSurface("CPNT-ON", out exists); } } catch (System.Exception) { } ObjectId idBldg = objAlign.GetPolyline(); Point3d pnt3d = idBldg.getCentroid(); Point3d pnt3dCen = new Point3d(pnt3d.X, pnt3d.Y, objSurface.FindElevationAtXY(pnt3d.X, pnt3d.Y)); if (pnt3dCen.Z == -99999.99) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Invalid Elevation at Reference Point - Exiting......."); return; } //Set objCircle = addcircle(pnt3dCEN, 3) //objCircle.color = acRed //objCircle.Update double dblAngTar = 0; int intMark = 0; idBldg.getEastWestBaseLineDir(ref dblAngTar, ref intMark); Point3d pnt3dTar = new Point3d(pnt3d.X, pnt3d.Y, objSurface.FindElevationAtXY(pnt3d.X, pnt3d.Y)); double dblSlope = System.Math.Round((pnt3dTar.Z - pnt3dCen.Z) / 100, 4); //Set objCircle = addcircle(pnt3dTAR, 3) //objCircle.color = acYellow //objCircle.Update if (dblSlope == 0) { dblAngTar = dblAngTar + PI / 2; if (dblAngTar > 2 * PI) { dblAngTar = dblAngTar - 2 * PI; } pnt3d = pnt3dCen.traverse(dblAngTar, 100); pnt3dTar = new Point3d(pnt3d.X, pnt3d.Y, objSurface.FindElevationAtXY(pnt3d.X, pnt3d.Y)); // Set objCircle = addcircle(pnt3dTAR, 3) // objCircle.color = acGreen // objCircle.Update if (System.Math.Round(dblSlope, 3) == 0) { pnt3d = pnt3dCen.traverse(dblAngTar - PI / 2, 100); //back to original orientation pnt3dTar = new Point3d(pnt3d.X, pnt3d.Y, objSurface.FindElevationAtXY(pnt3d.X, pnt3d.Y)); // Set objCircle = addcircle(pnt3dTAR, 3) // objCircle.color = acCyan // objCircle.Update } } else if (dblSlope < 0) { dblAngTar = dblAngTar + PI; if (dblAngTar > 2 * PI) { dblAngTar = dblAngTar - 2 * PI; } pnt3dTar = new Point3d(pnt3d.X, pnt3d.Y, objSurface.FindElevationAtXY(pnt3d.X, pnt3d.Y)); // Set objCircle = addcircle(pnt3dTAR, 3) // objCircle.color = acBlue // objCircle.Update dblSlope = -dblSlope; } BlockReference objBlkRef = null; using (Transaction tr = BaseObjs.startTransactionDb()) { try { List <string> attVals = new List <string> { dblSlope.ToString() }; objBlkRef = Blocks.addBlockRef("G:\\TOOLBOX\\Slparrow_STAKE.dwg", pnt3dCen, dblAngTar, attVals); objBlkRef.Layer = string.Format("STAKE-BLDG-{0}-LABEL", objAlign.Name); } catch (System.Exception) { } tr.Commit(); } idBldg.delete(); TypedValue[] tvs = new TypedValue[6] { new TypedValue(1001, "BLDG"), new TypedValue(1040, pnt3dCen.X), new TypedValue(1040, pnt3dCen.Y), new TypedValue(1040, pnt3dCen.Z), new TypedValue(1040, dblAngTar), new TypedValue(1040, dblSlope) }; objAlign.ObjectId.setXData(tvs, "STAKE"); }
// definira visinsko vođenje objekta // postoji mogućnost poboljšanja public Profile IzradaProfila(Alignment aligIn) { if (aligIn != null) { string ime = "Niveleta okomitog pera " + brojPera.ToString(); using (Transaction ts = AcAp.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()) { Alignment alig = aligIn; // postavke profila ObjectId layerProfila = alig.LayerId; ObjectId styleProfila = civDoc.Styles.ProfileStyles["Basic"]; ObjectId labelSetId = civDoc.Styles.LabelSetStyles.ProfileLabelSetStyles["_No Labels"]; // stvaranje praznog profila ObjectId ProfilPeraId = Profile.CreateByLayout(ime, alig.Id, layerProfila, styleProfila, labelSetId); // dodavanje elemenata u profil Profile ProfilPera = ts.GetObject(ProfilPeraId, OpenMode.ForRead) as Profile; // definiranje pointova Point3d prviPoint = TockaNaStacionazi(KodUzglavlje); Point3d drugiPoint = TockaNaStacionazi(KodZaglavlje); Point3d _prviPoint = new Point3d(prviPoint.X, prviPoint.Y, 0); Point3d _drugiPoint = new Point3d(drugiPoint.X, drugiPoint.Y, 0); Point3d GlavaPera = TockaNaStacionazi(KodGlave); // određivanje duljine iz polyline-a ObjectId pomocniPolyId = alig.GetPolyline(); Polyline pomocniPoly = ts.GetObject(pomocniPolyId, OpenMode.ForRead) as Polyline; double ukupnaDuljina = pomocniPoly.Length; double pocetnaDuljina = _prviPoint.DistanceTo(_drugiPoint); DuljinaPera = pocetnaDuljina; double duljinaLuka = ukupnaDuljina - 2 * pocetnaDuljina; // izrada pointova i dobivanje profila (mislim da se može brže) // dodatno istražiti // for petaljom ? Point2d profilePoint1 = new Point2d(alig.StartingStation, prviPoint.Z); Point2d profilePoint2 = new Point2d(alig.StartingStation + DuljinaPera, drugiPoint.Z); ProfileTangent Tangenta1 = ProfilPera.Entities.AddFixedTangent(profilePoint1, profilePoint2); Point2d profilePoint3 = new Point2d(Tangenta1.EndStation, Tangenta1.EndElevation); Point2d profilePoint4 = new Point2d(Tangenta1.EndStation + duljinaLuka / 2, GlavaPera.Z); ProfileTangent Tangenta2 = ProfilPera.Entities.AddFixedTangent(profilePoint3, profilePoint4); Point2d profilePoint5 = new Point2d(Tangenta2.EndStation, Tangenta2.EndElevation); Point2d profilePoint6 = new Point2d(Tangenta2.EndStation + duljinaLuka / 2, drugiPoint.Z); ProfileTangent Tangenta3 = ProfilPera.Entities.AddFixedTangent(profilePoint5, profilePoint6); Point2d profilePoint7 = new Point2d(Tangenta3.EndStation, Tangenta3.EndElevation); Point2d profilePoint8 = new Point2d(alig.EndingStation, prviPoint.Z); ProfileTangent Tangenta4 = ProfilPera.Entities.AddFixedTangent(profilePoint7, profilePoint8); ts.Commit(); return(ProfilPera); } } else { return(null); } }