getXRefTinSurface(ObjectId idbr, string nameSurf) { TinSurface s = null; try { using (Transaction tr = BaseObjs.startTransactionDb()) { BlockReference br = (BlockReference)tr.GetObject(idbr, OpenMode.ForRead); ObjectId idbtr = br.BlockTableRecord; BlockTableRecord btr = (BlockTableRecord)idbtr.GetObject(OpenMode.ForRead); foreach (ObjectId idObj in btr) { Entity ent = (Entity)tr.GetObject(idObj, OpenMode.ForRead); if (ent is TinSurface) { s = (TinSurface)ent; if (s.Name == nameSurf) { break; } } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " xRef.cs: line: 1203"); } return(s); }
protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw) { Circle c = new Circle(CenterPoint, new Vector3d(0, 0, 1), 10); //c.Annotative = AnnotativeStates.True; //c.Annotative c.ColorIndex = 151; ConnectionPointEntity = c; //~~~~~~~~ SCALE ~~~~~~~~~~ Matrix3d trans1 = Matrix3d.Scaling(MyScale, new Point3d(CenterPoint.X, CenterPoint.Y, 0)); //foreach (Entity en in Entities) //{ ConnectionPointEntity.TransformBy(trans1); //} //~~~~~~~~~~~~~~~~~~~~~~~~~ draw.Geometry.Draw(ConnectionPointEntity); return(true); }
selectEntity(System.Type classType, string message, string reject, out Point3d pnt3dPicked, out PromptStatus ps) { Entity ent = null; BaseObjs.acadActivate(); PromptEntityOptions peos = new PromptEntityOptions(message); peos.SetRejectMessage(reject); peos.AddAllowedClass(classType, true); peos.AllowNone = true; PromptEntityResult per = BaseObjs._editor.GetEntity(peos); pnt3dPicked = per.PickedPoint; ps = per.Status; switch (ps) { case PromptStatus.OK: try { using (Transaction tr = BaseObjs.startTransactionDb()) { ent = (Entity)tr.GetObject(per.ObjectId, OpenMode.ForRead); tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Select.cs: line: 599"); } break; } return(ent); }
private void gotoPoint(Button btn) { Entity entX = null; using (BaseObjs._acadDoc.LockDocument()) { Handle h = btn.Content.ToString().stringToHandle(); entX = h.getEnt(); pnt = (CogoPoint)entX; Point3d pnt3dIns = pnt.Location; ViewTableRecord vtr = new ViewTableRecord(); vtr.CenterPoint = new Point2d(pnt3dIns.X, pnt3dIns.Y); vtr.Height = 30; vtr.Width = 50; BaseObjs._editor.SetCurrentView(vtr); pnt.Highlight(); BaseObjs.acadActivate(); ObjectId[] idsPntArr = new ObjectId[] { pnt.ObjectId }; List <ObjectId> idPnt = Base_Tools45.Select.getEntityatPoint(pnt3dIns, typeof(CogoPoint), "*"); ed.SelectionAdded += ed_SelectionAdded; proceed = true; } }
deleteObjs(ObjectId[] ids) { try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId idObj in ids) { try { Entity ENT = (Entity)idObj.GetObject(OpenMode.ForWrite); ENT.Erase(); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 503"); } } tr.Commit(); } // end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 511"); } }
static public void GetEnt() { AcEd.Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor; PromptResult rs = ed.GetString("\nВведите метку примитива (в hex-представлении): "); if (rs.Status != PromptStatus.OK) { return; } System.Int64 l = System.Int64.Parse(rs.StringResult, System.Globalization.NumberStyles.HexNumber); AcDb.Handle h = new AcDb.Handle(l); AcDb.Database db = AcDb.HostApplicationServices.WorkingDatabase; AcDb.ObjectId id = db.GetObjectId(false, h, 0); if (!id.IsValid) { ed.WriteMessage("\nОшибочная метка примитива {0}", h); return; } using (AcAp.DocumentLock doclock = ed.Document.LockDocument()) { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.Entity ent = tr.GetObject(id, AcDb.OpenMode.ForRead) as AcDb.Entity; if (ent != null) { ed.WriteMessage("\nEntity Class: {0}", AcRx.RXClass.GetClass(ent.GetType()).Name); // Ну и так далее - делаешь с примитивом то, что тебе нужно... } else { ed.WriteMessage("\nЭто не примитив!"); } } } }
checkObject(ObjectId idEnt) { color = new Color(); color = Color.FromColorIndex(ColorMethod.ByBlock, 6); switch (idEnt.getType()) { case "Arc": case "Line": case "Polyline": case "Polyline3d": case "Alignment": idEnt.changeProp(color, idEnt.getLayer(), LineWeight.LineWeight050); return(true); case "PolylineVertex3d": Entity ent = idEnt.getEnt(); Polyline3d poly3d = (Polyline3d)ent.OwnerId.getEnt(); idEnt.changeProp(color, idEnt.getLayer(), LineWeight.LineWeight050); return(true); default: return(false); } }
deleteObjs(TypedValue[] TVs, Point3d pnt3dLL, Point3d pnt3dUR) { ObjectId[] ids; SelectionFilter filter = new SelectionFilter(TVs); PromptSelectionResult PSR = BaseObjs._editor.SelectCrossingWindow(pnt3dLL, pnt3dUR, filter); if (PSR.Status == PromptStatus.OK) { ids = PSR.Value.GetObjectIds(); } else { return; } try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId idObj in ids) { Entity ENT = (Entity)idObj.GetObject(OpenMode.ForWrite, true); ENT.Erase(); } tr.Commit(); } // end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 433"); } }
public static void Explode(Autodesk.AutoCAD.DatabaseServices.Entity ent, List <Autodesk.AutoCAD.DatabaseServices.DBObject> entities) { var objs = new DBObjectCollection(); if (ent != null) { entities.Add(ent); try { ent.Explode(objs); } catch { } if (objs.Count == 0) { return; } else { foreach (Autodesk.AutoCAD.DatabaseServices.Entity obj in objs) { Explode(obj, entities); } } } }
private MassElement[] GetSelectedMassElement() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptSelectionOptions Opts = new PromptSelectionOptions(); PromptSelectionResult psr = ed.GetSelection(Opts); if (psr.Status == PromptStatus.OK) { Autodesk.AutoCAD.EditorInput.SelectionSet ss = psr.Value; Autodesk.AutoCAD.DatabaseServices.ObjectId[] oids = ss.GetObjectIds(); int count = oids.Length; MassElement[] result = new MassElement[count]; Database db = Application.DocumentManager.MdiActiveDocument.Database; Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; Transaction trans = tm.StartTransaction(); MassElement me = new MassElement(); for (int i = 0; i < count; i++) { Autodesk.AutoCAD.DatabaseServices.Entity ety = tm.GetObject(oids[i], OpenMode.ForWrite, true) as Autodesk.AutoCAD.DatabaseServices.Entity; result[i] = ety as MassElement; } trans.Commit(); trans.Dispose(); return(result); } return(null); }
public PathInfo(AcadDB.Entity r, AcadDB.Entity sr, AcadDB.Entity p, AcadGeo.Point3d sp) { region = r; sub_region = sr; path = p; start_position = sp; }
cloneAndXformObjects(Database db, ObjectIdCollection entsToClone, ObjectId ownerBlockId, Matrix3d xformMat) { try { using (Transaction tr = BaseObjs.startTransactionDb()) { IdMapping idMap = new IdMapping(); db.DeepCloneObjects(entsToClone, ownerBlockId, idMap, false); // walk through all the cloned objects and Xform any of the entities foreach (IdPair idpair in idMap) { if (idpair.IsCloned) { DBObject clonedObj = tr.GetObject(idpair.Value, OpenMode.ForWrite); Entity clonedEnt = clonedObj as Entity; if (clonedEnt != null) { clonedEnt.TransformBy(xformMat); } } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Db.cs: line: 46"); } }
getXdata(Entity ent, string nameApp, out List <Object> typeOut, out List <Object> valOut) { bool isEmpty = true; List <Object> type = new List <Object>(); List <Object> val = new List <Object>(); try { using (Transaction tr = BaseObjs.startTransactionDb()) { ResultBuffer rb = ent.GetXDataForApplication(nameApp); if (rb != null) { foreach (TypedValue tv in rb) { type.Add(tv.TypeCode); val.Add(tv.Value); } isEmpty = false; } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " xData.cs: line: 279"); } typeOut = type; valOut = val; return(isEmpty); }
clearAllXdata() { bool escape = true; Entity ent = Select.selectEntity("Select ent:", out escape); if (escape) { return; } ResultBuffer rb = ent.ObjectId.getXData(null); if (rb == null) { return; } TypedValue[] tvs = rb.AsArray(); List <string> apps = new List <string>(); List <TypedValue[]> tvsList = tvs.parseXData(out apps); foreach (string n in apps) { ent.ObjectId.clearXData(n); } }
isTG(BlockTableRecord objXRefDbModelSpace, Handle varHandle) { foreach (ObjectId id in objXRefDbModelSpace) { Entity objXRefObj = id.getEnt(); if (objXRefObj.Handle == varHandle) { BlockReference objBlkRef = (BlockReference)objXRefObj; var varAtts = objBlkRef.AttributeCollection; ObjectId idAtt = varAtts[1]; using (Transaction tr = BaseObjs.startTransactionDb()) { AttributeReference objAttRef = (AttributeReference)tr.GetObject(idAtt, OpenMode.ForRead); //per characteristics of FL/TG callout if (objAttRef.TextString.Contains("TG")) { return(true); } tr.Commit(); } } } return(false); }
/// <summary> /// Get layer name by select a object /// </summary> /// <param name="msg"></param> /// <param name="doc"></param> /// <returns></returns> public static string getLayerName(string msg, Document doc) { //Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; string sLayer = null; PromptEntityResult per = ed.GetEntity(msg); if (per.Status == PromptStatus.OK) { ObjectId objectId = per.ObjectId; try { using (Transaction trans = db.TransactionManager.StartTransaction()) { //Get the entity Autodesk.AutoCAD.DatabaseServices.Entity ent = trans.GetObject(objectId, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Entity; sLayer = ent.Layer; } } catch { } } return(sLayer); }
getBLDG(BlockTableRecord objXRefDbModelSpace) { List <ObjectId> idsPoly = new List <ObjectId>(); foreach (ObjectId id in objXRefDbModelSpace) { Entity objXRefObj = id.getEnt(); if (objXRefObj is Polyline) { if (objXRefObj.Layer.Contains("BLDG")) { idsPoly.Add(id); //test if grid is inside this boundary to match up grid to bldg limit } } } if (idsPoly.Count == 0) { return(null); } ObjectIdCollection ids = new ObjectIdCollection(); using (Transaction tr = BaseObjs.startTransactionDb()) { BlockTable bt = (BlockTable)objXRefDbModelSpace.Database.BlockTableId.GetObject(OpenMode.ForRead); BlockReference br = (BlockReference)objXRefDbModelSpace.OwnerId.GetObject(OpenMode.ForRead); ids = xRef.copyXRefEnts(br.ObjectId, idsPoly); } Polyline objPoly = (Polyline)ids[0].getEnt(); return(objPoly); }
deleteObjs(TypedValue[] TVs) { SelectionSet ss = Select.buildSSetBase(TVs, true); if (ss == null) { return; } try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId idObj in ss.GetObjectIds()) { Entity ENT = (Entity)idObj.GetObject(OpenMode.ForWrite, true); ENT.Erase(); } tr.Commit(); } // end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 458"); } }
public static List <ObjectId> getLeaders() { List <ObjectId> ids = new List <ObjectId>(); using (var tr = BaseObjs.startTransactionDb()) { var bt = (BlockTable)tr.GetObject( BaseObjs._db.BlockTableId, OpenMode.ForRead); var ms = (BlockTableRecord)tr.GetObject( bt[BlockTableRecord.ModelSpace], OpenMode.ForRead); foreach (ObjectId id in ms) { Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead); if (ent is Leader) { ids.Add(id); } } tr.Commit(); } return(ids); }
makeProfile(ObjectId idAlign) { Point3d pnt3dPick = Pub.pnt3dO; if (idAlign == ObjectId.Null) { Autodesk.AutoCAD.DatabaseServices.Entity ent = Select.selectEntity(typeof(Alignment), "\nSelect Alignment: ", "\nSelected object was not an alignment. Try again: ", out pnt3dPick); idAlign = ent.ObjectId; } bool exists = false; ProfileView pView = null; using (BaseObjs._acadDoc.LockDocument()) { TinSurface tinSurf = Surf.getTinSurface("EXIST", out exists); string nameProfile = tinSurf.Name; Profile profEX = Prof.addProfileBySurface(nameProfile, idAlign, tinSurf.ObjectId, fMNP.idLayer, fMNP.idProfileStyleEX, fMNP.idProfileLabelSetEX); tinSurf = Surf.getTinSurface("CPNT-ON", out exists); nameProfile = tinSurf.Name; Profile profDE = Prof.addProfileBySurface(nameProfile, idAlign, tinSurf.ObjectId, fMNP.idLayer, fMNP.idProfileStyleDE, fMNP.idProfileLabelSetDE); fMNP.idProfile = profDE.ObjectId; PromptStatus ps; pnt3dPick = UserInput.getPoint("Select insertion point for Profile View", out ps, osMode: 0); pView = Prof.addProfileView(idAlign, pnt3dPick, fMNP.idProfileBandSetStyle, fMNP.idProfileViewStyle); } return(pView.ObjectId); }
explode(this ObjectId[] ids) { ObjectIdCollection idsEx = new ObjectIdCollection(); using (Transaction tr = BaseObjs.startTransactionDb()) { for (int i = 0; i < ids.Length; i++) { try { Entity ent = (Entity)tr.GetObject(ids[i], OpenMode.ForWrite); DBObjectCollection dbObjs = new DBObjectCollection(); ent.Explode(dbObjs); ent.Erase(); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(BaseObjs._db.CurrentSpaceId, OpenMode.ForWrite); foreach (DBObject dbObj in dbObjs) { Entity entX = (Entity)dbObj; idsEx.Add(ms.AppendEntity(entX)); tr.AddNewlyCreatedDBObject(entX, true); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 390"); } } tr.Commit(); } return(idsEx); }
selectEntity(string message, out bool escape) { escape = false; Entity ent = null; BaseObjs.acadActivate(); PromptEntityOptions peos = new PromptEntityOptions(message); peos.AllowNone = false; PromptEntityResult per = BaseObjs._editor.GetEntity(peos); if (per.Status == PromptStatus.OK) { using (Transaction tr = BaseObjs.startTransactionDb()) { ent = (Entity)tr.GetObject(per.ObjectId, OpenMode.ForRead); tr.Commit(); } } else { escape = true; } return(ent); }
moveSite(this ObjectIdCollection ids, Point3d pnt3dFrom, Point3d pnt3dTo) { Vector3d v3d = pnt3dFrom.GetVectorTo(pnt3dTo); try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId id in ids) { Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite); if (ent is CogoPoint) { CogoPoint cgPnt = (CogoPoint)ent; Point3d cgPntLoc = id.getCogoPntCoordinates(); Point3d cgPntNew = cgPntLoc.TransformBy(Matrix3d.Displacement(v3d)); cgPnt.Easting = cgPntNew.X; cgPnt.Northing = cgPntNew.Y; } else { ent.TransformBy(Matrix3d.Displacement(v3d)); } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 587"); } }
selectEntity(string message, string reject, out bool escape) { escape = true; ObjectId idEnt = ObjectId.Null; BaseObjs.acadActivate(); PromptEntityOptions PEOS = new PromptEntityOptions(message); PEOS.SetRejectMessage(reject); PEOS.AddAllowedClass(typeof(Line), true); PEOS.AddAllowedClass(typeof(Arc), true); PEOS.AddAllowedClass(typeof(Polyline), true); PEOS.AllowNone = false; PromptEntityResult PER = BaseObjs._editor.GetEntity(PEOS); if (PER.Status == PromptStatus.OK) { try { using (Transaction tr = BaseObjs.startTransactionDb()) { Entity ENT = (Entity)tr.GetObject(PER.ObjectId, OpenMode.ForRead); idEnt = ENT.ObjectId; escape = false; tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Select.cs: line: 635"); } } return(idEnt); }
getXRefEntsByLayer(ObjectId idBlkRef, string nameLayer) { ObjectIdCollection idEnts = new ObjectIdCollection(); try { using (Transaction tr = BaseObjs.startTransactionDb()) { BlockReference br = (BlockReference)tr.GetObject(idBlkRef, OpenMode.ForRead); ObjectId idbtr = br.BlockTableRecord; BlockTableRecord btr = (BlockTableRecord)idbtr.GetObject(OpenMode.ForRead); foreach (ObjectId idObj in btr) { Entity ent = (Entity)tr.GetObject(idObj, OpenMode.ForRead); if (ent.Layer.Contains(nameLayer)) { idEnts.Add(idObj); } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " xRef.cs: line: 1049"); } return(idEnts); }
Extents() { m_db = Utils.Db.GetCurDwg(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = m_db.TransactionManager; while (true) { PromptEntityResult prEntRes = ed.GetEntity("\nSelect entity to show extents"); if (prEntRes.Status != PromptStatus.OK) { break; } using (Autodesk.AutoCAD.DatabaseServices.Transaction tr = tm.StartTransaction()) { AcDb.Entity ent = (AcDb.Entity)tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead); Extents3d ext = ent.GeometricExtents; Point3d centerPt = Utils.Ge.Midpoint(ext.MinPoint, ext.MaxPoint); Utils.AcadUi.PrintToCmdLine(string.Format("\nEXTMIN: {0}", Utils.AcadUi.PtToStr(ext.MinPoint))); Utils.AcadUi.PrintToCmdLine(string.Format("\nEXTMAX: {0}", Utils.AcadUi.PtToStr(ext.MaxPoint))); Utils.AcadUi.PrintToCmdLine(string.Format("\nCENTER PT: {0}", Utils.AcadUi.PtToStr(centerPt))); tr.Commit(); MakeExtentsBlock(ext); } } }
public DrawMafsalJig(double Scale) { MyScale = Scale; Circle c = new Circle(CenterPoint, new Vector3d(0, 0, 0), 10); c.ColorIndex = 3; ConnectionPointEntity = c; }
getDockLimits() { List <Point3d> pnts3d = new List <Point3d>(); Point3d pnt3dPick; Entity ent = Select.selectEntity(typeof(Polyline3d), "\nSelect Finish Floor 3d Polyline: ", "3d Polyline selection failed. Exiting...", out pnt3dPick); Polyline3d poly3d = (Polyline3d)ent; ResultBuffer rb = poly3d.ObjectId.getXData("AVG"); if (rb == null) { return(pnts3d); } TypedValue[] tvs = rb.AsArray(); bldgNum = tvs[2].Value.ToString(); using (BaseObjs._acadDoc.LockDocument()) { Object selectCycling = Application.GetSystemVariable("SELECTIONCYCLING"); Application.SetSystemVariable("SELECTIONCYCLING", 0); Object osMode = SnapMode.getOSnap(); SnapMode.setOSnap((int)osModes.END); PromptStatus ps; try { bool escape = false; Point3d pnt3dRet = UserInput.getPoint("\nSelect Dock Begin point (CCW orientation)", Pub.pnt3dO, out escape, out ps, osMode: 1); if (escape) { return(pnts3d); } pnts3d.Add(pnt3dRet); pnt3dRet = UserInput.getPoint("\nSelect Dock End point (CCW orientation)", pnt3dRet, out escape, out ps, osMode: 1); if (escape) { return(pnts3d); } pnts3d.Add(pnt3dRet); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " cmdGD_old.cs: line: 284"); } finally { Application.SetSystemVariable("SELECTIONCYCLING", selectCycling); SnapMode.setOSnap((int)osMode); } } return(pnts3d); }
addXData(Entity ent, string nameApp, List <short> type, List <object> val) { TypedValue[] TVs = new TypedValue[type.Count]; for (int i = 0; i < type.Count; i++) { TVs.SetValue(new TypedValue(type[i], val[i]), i); } addXData(ent.ObjectId, TVs, nameApp); }
public static MapValue ReadPipeSystem(Entity ent) { string layer = ent.Layer; switch (layer) { case "FJV-TWIN-DN32": case "FJV-TWIN-DN40": case "FJV-TWIN-DN50": case "FJV-TWIN-DN65": case "FJV-TWIN-DN80": case "FJV-TWIN-DN100": case "FJV-TWIN-DN125": case "FJV-TWIN-DN150": case "FJV-TWIN-DN200": return(new MapValue("Twin")); case "FJV-FREM-DN32": case "FJV-RETUR-DN32": case "FJV-FREM-DN40": case "FJV-RETUR-DN40": case "FJV-FREM-DN50": case "FJV-RETUR-DN50": case "FJV-FREM-DN65": case "FJV-RETUR-DN65": case "FJV-FREM-DN80": case "FJV-RETUR-DN80": case "FJV-FREM-DN100": case "FJV-RETUR-DN100": case "FJV-FREM-DN125": case "FJV-RETUR-DN125": case "FJV-FREM-DN150": case "FJV-RETUR-DN150": case "FJV-FREM-DN200": case "FJV-RETUR-DN200": case "FJV-FREM-DN250": case "FJV-RETUR-DN250": case "FJV-FREM-DN300": case "FJV-RETUR-DN300": case "FJV-FREM-DN350": case "FJV-RETUR-DN350": case "FJV-FREM-DN400": case "FJV-RETUR-DN400": case "FJV-FREM-DN450": case "FJV-RETUR-DN450": case "FJV-FREM-DN500": case "FJV-RETUR-DN500": case "FJV-FREM-DN600": case "FJV-RETUR-DN600": return(new MapValue("Enkelt")); default: prdDbg("For entity: " + ent.Handle.ToString() + " no system could be determined!"); return(new MapValue("Unknown")); } }