private static void setPartGeometry(PipingProject prjpart, ObjectId objId, int rowId) { Database db = objId.Database; DataLinksManager dlm = prjpart.DataLinksManager; StringCollection props = new StringCollection(); StringCollection vals = new StringCollection(); using (Transaction trans = db.TransactionManager.StartTransaction()) { try { PnP3d.Part part = trans.GetObject(objId, OpenMode.ForRead) as PnP3d.Part; //if (part is Pipe) if (part is PnP3d.Pipe) { PnP3d.Pipe pipe = (PnP3d.Pipe)part; props.Add("Length"); vals.Add(pipe.Length.ToString()); props.Add("CutLength"); vals.Add(pipe.Length.ToString()); props.Add("Position X"); vals.Add(pipe.StartPoint.X.ToString()); props.Add("Position Y"); vals.Add(pipe.StartPoint.Y.ToString()); props.Add("Position Z"); vals.Add(pipe.StartPoint.Z.ToString()); } // else if () // Handle other Plant3D entity types // { // } // else // { // } dlm.SetProperties(rowId, props, vals); trans.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { // display exception on the command line Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage(ex.ToString()); trans.Abort(); } } }
private static ObjectId CreatePipe() { // Create a pipe PnP3d.Pipe p = new PnP3d.Pipe(); p.StartPoint = new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0); p.EndPoint = new Autodesk.AutoCAD.Geometry.Point3d(100, 0, 0); p.OuterDiameter = 10; ObjectId newId = ObjectId.Null; // Add the pipe to the current space, either model or paper space Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; if (bt != null) { BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; if (btr != null) { newId = btr.AppendEntity(p); trans.AddNewlyCreatedDBObject(p, true); trans.Commit(); } } } return(newId); }
public void pipeGet() { // Get the AutoCAD editor Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; //http://adndevblog.typepad.com/autocad/wayne-brill/ Project currentProject = PlantApplication.CurrentProject.ProjectParts["PnId"]; DataLinksManager dlm = currentProject.DataLinksManager; PnPDatabase pnpdb = dlm.GetPnPDatabase(); // Prompt the user to select a pipe entity PromptEntityOptions pmtEntOpts = new PromptEntityOptions("Select a Pipe : "); PromptEntityResult pmtEntRes = ed.GetEntity(pmtEntOpts); if (pmtEntRes.Status == PromptStatus.OK) { // Get the ObjectId of the selected entity ObjectId entId = pmtEntRes.ObjectId; // Use the using statement and start a transaction // Use the transactionManager created above (tm) using (Transaction trans = db.TransactionManager.StartTransaction()) { PnP3d.Pipe supP3DPipe = trans.GetObject(entId, OpenMode.ForRead) as PnP3d.Pipe; if (supP3DPipe == null) { ed.WriteMessage("\n Selected entity is not a Plant 3D Pipe"); } else { Point3d start = supP3DPipe.StartPoint; Point3d end = supP3DPipe.EndPoint; double len = supP3DPipe.Length; string lay = supP3DPipe.Layer; ed.WriteMessage( "\nProperties of selected Pipe: " + "\nStartpoint: " + start + "\nEndpoint: " + end + "\nLength: " + len + "\nLayer: " + lay ); } trans.Commit(); } } }
public static List <Datas> Pipes() { // Get the AutoCAD editor Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database acadDb = doc.Database; Editor ed = doc.Editor; List <Datas> list = new List <Datas>(); //http://adndevblog.typepad.com/autocad/wayne-brill/ Project currentProject = PlantApplication.CurrentProject.ProjectParts["PnId"]; DataLinksManager dlm = currentProject.DataLinksManager; PnPDatabase pnpdb = dlm.GetPnPDatabase(); TypedValue[] filterlist = new TypedValue[1]; filterlist[0] = new TypedValue(0, "ACPPPIPE"); SelectionFilter filter = new SelectionFilter(filterlist); PromptSelectionResult psr = ed.SelectAll(filter); SelectionSet sset = null; //Entity ent = null; //Line line = null; if (psr.Status == PromptStatus.OK) { sset = psr.Value; } using (Transaction trans = acadDb.TransactionManager.StartTransaction()) { if (sset != null) { for (int i = 0; i < sset.Count; i++) { try { PnP3d.Pipe supP3DPipe = trans.GetObject(sset[i].ObjectId, OpenMode.ForRead) as PnP3d.Pipe; if (supP3DPipe != null) { Point3d start = supP3DPipe.CenterOfGravity; Point3d end = supP3DPipe.EndPoint; double len = supP3DPipe.Length; string lay = supP3DPipe.Layer; list.Add(new Datas { Position = start, Content = lay }); //ed.WriteMessage( // "\nProperties of selected Pipe: " + // "\nStartpoint: " + start + // "\nEndpoint: " + end + // "\nLength: " + len + // "\nLayer: " + lay // ); } } catch (System.Exception ex) { ed.WriteMessage("\nËrror: " + ex); } } } trans.Commit(); } return(list); }