modSurface(string nameSurface, string descSurface, ObjectIdCollection idsPoly3d, bool boolNewSurface) { bool exists = false; TinSurface objSurface = Surf.getTinSurface(nameSurface, out exists); if (!exists) { objSurface.StyleId = Surf_Styles.getSurfaceStyle(nameSurface); } objSurface.BreaklinesDefinition.AddStandardBreaklines(idsPoly3d, 1, 0, 0, 0); objSurface.BuildOptions.CrossingBreaklinesElevationOption = Autodesk.Civil.CrossingBreaklinesElevationType.UseAverage; objSurface.Rebuild(); }
private static void extractContours(Surface surf) { if (surf is TinSurface) { if (surf.IsReferenceObject) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("Surface {0} is from {1}", surf.Name, surf.OwnerId.ToString())); return; } TinSurface tinSurf = (TinSurface)surf; string nameSurf = tinSurf.Name; ObjectId idStyle = tinSurf.StyleId; SurfaceStyle style = Surf_Styles.getSurfaceStyle(idStyle); double majorInt = style.ContourStyle.MajorContourInterval; double minorInt = style.ContourStyle.MinorContourInterval; DisplayStyle planDispStyle = style.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour); string majorLay = planDispStyle.Layer; planDispStyle = style.GetDisplayStylePlan(SurfaceDisplayStyleType.MinorContour); string minorLay = planDispStyle.Layer; ObjectIdCollection idsContours = tinSurf.ExtractContours(minorInt); Color color = new Color(); color = Color.FromColorIndex(ColorMethod.ByLayer, 256); using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId id in idsContours) { Polyline poly = (Polyline)tr.GetObject(id, OpenMode.ForRead); double elev = System.Math.Round(poly.Elevation, 2); if ((elev / majorInt).mantissa() == 0) { id.changeProp(color, majorLay, LineWeight.LineWeight030); } else { id.changeProp(color, minorLay, LineWeight.LineWeight020); } } tr.Commit(); } } }
checkSurfaceStyles(string varStyle = "") { ObjectId idSurfaceStyle = ObjectId.Null; if ((varStyle == "")) { Surf_Styles.getSurfaceStyle("EXIST"); Surf_Styles.getSurfaceStyle("CPNT"); Surf_Styles.getSurfaceStyle("SG"); Surf_Styles.getSurfaceStyle("OX"); Surf_Styles.getSurfaceStyle("BOT"); Surf_Styles.getSurfaceStyle("VOL"); } else { Surf_Styles.getSurfaceStyle(varStyle); } }
getSurfaceFromXRef(string nameSurf, string strSource) { string nameXRef = ""; if (nameSurf == "CPNT-ON") { nameXRef = "GCAL"; } if (nameSurf == "EXIST") { nameXRef = "CONT"; } ResultBuffer rb = xRef.getXRefsContainingTargetDwgName(nameXRef); TypedValue[] tvs = rb.AsArray(); switch (tvs.Length) { case 0: Application.ShowAlertDialog(string.Format("{0} not attached", nameXRef = (nameSurf == "CPNT-ON") ? "GCAL" : "CONT")); break; case 2: foreach (TypedValue tv in tvs) { if (tv.TypeCode == 1001) { nameXRef = tv.Value.ToString(); } } break; default: string prompt = string.Format("Multible {0} are attached. Select one to use for staking: ", nameXRef = (nameSurf == "CPNT-ON") ? "GCAL" : "CONT"); Application.ShowAlertDialog(prompt); fPickXref = Forms.Stake_Forms.sForms.fPickXref; foreach (TypedValue tv in tvs) { if (tv.TypeCode == 1001) { fPickXref.lboxSelectXref.Items.Add(tv.Value.ToString()); } } fPickXref.Text = string.Format("Multible {0} are attached. Select one to use for staking: ", nameXRef = (nameSurf == "CPNT-ON") ? "GCAL" : "CONT"); Application.ShowModalDialog(null, fPickXref, false); nameXRef = fPickXref.nameXRef; if (nameXRef == "") { return; } break; } Surf.removeSurface(nameSurf); BlockReference br = xRef.getXRefBlockReference(nameXRef); TinSurface s = xRef.getXRefTinSurface(br.Id, nameSurf); if (s == null) { return; } string nameLayer = string.Format("{0}-SURFACE", nameSurf); if (nameSurf == "CPNT-ON") { nameLayer = "CPNT-SURFACE"; } Layer.manageLayers(nameLayer); TinSurface surf = null; string nameStyle = "CPNT-ON"; using (Transaction tr = BaseObjs.startTransactionDb()) { if (nameSurf == "CONT") { nameStyle = "EXIST"; } ObjectId idStyle = Surf_Styles.getSurfaceStyle(nameStyle); ObjectId idSurf = TinSurface.Create(nameSurf, idStyle); surf = (TinSurface)idSurf.GetObject(OpenMode.ForWrite); surf.Layer = nameLayer; surf.Description = string.Format("COPIED FROM {0} - {1}", nameXRef, DateTime.Now); tr.Commit(); } surf.PasteSurface(s.ObjectId); Layer.manageLayer(nameLayer, layerFrozen: true); if (nameSurf == "CPNT-ON") { if (strSource == "STAKE") { sFrms.sForms.fStake.SurfaceCPNT = surf; } } }
doLabels() { Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("CMDECHO", 0); object osMode = SnapMode.getOSnap(); SnapMode.setOSnap(512); ObjectId idSurface = ObjectId.Null; using (BaseObjs._acadDoc.LockDocument()) { try { using (Transaction tr = BaseObjs.startTransactionDb()) { ObjectIdCollection ids = BaseObjs._civDoc.GetSurfaceIds(); switch (ids.Count) { case 0: Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog("There are Zero surfaces in this drawing. Exiting...."); return; case 1: idSurface = ids[0]; break; default: idSurface = getSurface(); break; } tr.Abort(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} ContourLabels.cs: line: 58", ex.Message)); } if (!idSurface.IsNull) { try { using (Transaction tr = BaseObjs.startTransactionDb()) { ObjectId idStyleMajor = Surf_Styles.getSurfaceContourLabelStyleId("Thienes_Major"); ObjectId idStyleMinor = Surf_Styles.getSurfaceContourLabelStyleId("Thienes_Minor"); PromptPointResult ppr; do { PromptPointOptions ppo = new PromptPointOptions("\nPick contour line."); ppr = BaseObjs._editor.GetPoint(ppo); if (ppr.Status == PromptStatus.OK) { Point3d pnt3d = ppr.Value; Surface surf = (Surface)idSurface.GetObject(OpenMode.ForWrite); double dir = surf.FindDirectionAtXY(pnt3d.X, pnt3d.Y); Point3d pnt3dTar1 = Geom.traverse_pnt3d(pnt3d, dir + System.Math.PI, 0.5); Point3d pnt3dTar2 = Geom.traverse_pnt3d(pnt3d, dir, 0.5); Point2dCollection pnts2d = new Point2dCollection(); pnts2d.Add(new Point2d(pnt3dTar1.X, pnt3dTar1.Y)); pnts2d.Add(new Point2d(pnt3dTar2.X, pnt3dTar2.Y)); doLabel(idSurface, pnts2d, idStyleMajor, idStyleMinor); //sclg.Annotative = AnnotativeStates.True; } else { break; } }while (ppr.Status == PromptStatus.OK); tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} ContourLabels.cs: line: 97", ex.Message)); } finally { SnapMode.setOSnap((int)osMode); } } } }