public void TestTrans() { try { //System.Windows.Forms.MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "_test = {0}", _test)); //_test = 0; _AcDb.Database db = _AcAp.Application.DocumentManager.MdiActiveDocument.Database; _AcDb.TransactionManager dbTrans = db.TransactionManager; using (_AcDb.Transaction trans = dbTrans.StartTransaction()) { // create a line _AcDb.Line ln = new _AcDb.Line(new _AcGe.Point3d(0.0, 0.0, 0.0), new _AcGe.Point3d(1.0, 1.0, 0.0)); _AcDb.BlockTable bt = dbTrans.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead, false) as _AcDb.BlockTable; if (bt == null) { return; } //ObjectId id = bt[BlockTableRecord.ModelSpace]; _AcDb.BlockTableRecord btr = dbTrans.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForWrite, false) as _AcDb.BlockTableRecord; if (btr == null) { return; } //Add it to the model space block table record. btr.AppendEntity(ln); //Make sure that the transaction knows about this new object. tm.AddNewlyCreatedDBObject(line, True) dbTrans.AddNewlyCreatedDBObject(ln, true); //'Add some hyperlinks. Dim hyper As New HyperLink() hyper.Name = "www.autodesk.com" line.Hyperlinks.Add(hyper) _AcDb.HyperLink hyper = new _AcDb.HyperLink(); hyper.Name = "www.facebook.com"; ln.Hyperlinks.Add(hyper); if (ln.Hyperlinks.Contains(hyper)) { hyper.Name = "www.gotdotnet.com"; } ln.Hyperlinks.Add(hyper); foreach (var hl in ln.Hyperlinks) { System.Diagnostics.Debug.WriteLine(hl.ToString()); } trans.Commit(); } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
public static bool Plan2AddHyperLink(_AcDb.ResultBuffer rb) { var doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = _AcAp.Application.DocumentManager.MdiActiveDocument.Database; _AcDb.TransactionManager dbTrans = db.TransactionManager; _AcEd.Editor ed = doc.Editor; try { _AcDb.ObjectId oid; string description, name, sublocation; if (rb == null) { ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)"); return(false); } var typedValues = rb.AsArray(); if (typedValues == null || typedValues.Length != 4) { ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)"); return(false); } if (typedValues[0].TypeCode != (short)_AcBrx.LispDataType.ObjectId) { ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)"); return(false); } oid = (_AcDb.ObjectId)typedValues[0].Value; if (typedValues[1].TypeCode != (short)_AcBrx.LispDataType.Text) { ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)"); return(false); } description = typedValues[1].Value.ToString(); if (typedValues[2].TypeCode != (short)_AcBrx.LispDataType.Text) { ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)"); return(false); } name = typedValues[2].Value.ToString(); if (typedValues[3].TypeCode != (short)_AcBrx.LispDataType.Text) { ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)"); return(false); } sublocation = typedValues[3].Value.ToString(); using (_AcDb.Transaction trans = dbTrans.StartTransaction()) { _AcDb.Entity ent = trans.GetObject((_AcDb.ObjectId)typedValues[0].Value, _AcDb.OpenMode.ForWrite) as _AcDb.Entity; if (ent != null) { _AcDb.HyperLink hyperLink = new _AcDb.HyperLink(); hyperLink.Description = description; hyperLink.Name = name; hyperLink.SubLocation = sublocation; ent.Hyperlinks.Add(hyperLink); } trans.Commit(); } return(true); } catch (Exception ex) { ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)"); } return(false); }