Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void Bake(List <_OdDb.ObjectId> ghDataIds, UI.BakeDialog bakeProperties)
        {
            DisableReactors();
            var saveDoc = GhDrawingContext.LinkedDocument;

            GhDrawingContext.LinkedDocument = Document;
            using (var transaction = Document.Database.TransactionManager.StartTransaction())
            {
                using (var form = new UI.ModalForm())
                {
                    foreach (var ghDataId in ghDataIds)
                    {
                        var ghData = transaction.GetObject(ghDataId, _OdDb.OpenMode.ForRead) as GrasshopperData;
                        if (ghData == null)
                        {
                            continue;
                        }

                        var definition = DefinitionManager.Definition(ghData.Definition);
                        if (definition == null)
                        {
                            continue;
                        }

                        foreach (var obj in definition.Objects.OfType <Components.BakeComponent>())
                        {
                            if (!obj.Locked)
                            {
                                Components.BakeComponent.Expire(obj, bakeProperties);
                            }
                        }
                        GrasshopperPlayer.Run(definition, ghData, Document);
                    }
                }
                transaction.Commit();
            }
            GhDrawingContext.LinkedDocument = saveDoc;
            EnableReactors();
        }