public override bool WorldDraw(Drawable drawable, WorldDraw wd) { if (drawable is Entity ent) { var id = GrasshopperData.GetGrasshopperData(ent); if (!id.IsNull) { var database = id.Database; var docExt = GhBcConnection.GrasshopperDataExtension.GrasshopperDataManager(database); var ghDrawable = docExt?.Drawable(id); if (ghDrawable == null) { return(base.WorldDraw(drawable, wd)); } bool needToDraw = false; using (var transaction = database.TransactionManager.StartTransaction()) { var ghData = transaction.GetObject(id, OpenMode.ForRead) as GrasshopperData; needToDraw = ghData.IsVisible; transaction.Commit(); } if (needToDraw) { using (var trSt = new TraitsState(wd.SubEntityTraits)) { wd.Geometry.Draw(ghDrawable); } wd.SubEntityTraits.Transparency = new Transparency((byte)GhDataSettings.HostTransparency); } } } return(base.WorldDraw(drawable, wd)); }
private void OnObjectModified(object sender, _OdDb.ObjectEventArgs e) { var objId = e.DBObject.ObjectId; if (objId.ObjectClass.IsDerivedFrom(_OdRx.RXObject.GetClass(typeof(GrasshopperData)))) { _toUpdate.Add(objId); } else if (e.DBObject is _OdDb.Entity ent) { var id = GrasshopperData.GetGrasshopperData(ent); if (!id.IsNull) { _toUpdate.Add(id); } } else if (e.DBObject is _OdDb.BlockTableRecord btr) { foreach (_OdDb.ObjectId refId in btr.GetBlockReferenceIds(true, false)) { using (var blockRef = refId.GetObject(_OdDb.OpenMode.ForRead) as _OdDb.Entity) { var id = GrasshopperData.GetGrasshopperData(blockRef); if (!id.IsNull) { _toUpdate.Add(id); } } } } }
private void OnObjectErased(object sender, _OdDb.ObjectErasedEventArgs e) { var obj = e.DBObject; var ghId = _OdDb.ObjectId.Null; if (obj is GrasshopperData) { ghId = obj.ObjectId; } else if (obj is _OdDb.Entity ent) { ghId = GrasshopperData.GetGrasshopperData(ent); } if (!ghId.IsNull) { if (obj.IsErased) { _grasshopperData.Remove(obj.ObjectId); } else { _toUpdate.Add(obj.ObjectId); } } }
public GhDataManager(_BcAp.Document doc) { Document = doc; DefinitionManager = new GhDefinitionManager(); DefinitionManager.Reloaded += (s, def) => { using (var transaction = Document.Database.TransactionManager.StartTransaction()) { foreach (var it in _grasshopperData) { var ghDataId = it.Key; var ghData = transaction.GetObject(ghDataId, _OdDb.OpenMode.ForRead) as GrasshopperData; if (ghData == null) { continue; } _toUpdate.Add(ghDataId); } } }; var database = doc.Database; using (var transaction = database.TransactionManager.StartTransaction()) { var blockTable = transaction.GetObject(database.BlockTableId, _OdDb.OpenMode.ForRead) as _OdDb.BlockTable; var searchPath = new string[] { DwgPath }; foreach (var blockId in blockTable) { var block = transaction.GetObject(blockId, _OdDb.OpenMode.ForRead) as _OdDb.BlockTableRecord; foreach (var id in block) { var entity = transaction.GetObject(id, _OdDb.OpenMode.ForRead) as _OdDb.Entity; var ghDataId = GrasshopperData.GetGrasshopperData(entity); if (ghDataId.IsNull) { continue; } var ghData = transaction.GetObject(ghDataId, _OdDb.OpenMode.ForRead) as GrasshopperData; DefinitionManager.Load(ghData.Definition, searchPath); _toUpdate.Add(ghDataId); } } transaction.Commit(); } EnableReactors(); }
public static void BakeGhData() { var editor = Application.DocumentManager.MdiActiveDocument.Editor; var selection = editor.GetSelection(); if (selection.Status != PromptStatus.OK) { return; } var database = editor.Document.Database; var ghDataToBake = new List <ObjectId>(); using (var transaction = database.TransactionManager.StartTransaction()) { for (int i = 0; i < selection.Value.Count; ++i) { var entity = transaction.GetObject(selection.Value[i].ObjectId, OpenMode.ForRead) as Entity; var id = GrasshopperData.GetGrasshopperData(entity); if (!id.IsNull) { ghDataToBake.Add(id); } } transaction.Commit(); } if (ghDataToBake.Count == 0) { return; } var bakeProperties = new UI.BakeDialog(); if (bakeProperties.ShowDialog() != _WF.DialogResult.OK) { return; } var docExt = GhBcConnection.GrasshopperDataExtension.GrasshopperDataManager(Application.DocumentManager.MdiActiveDocument, true); docExt?.Bake(ghDataToBake, bakeProperties); }