//this function is used to read all xdata of selected object // this is not used in dialog public static void fnreadXData(ObjectId objectid) { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { DBObject obj = tr.GetObject(objectid, OpenMode.ForRead); ResultBuffer rb = obj.XData; if (rb == null) { ed.WriteMessage("\nEntity does not have XData attached."); } else { int n = 0; foreach (TypedValue tv in rb) { ed.WriteMessage("\nTypedValue {0} - type: {1}, value: {2}", n++, tv.TypeCode, tv.Value); } rb.Dispose(); } } }
static public void Poly() { Document doc = Application.DocumentManager.MdiActiveDocument; using (DocumentLock l = doc.LockDocument()) { using (Transaction t = doc.Database.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); using (Autodesk.ObjectDbxSample.Poly poly = new Autodesk.ObjectDbxSample.Poly()) { poly.Center = new Point2d(100, 100); poly.StartPoint2d = new Point2d(300, 100); poly.NumberOfSides = 5; poly.Name = "Managed Poly"; btr.AppendEntity(poly); t.AddNewlyCreatedDBObject(poly, true); AddRegAppTableRecord("IOVIEWERSAMPLE"); ResultBuffer rb = new ResultBuffer(new TypedValue(1001, "IOVIEWERSAMPLE"), new TypedValue(1000, "This is a sample string")); poly.XData = rb; rb.Dispose(); } t.Commit(); } } }
//Function to load xdata of selected object // used in dialog public static string loadXData(ObjectId objectid, string appName) { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { DBObject obj = tr.GetObject(objectid, OpenMode.ForRead); Entity ent = (Entity)tr.GetObject(objectid, OpenMode.ForRead); ResultBuffer buffer = ent.GetXDataForApplication(appName.ToString()); if (buffer != null) { ResultBuffer rb = ent.XData; foreach (TypedValue tv in buffer) { if (tv.TypeCode == 1000) { return(tv.Value.ToString()); //ed.WriteMessage(tv.Value.ToString());// } } rb.Dispose(); //should be written before return buffer.Dispose(); //should be written before return } return(""); } }
addXData(ObjectId id, TypedValue[] tvs, string nameApp) { AddRegAppTableRecord(nameApp); try { using (Transaction tr = BaseObjs.startTransactionDb()) { try { ResultBuffer RB = new ResultBuffer(tvs); DBObject dbObj = tr.GetObject(id, OpenMode.ForWrite); dbObj.XData = RB; RB.Dispose(); tr.Commit(); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " xData.cs: line: 45"); } }//end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " xData.cs: line: 51"); } }
/// <summary> /// 调用AutoCad命令 /// </summary> /// <param name="endCommandByUser">命令结束方式</param> /// <param name="args">参数</param> public static void RunCommand(bool endCommandByUser, params object[] args) { ResultBuffer rb = new ResultBuffer(); ResultBuffer rbend = new ResultBuffer(); foreach (object val in args) { AddValueToResultBuffer(ref rb, val); } try { Document doc = cadApplication.DocumentManager.MdiActiveDocument; string currCmdName = doc.CommandInProgress; acedCmd(rb.UnmanagedObject); if (endCommandByUser) { rbend.Add(new TypedValue((int)LispDataType.Text, "\\")); } while (doc.CommandInProgress != currCmdName) { acedCmd(rbend.UnmanagedObject); } } catch { } finally { rb.Dispose(); rbend.Dispose(); } }
// Get the XData for a particular object // and return the "pipe radius" if it exists public static double PipeRadiusForObject(DBObject obj) { double res = 0.0; ResultBuffer rb = obj.XData; if (rb != null) { bool foundStart = false; foreach (TypedValue tv in rb) { if (tv.TypeCode == (int)DxfCode.ExtendedDataRegAppName && tv.Value.ToString() == regAppName) { foundStart = true; } else { if (foundStart == true) { if (tv.TypeCode == (int)DxfCode.ExtendedDataReal) { res = (double)tv.Value; break; } } } } rb.Dispose(); } return(res); }
private static void SetXDataAndMoveToLocation( Entity ent, ResultBuffer rbdata, Point3d pt ) { Database db = Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { ent = tr.GetObject(ent.ObjectId, OpenMode.ForWrite) as Entity; // Let's add our message information as XData, // for later editing RbEncoder.AddRegAppTableRecord(APPLICATION_PREFIX); ResultBuffer rb = rbdata; ent.XData = rb; rb.Dispose(); // Move to the correct location Matrix3d disp = Matrix3d.Displacement(pt.GetAsVector()); ent.TransformBy(disp); tr.Commit(); } }
static public ObjectIdCollection ReadXdata(Entity ent) { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; ResultBuffer rb = ent.GetXDataForApplication("ListBlock"); ObjectIdCollection listId = new ObjectIdCollection(); if (rb == null) { return(null); } else { foreach (TypedValue tv in rb) { if (tv.TypeCode == (int)DxfCode.SoftPointerId) { ObjectId id = (ObjectId)tv.Value; if (id.IsValid && id.IsErased == false) { listId.Add(id); } } } rb.Dispose(); } return(listId); }
/// <summary> /// Записываем в XData пару ключ-значение для позиции. Внимание! При повторной записи старое значение теряется! /// </summary> public void AttachPosition() { var pos = Input.Text("Введите наименование позиции"); if (Input.StatusBad) { return; } var sset = Input.Objects("Выберите объекты для добавления XData"); if (Input.StatusBad) { return; } var rb = new ResultBuffer(new TypedValue(1001, AppName), new TypedValue(1000, PosKey), new TypedValue(1000, pos), new TypedValue((int)DxfCode.ExtendedDataInteger32, HandleCounter++) ); using (var th = new TransactionHelper()) { var objects = th.EditObjects(sset); foreach (var o in objects) { o.XData = rb; } rb.Dispose(); } }
static public void Plan2HoePrResetCheck() { const int RTNORM = 5100; try { //if (!OpenHoePrPalette()) return; //var opts = Globs.TheHoePrOptions; Document doc = Application.DocumentManager.MdiActiveDocument; using (DocumentLock m_doclock = doc.LockDocument()) { using (var rb = new ResultBuffer(new TypedValue((int)LispDataType.Text, "c:Plan2HoePrReset"))) { int stat = 0; ResultBuffer res = CADDZone.AutoCAD.Samples.AcedInvokeSample.InvokeLisp(rb, ref stat); if (stat == RTNORM && res != null) { res.Dispose(); } } } } catch (System.Exception ex) { Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2HoePrResetCheck aufgetreten! {0}", ex.Message)); } }
private static void EditBallon(BallonViewModel ballonViewModel) { Document doc = AcAp.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Transaction trans = doc.TransactionManager.StartTransaction(); using (trans) { try { Group group = trans.GetObject(ballonViewModel.BallonObjectId, OpenMode.ForWrite) as Group; ObjectId[] objectIds = group.GetAllEntityIds(); Line line = null; Circle circle = null; DBText dBText = null; foreach (ObjectId item in objectIds) { DBObject ent = trans.GetObject(item, OpenMode.ForWrite); if (ent is Line) { line = ent as Line; } else if (ent is Circle) { circle = ent as Circle; } else if (ent is DBText) { dBText = ent as DBText; } } //edit graphical properties for ballon dBText.TextString = ballonViewModel.StringInput; double newLenth = ballonViewModel.Length; double newRadian = ballonViewModel.Angle * Math.PI / 180; line.EndPoint = new Point3d(line.StartPoint.X + newLenth * Math.Cos(newRadian), line.StartPoint.Y + newLenth * Math.Sin(newRadian), line.StartPoint.Z); line.Layer = ballonViewModel.LayerName; line.ColorIndex = ballonViewModel.ColorIndex; double newRadius = ballonViewModel.Radius; circle.Radius = newRadius; circle.Center = new Point3d(line.EndPoint.X + newRadius * Math.Cos(newRadian), line.EndPoint.Y + newRadius * Math.Sin(newRadian), line.EndPoint.Z); dBText.AlignmentPoint = circle.Center; //edit xdata ResultBuffer rb = CreateBalloonBuffer(ballonViewModel.MyBallon, BALLON_XDATA_NAME); group.XData = rb;// new ResultBuffer(new TypedValue(1001, BALLON_XDATA_NAME)); rb.Dispose(); trans.Commit(); } catch (Exception e) { trans.Abort(); throw e; } } }
public static void AddXData(this DBObject dbobject, Grevit.Types.Component comp, Transaction tr) { AddRegAppTableRecord("Grevit", tr); Entity ent = (Entity)tr.GetObject(dbobject.Id, OpenMode.ForWrite); ResultBuffer rbs = new ResultBuffer(new TypedValue(1001, "Grevit"), new TypedValue(1000, comp.GID)); ent.XData = rbs; rbs.Dispose(); ent.Dispose(); }
public static void InvokeCGeoin() { ResultBuffer args = new ResultBuffer(); int stat = 0; args.Add(new TypedValue(RTSTR, "c:geoin")); ResultBuffer res = InvokeLisp(args, ref stat); if (stat == RTNORM && res != null) { PrintResbuf(res); res.Dispose(); } }
// Token: 0x060000CA RID: 202 RVA: 0x0000A3A4 File Offset: 0x000085A4 internal void b(DBObject A_0, Transaction A_1) { ResultBuffer xdataForApplication = A_0.GetXDataForApplication(this.XDAppName); if (xdataForApplication != null) { if (!A_0.IsWriteEnabled && !A_0.ObjectId.IsNull) { A_1.GetObject(A_0.ObjectId, 1, false, true); } this.a(A_0.Database, A_1); A_0.XData = this.n(); xdataForApplication.Dispose(); } }
public static void InvokeCLisp(string funcNameWithoutC) { ResultBuffer args = new ResultBuffer(); int stat = 0; args.Add(new TypedValue(RTSTR, "c:" + funcNameWithoutC)); ResultBuffer res = InvokeLisp(args, ref stat); if (stat == RTNORM && res != null) { PrintResbuf(res); res.Dispose(); } }
private void CreateAndGroupBallon(Ballon ballon) { Document doc = AcAp.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Transaction trans = doc.TransactionManager.StartTransaction(); using (trans) { try { PromptPointResult pPtRes; PromptPointOptions pPtOpts = new PromptPointOptions("Enter Base point[X,Y]: "); pPtRes = doc.Editor.GetPoint(pPtOpts); if (pPtRes.Status == PromptStatus.Cancel) { return; } Point3d startPoint = pPtRes.Value; //Line line = new Line(startPoint, endPoint); Line line = CreateLine(startPoint, ballon.Angle, ballon.Length, ballon.LayerName, ballon.ColorIndex); Circle cir = CreateCirle(line.EndPoint, ballon.Angle, ballon.Radius); DBText text = CreateText(cir.Center, ballon.StringInput); //Open the Layer table for read ObjectId oLineId = DatabaseHelper.AppendEntityToDatabase(line); ObjectId oCircleId = DatabaseHelper.AppendEntityToDatabase(cir); ObjectId oTextId = DatabaseHelper.AppendEntityToDatabase(text); Group grp = new Group("Test group description", true); // Add the new group to the dictionary DBDictionary gd = trans.GetObject(db.GroupDictionaryId, OpenMode.ForRead) as DBDictionary; gd.UpgradeOpen(); ObjectId grpId = gd.SetAt("GroupCaseStudy1", grp); trans.AddNewlyCreatedDBObject(grp, true); ObjectIdCollection ids = new ObjectIdCollection(); ids.Add(oLineId); ids.Add(oCircleId); ids.Add(oTextId); grp.InsertAt(0, ids); ResultBuffer rb = CreateBalloonBuffer(ballon, BALLON_XDATA_NAME); grp.XData = rb; rb.Dispose(); trans.Commit(); } catch (System.Exception e) { trans.Abort(); } } }
protected void SetXDataForForcesAndMoment(ObjectId idExternalForces, string intensity, ObjectId objectId) { Document doc = AcAp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { Common.AddRegAppTableRecord("Data_MechanicalCalculation"); TypedValue typedValue = new TypedValue(1000, intensity + "," + objectId.ToString()); ResultBuffer rb = new ResultBuffer(new TypedValue(1001, "Data_MechanicalCalculation"), typedValue); tr.GetObject(idExternalForces, OpenMode.ForWrite).XData = rb; rb.Dispose(); tr.Commit(); } }
/// <summary> /// 调用AutoCad命令 /// </summary> /// <param name="prompt">命令行提示</param> /// <param name="arg">参数</param> public static void RunCommand(string prompt, object arg) { //EdUtility.WriteMessage(prompt); ResultBuffer rb = new ResultBuffer(); AddValueToResultBuffer(ref rb, arg); try { acedCmd(rb.UnmanagedObject); } catch { } finally { rb.Dispose(); } }
//function to add xdata to selected object public static void addXData(ObjectId objectid, string appName, string value) { Document doc = Application.DocumentManager.MdiActiveDocument; Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { doc.LockDocument(); DBObject obj = tr.GetObject(objectid, OpenMode.ForWrite); AddRegAppTableRecord(appName.ToString()); ResultBuffer rb = new ResultBuffer(new TypedValue(1001, appName.ToString()), new TypedValue(1000, value.ToString())); obj.XData = rb; rb.Dispose(); tr.Commit(); } }
public static void TestInvokeLisp() { ResultBuffer args = new ResultBuffer(); int stat = 0; args.Add(new TypedValue(RTSTR, "testfunc")); args.Add(new TypedValue(RTLONG, 100)); args.Add(new TypedValue(RTLONG, 200)); ResultBuffer res = InvokeLisp(args, ref stat); if (stat == RTNORM && res != null) { PrintResbuf(res); res.Dispose(); } }
private static void GetConfiguration() { _CurrentConfig = string.Empty; using (var rb = new ResultBuffer(new TypedValue((int)LispDataType.Text, "c:Plan2CurrentConfig"))) { int stat = 0; ResultBuffer res = CADDZone.AutoCAD.Samples.AcedInvokeSample.InvokeLisp(rb, ref stat); if (stat == RTNORM && res != null) { _CurrentConfig = res.AsArray()[0].Value.ToString(); res.Dispose(); } else { throw new InvalidOperationException("Konnte Konfigurationsdateiname nicht ermitteln!"); } } }
// Thêm XData private void SetXData(ObjectId IdEntity, ObjectId obj1, ObjectId obj2) { Document doc = AcAp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { Entity objects = new Entity(); Common.AddRegAppTableRecord("Data_MechanicalCalculation"); DBObject obj = tr.GetObject(IdEntity, OpenMode.ForWrite); TypedValue typedValue = new TypedValue(1000, Common.ObjectIdToString(obj1) + "," + Common.ObjectIdToString(obj2)); ResultBuffer rb = new ResultBuffer(new TypedValue(1001, "Data_MechanicalCalculation"), typedValue); obj.XData = rb; rb.Dispose(); tr.Commit(); } }
private void button1_Click(object sender, EventArgs e) { try { Test(); return; #if ARX_APP ResultBuffer rbInvoke = new ResultBuffer(); rbInvoke.Add(new TypedValue((int)(_AcBrx.LispDataType.Text), "alx_F:ino_plan2_GetConfiguration")); ResultBuffer resInvoke = _AcAp.Application.Invoke(rbInvoke); rbInvoke.Dispose(); object o1 = Globs.GetLispVariable("alx_V:ino_flattrib"); object o2 = Globs.GetLispVariable("alx_V:ino_flattribdfa"); object o3 = Globs.LispFindFile("plan2.cfg"); if (o3 != null) { object o4 = Globs.LispTryLoadGlobs(o3.ToString()); } #endif //rbInvoke = new ResultBuffer(); //rbInvoke.Add(new TypedValue((int)(Autodesk.AutoCAD.Runtime.LispDataType.Text), "alx_F:ino_EvalLispVariable")); //rbInvoke.Add(new TypedValue((int)(Autodesk.AutoCAD.Runtime.LispDataType.Text), "alx_V:ino_flattrib")); //resInvoke = _AcAp.Application.Invoke(rbInvoke); //rbInvoke.Dispose(); //rbInvoke = new ResultBuffer(); //rbInvoke.Add(new TypedValue((int)(Autodesk.AutoCAD.Runtime.LispDataType.Text), "alx_F:ino_EvalLispVariable")); //rbInvoke.Add(new TypedValue((int)(Autodesk.AutoCAD.Runtime.LispDataType.Text), "alx_V:ino_flattribxdf")); //resInvoke = _AcAp.Application.Invoke(rbInvoke); //rbInvoke.Dispose(); } catch (Exception ex) { string x = ex.Message; ; } }
// Set the "pipe radius" in the XData of a particular object public static void SetPipeRadiusOnObject( Transaction tr, DBObject obj, double radius ) { Database db = obj.Database; // Make sure the application is registered // (we could separate this out to be called // only once for a set of operations) RegAppTable rat = (RegAppTable)tr.GetObject( db.RegAppTableId, OpenMode.ForRead ); if (!rat.Has(regAppName)) { rat.UpgradeOpen(); RegAppTableRecord ratr = new RegAppTableRecord(); ratr.Name = regAppName; rat.Add(ratr); tr.AddNewlyCreatedDBObject(ratr, true); } // Create the XData and set it on the object ResultBuffer rb = new ResultBuffer( new TypedValue( (int)DxfCode.ExtendedDataRegAppName, regAppName ), new TypedValue( (int)DxfCode.ExtendedDataReal, radius ) ); obj.XData = rb; rb.Dispose(); }
public void UpdateXData()//更新扩展数据 { if (isChanged) { //下面2行代码锁住文档 DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application. DocumentManager.MdiActiveDocument.LockDocument(); Document doc = Application.DocumentManager.MdiActiveDocument; Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { DBObject obj = tr.GetObject(this.id, OpenMode.ForWrite); ResultBuffer rb = new ResultBuffer(); foreach (KeyValuePair <string, Dictionary <string, string> > kp in this.appName2values) { rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, kp.Key)); foreach (KeyValuePair <string, string> pair in kp.Value) { rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, pair.Key)); rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, pair.Value)); } obj.XData = rb;//替换对应appname的扩展数据 rb = new ResultBuffer(); } rb.Dispose(); tr.Commit(); } isChanged = false; //PurgeDatabase(doc.Database);//作为实验,看是否能够清除多余的appname,(暂时不考虑,如果出现问题在考虑这个问题) docLock.Dispose(); } }
public void SetXData(Handle handle, XDataCollection extendedData) { Transaction trans = doc.TransactionManager.StartTransaction(); using (trans) { ObjectId objId; if (db.TryGetObjectId(handle, out objId)) { DBObject dbObj = trans.GetObject(objId, OpenMode.ForWrite); ResultBuffer rb = new ResultBuffer(); foreach (XData xData in extendedData) { AddRegAppTableRecord(xData.AppName); rb.Add(new TypedValue(1001, xData.AppName)); rb.Add(new TypedValue(xData.Code, xData.Data.ToString())); } dbObj.XData = rb; rb.Dispose(); trans.Commit(); } } }
/// <summary> /// 写扩展词典 /// </summary public static void AddExtDict(DBObject obj) { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; /* PromptEntityOptions peo = new PromptEntityOptions("请选择实体:"); * PromptEntityResult per = ed.GetEntity(peo); * if (per.Status == PromptStatus.OK) * {*/ Transaction trans = doc.TransactionManager.StartTransaction(); // DBObject obj = trans.GetObject(per.ObjectId, OpenMode.ForWrite); AddRegAppTableRecord("扩展数据测试"); ResultBuffer rb = new ResultBuffer(); rb.Add(new TypedValue(1001, "扩展数据测试")); rb.Add(new TypedValue(1000, "我是扩展数据,大家好!")); rb.Add(new TypedValue(1000, "看到我你就测试成功了!")); obj.XData = rb; rb.Dispose(); trans.Commit(); trans.Dispose(); // } }
public static void AddXData(this DBObject dbobject, Grevit.Types.Component comp, Transaction tr) { AddRegAppTableRecord("Grevit",tr); Entity ent = (Entity)tr.GetObject(dbobject.Id, OpenMode.ForWrite); ResultBuffer rbs = new ResultBuffer(new TypedValue(1001, "Grevit"), new TypedValue(1000, comp.GID)); ent.XData = rbs; rbs.Dispose(); ent.Dispose(); }
public void UpdateXData()//更新扩展数据 { if (isChanged) { //下面2行代码锁住文档 DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application. DocumentManager.MdiActiveDocument.LockDocument(); Document doc = Application.DocumentManager.MdiActiveDocument; Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { DBObject obj = tr.GetObject(this.id, OpenMode.ForWrite); ResultBuffer rb = new ResultBuffer(); foreach (KeyValuePair<string, Dictionary<string, string>> kp in this.appName2values) { rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, kp.Key)); foreach (KeyValuePair<string, string> pair in kp.Value) { rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, pair.Key)); rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, pair.Value)); } obj.XData = rb;//替换对应appname的扩展数据 rb = new ResultBuffer(); } rb.Dispose(); tr.Commit(); } isChanged = false; //PurgeDatabase(doc.Database);//作为实验,看是否能够清除多余的appname,(暂时不考虑,如果出现问题在考虑这个问题) docLock.Dispose(); } }
public void Draw(string block, string Basislayer) { Database db = HostApplicationServices.WorkingDatabase; _AcDb.TransactionManager myTm = db.TransactionManager; Transaction myT = db.TransactionManager.StartTransaction(); Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ObjectContextManager conTextManager = db.ObjectContextManager; Dictionary <string, Point3d> _attPos = new Dictionary <string, Point3d>(); List <AttributeDefinition> _attDef = new List <AttributeDefinition>(); MyLayer objLayer = MyLayer.Instance; //objLayer.CheckLayer(Basislayer, true); try { using (DocumentLock dl = Application.DocumentManager.MdiActiveDocument.LockDocument()) { //Block in Zeichnung einfügen BlockTable bt = (BlockTable)myT.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)myT.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); BlockTableRecord btrDef = (BlockTableRecord)myT.GetObject(bt[block], OpenMode.ForRead); //Attribute aus Blockdefinition übernehmen if (btrDef.HasAttributeDefinitions) { foreach (ObjectId id in btrDef) { DBObject obj = myT.GetObject(id, OpenMode.ForRead); try { AttributeDefinition ad = (AttributeDefinition)obj; if (ad != null) { _attPos.Add(ad.Tag, ad.Position); _attDef.Add(ad); } } catch { try { Entity ent = (Entity)obj; //Layer = ent.Layer; } catch { } } } } BlockReference blkRef = new BlockReference(_Pos3d, bt[block]) { ScaleFactors = new Scale3d(db.Cannoscale.Scale), Layer = Basislayer }; btr.AppendEntity(blkRef); //XData schreiben RegAppTable acRegAppTbl; acRegAppTbl = (RegAppTable)myT.GetObject(db.RegAppTableId, OpenMode.ForRead); if (!acRegAppTbl.Has(Global.Instance.AppName)) { using (RegAppTableRecord acRegAppTblRec = new RegAppTableRecord()) { acRegAppTblRec.Name = Global.Instance.AppName; acRegAppTbl.UpgradeOpen(); acRegAppTbl.Add(acRegAppTblRec); myT.AddNewlyCreatedDBObject(acRegAppTblRec, true); } } using (ResultBuffer rb = new ResultBuffer()) { rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, Global.Instance.AppName)); rb.Add(new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, _Pos3d)); if (_HöheOrg != null) { rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, _HöheOrg)); } blkRef.XData = rb; rb.Dispose(); } myT.AddNewlyCreatedDBObject(blkRef, true); //Attribute befüllen if (_attPos != null) { string[] lsBasislayer = Basislayer.Split('-'); string Stammlayer = lsBasislayer[lsBasislayer.Length - 2]; for (int i = 0; i < _attPos.Count; i++) { AttributeReference _attRef = new AttributeReference(); _attRef.SetDatabaseDefaults(); _attRef.SetAttributeFromBlock(_attDef[i], Matrix3d.Identity); _attRef.SetPropertiesFrom(_attDef[i]); Point3d ptBase = new Point3d(blkRef.Position.X + _attRef.Position.X, blkRef.Position.Y + _attRef.Position.Y, blkRef.Position.Z + _attRef.Position.Z); _attRef.Position = ptBase; string attLayer = String.Empty; KeyValuePair <string, Point3d> keyValuePair = _attPos.ElementAt(i); switch (keyValuePair.Key) { case "number": _attRef.TextString = _PNum; _attRef.Layer = Stammlayer + Global.Instance.LayNummer; break; case "height": if (_HöheOrg != null) { _attRef.TextString = _HöheOrg; _attRef.Layer = Stammlayer + Global.Instance.LayHöhe; } break; case "date": _attRef.Layer = Stammlayer + "-Datum"; _attRef.Layer = Stammlayer + Global.Instance.LayDatum; break; case "code": _attRef.Layer = Stammlayer + "-Code"; _attRef.Layer = Stammlayer + Global.Instance.LayCode; break; case "owner": _attRef.Layer = Stammlayer + "-Hersteller"; break; default: break; } blkRef.AttributeCollection.AppendAttribute(_attRef); myT.AddNewlyCreatedDBObject(_attRef, true); } blkRef.Dispose(); } } } //Block aus Prototypzeichnung holen catch { } finally { myT.Commit(); myT.Dispose(); } }
public static void EditQR() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; // Ask user to select an QR code, hatch or raster image PromptEntityOptions peo = new PromptEntityOptions("Select a QR code: "); peo.SetRejectMessage( "\nMust be a hatch or a raster image" ); peo.AddAllowedClass(typeof(Hatch), true); // AutoCAD crash if we try AddAllowedClass for RasterImage // when no raster image is defined or just hatch QRs were // defined, probably because in C++ we need to call // acedArxLoad("acismui.arx"), which is not exposed in .NET, // so let's check before if the drawing contains any // RasterImages, if not we don't need this filter. if (!RasterImageDef.GetImageDictionary(db).IsNull) { peo.AddAllowedClass(typeof(RasterImage), true); } PromptEntityResult entityResult = ed.GetEntity(peo); if (entityResult.Status != PromptStatus.OK) { return; } Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { Entity ent = tr.GetObject(entityResult.ObjectId, OpenMode.ForRead) as Entity; ResultBuffer rb = ent.GetXDataForApplication(APPLICATION_PREFIX); if (rb != null && rb.AsArray().Length == 0) { ed.WriteMessage("\nThis is not a valid QR code"); tr.Commit(); //faster return; } // Show the form with current information QRCodeForm form = new QRCodeForm(); form.IsEditing = true; form.QREncodeDataAsResultBuffer = rb; rb.Dispose(); System.Windows.Forms.DialogResult res = Application.ShowModalDialog(form); if (res != System.Windows.Forms.DialogResult.OK) { return; } //Get insert point and size double size = ent.GeometricExtents.MaxPoint.X - ent.GeometricExtents.MinPoint.X; Point3d inspt = ent.GeometricExtents.MinPoint; if (ent is RasterImage) { // Just update the raster image definition RasterImage image = ent as RasterImage; RasterImageDef imageDef = tr.GetObject(image.ImageDefId, OpenMode.ForWrite) as RasterImageDef; imageDef.SourceFileName = FormatDataHelper.EncodeQrCodeUrl(form.QREncodeData); imageDef.Load(); } else { // Erase current entity ent.UpgradeOpen(); ent.Erase(); // Create a new one Entity newEnt = GenerateQRHatch( form.QREncodeData, form.QREncode, form.QRVersion, form.QRErrorCorrect, (int)size ); if (newEnt == null) { return; } ResultBuffer newRb = form.QREncodeDataAsResultBuffer; newEnt.XData = newRb; newRb.Dispose(); newEnt.TransformBy( Matrix3d.Displacement(inspt.GetAsVector()) ); AppendEntityToCurrentSpace(newEnt); } tr.Commit(); } }
static public void Test() { var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; PromptResult pr = ed.GetString("Specify output filename:"); if (pr.Status == Autodesk.AutoCAD.EditorInput.PromptStatus.Cancel) { ed.WriteMessage("Command cancelled"); return; } string outputFile = pr.StringResult; if (string.IsNullOrEmpty(outputFile)) { ed.WriteMessage("Error: Invalid output file"); return; } try { Collection <DBObjectInfo> xdata = new Collection <DBObjectInfo>(); Database db = doc.Database; ObjectId modId = SymbolUtilityServices.GetBlockModelSpaceId(db); using (Transaction trans = doc.TransactionManager.StartTransaction()) { BlockTableRecord btr = trans.GetObject(modId, OpenMode.ForRead) as BlockTableRecord; foreach (ObjectId entId in btr) { DBObject obj = trans.GetObject(entId, OpenMode.ForRead); ResultBuffer rb = obj.XData; if (rb == null) { continue; } DBObjectInfo objInfo = new DBObjectInfo(); objInfo.Id = obj.Handle.ToString(); string strValue; foreach (TypedValue tvalue in rb) { strValue = ""; if (tvalue.TypeCode == 1004) { string hexvalue = BitConverter.ToString(tvalue.Value as byte[]); hexvalue = hexvalue.Replace("-", ""); strValue = hexvalue; } else { strValue = string.Format("{0}", tvalue.Value); } DataValue dataVal = new DataValue(); dataVal.Type = tvalue.TypeCode; dataVal.Value = strValue; objInfo.XData.Add(dataVal); } rb.Dispose(); xdata.Add(objInfo); } } if (xdata.Count <= 0) { ed.WriteMessage("There are no XData associated with entities in this drawing."); return; } Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); using (var stream = File.Create(outputFile)) { DataContractJsonSerializer ser = new DataContractJsonSerializer(xdata.GetType()); ser.WriteObject(stream, xdata); } } catch (System.Exception e) { ed.WriteMessage("Error: {0}", e); } }
private bool EditOrCreateTable(JsonData data, Point3d point) { //TotalFacilitiesRequired total = data.minimumfixture; ac.Document doc = ac.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Table tb = new Table(); tb.TableStyle = db.Tablestyle; tb.Layer = "TABLE"; //Set Size First... tb.SetSize(data.minimumfixture.fixtureUnitArray.Count + 4, 9); tb.Cells.ContentColor = Color.FromColorIndex(ColorMethod.ByAci, 2); tb.Cells.TextHeight = 0.09375; tb.Columns[0].Width = 1.06; tb.Columns[1].Width = 1.34 / 2; tb.Columns[2].Width = 1.34 / 2; tb.Columns[3].Width = 0.85; tb.Columns[4].Width = 1.3 / 2; tb.Columns[5].Width = 1.3 / 2; tb.Columns[6].Width = 1.27; tb.Columns[7].Width = 1.53; tb.Columns[8].Width = 2.15; //Table Title CellRange titleRange = CellRange.Create(tb, 0, 0, 0, 8); tb.MergeCells(titleRange); tb.Cells[0, 0].Value = "Minimum Number of Required Fixtures"; tb.Cells[0, 0].TextHeight = 3.0 / 16; //Table Items tb.Cells[1, 0].Value = "TYPE OF OCCUPANCY"; CellRange wcTitleRange = CellRange.Create(tb, 1, 1, 1, 2); tb.MergeCells(wcTitleRange); tb.Cells[1, 1].Value = "WATER CLOSETS"; tb.Cells[1, 3].Value = "URINALS"; CellRange lavatoriesTitle = CellRange.Create(tb, 1, 4, 1, 5); tb.MergeCells(lavatoriesTitle); tb.Cells[1, 4].Value = "LAVATORIES"; tb.Cells[1, 6].Value = "BATHTUBS OR SHOWERS"; tb.Cells[1, 7].Value = "DRINKINGFOUNTAINS/FACILITIES"; tb.Cells[1, 8].Value = "OTHER"; //Table Bottom: if (!data.minimumfixture.totalRequiredFixture.ContainsKey(Table422_1Categories.urinals) && data.minimumfixture.sliderValue > 0) { data.minimumfixture.totalRequiredFixture.Add(Table422_1Categories.urinals, 0); } string bottomValue = ""; if (data.minimumfixture.totalFixtureBasedOnGender.ContainsKey(data.minimumfixture.totalFemaleCloset) && data.minimumfixture.femaleWaterClosetAddIn > 0) { if (data.minimumfixture.femaleWaterClosetAddIn > 0) { bottomValue += string.Format("Female Water Closet: {0} + {1} (note 3)\n", data.minimumfixture.totalFixtureBasedOnGender[data.minimumfixture.totalFemaleCloset], data.minimumfixture.femaleWaterClosetAddIn); } else { bottomValue += string.Format("Female Water Closet: {0}\n", data.minimumfixture.totalFixtureBasedOnGender[data.minimumfixture.totalFemaleCloset]); } } if (data.minimumfixture.totalFixtureBasedOnGender.ContainsKey(data.minimumfixture.totalMaleCloset) && data.minimumfixture.totalRequiredFixture.ContainsKey(Table422_1Categories.urinals) ) { if (data.minimumfixture.sliderValue > 0) { bottomValue += string.Format("Male Water Closet: {0} - {1} (note 4)\n", data.minimumfixture.totalFixtureBasedOnGender[data.minimumfixture.totalMaleCloset], data.minimumfixture.sliderValue); } else { bottomValue += string.Format("Male Water Closet: {0}\n", data.minimumfixture.totalFixtureBasedOnGender[data.minimumfixture.totalMaleCloset]); } } if (data.minimumfixture.totalFixtureBasedOnGender.ContainsKey(data.minimumfixture.totalMaleUrinals) && data.minimumfixture.totalRequiredFixture.ContainsKey(Table422_1Categories.urinals) ) { if (data.minimumfixture.sliderValue > 0) { bottomValue += string.Format("** Male Urinal(s): {0} + {1} (note 4)\n", data.minimumfixture.totalFixtureBasedOnGender[data.minimumfixture.totalMaleUrinals], data.minimumfixture.sliderValue); } } if (data.minimumfixture.femaleWaterClosetAddIn > 0) { bottomValue += string.Format("* added {0} female lavatories -- satisfies note 3 requirement.\n", data.minimumfixture.femaleWaterClosetAddIn); } if (data.minimumfixture.sliderValue > 0) { bottomValue += string.Format("** based on Note 4, it's okay to added {0} male urinals and remove {0} male water closet\n", data.minimumfixture.sliderValue); } bottomValue += "\nCalifornia Plumbing Code 2019 - Table 422.1 - Note:\n"; bottomValue += "(3) The total number of required water closets for females shall be not less than the total number of required water closets and urinals for males.\n"; bottomValue += "(4) For each urinal added in excess of the minimum required, one water closet shall be permitted to be deducted. The number of water closets shall not be reduced to less than two-thirds of the minimum requirement.\n"; bottomValue += "\n Created based on Table 422.1 California Plumbing Code 2019"; int bottomRowIndex = data.minimumfixture.fixtureUnitArray.Count + 4 - 1; CellRange bottomRange = CellRange.Create(tb, bottomRowIndex, 0, bottomRowIndex, 8); tb.Cells[bottomRowIndex, 0].Value = bottomValue; tb.Cells[bottomRowIndex, 0].Alignment = CellAlignment.BottomLeft; tb.MergeCells(bottomRange); tb.Cells[0, 0].TextHeight = 3.0 / 16; //Fill Data... int rIndex = 2; foreach (FixtureUnit unit in data.minimumfixture.fixtureUnitArray) { createRow(unit.outputUnits, tb, ref rIndex, data, unit.occupancy.type, false); } createRow(data.minimumfixture.totalRequiredFixture, tb, ref rIndex, data, "TOTAL", true); tb.Cells.DataFormat = "%lu2%pr0%"; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); TableJig tJig = new TableJig(tb); Editor ed = ac.Application.DocumentManager.MdiActiveDocument.Editor; PromptResult result; bool cont = false; if (point == new Point3d(-1000, -1000, -1000)) { result = ed.Drag(tJig); if (result.Status == PromptStatus.OK) { point = tJig.insertionPoint; cont = true; } else { return(false); } } else { cont = true; } if (cont) { tb.Position = point; btr.AppendEntity(tb); tr.AddNewlyCreatedDBObject(tb, true); AddTableRecord(data.id.ToString(), db, tr, tb); ResultBuffer rb = new ResultBuffer( new TypedValue(1001, uriInit), new TypedValue(1000, data.id.ToString()) ); tb.XData = rb; rb.Dispose(); tr.Commit(); return(true); } else { return(false); } } }
public void SetXData() { PromptEntityOptions opt = new PromptEntityOptions("\nSelect entity: "); PromptEntityResult res = editor.GetEntity(opt); if (res.Status == PromptStatus.OK) { Transaction trans = doc.TransactionManager.StartTransaction(); using (trans) { DBObject obj = trans.GetObject( res.ObjectId, OpenMode.ForWrite ); AddRegAppTableRecord("skd"); AddRegAppTableRecord("l2p"); AddRegAppTableRecord("l1p"); AddRegAppTableRecord("g_d"); AddRegAppTableRecord("kom"); AddRegAppTableRecord("dds"); AddRegAppTableRecord("typ"); AddRegAppTableRecord("ilp"); AddRegAppTableRecord("ilw"); AddRegAppTableRecord("sko"); AddRegAppTableRecord("sre"); AddRegAppTableRecord("np-69"); AddRegAppTableRecord("el-100"); AddRegAppTableRecord("pro"); AddRegAppTableRecord("nop"); AddRegAppTableRecord("npo"); AddRegAppTableRecord("zn1"); AddRegAppTableRecord("zna"); ResultBuffer rb = new ResultBuffer( new TypedValue(1001, "skd"), new TypedValue(1040, 0), new TypedValue(1001, "l2p"), new TypedValue(1040, 9), new TypedValue(1001, "l1p"), new TypedValue(1040, 9), new TypedValue(1001, "g_d"), new TypedValue(1000, "glo"), new TypedValue(1001, "kom"), new TypedValue(1000, "\u0020"), new TypedValue(1001, "dds"), new TypedValue(1040, 0.4), new TypedValue(1001, "typ"), new TypedValue(1070, 1), new TypedValue(1001, "ilp"), new TypedValue(1070, 7), new TypedValue(1001, "ilw"), new TypedValue(1070, 8), new TypedValue(1001, "sko"), new TypedValue(1040, 0.21), new TypedValue(1001, "sre"), new TypedValue(1040, 0.016), new TypedValue(1001, "np-69"), new TypedValue(1000, "bw"), new TypedValue(1001, "el-100"), new TypedValue(1000, "bw"), new TypedValue(1001, "pro"), new TypedValue(1000, "sys01-v4"), new TypedValue(1001, "nop"), new TypedValue(1070, 9999), new TypedValue(1001, "npo"), new TypedValue(1070, 30), new TypedValue(1001, "zn1"), new TypedValue(1000, "bw"), new TypedValue(1001, "zna"), new TypedValue(1000, "zn1") ); obj.XData = rb; rb.Dispose(); trans.Commit(); } } }