Esempio n. 1
0
        private void SetupPython()
        {
            if (setupPython)
            {
                return;
            }

            IronPythonEvaluator.OutputMarshaler.RegisterMarshaler(
                (Element element) => element.ToDSType(true));

            // Turn off element binding during iron python script execution
            IronPythonEvaluator.EvaluationBegin           +=
                (a, b, c, d, e) => ElementBinder.IsEnabled = false;
            IronPythonEvaluator.EvaluationEnd += (a, b, c, d, e) => ElementBinder.IsEnabled = true;

            // register UnwrapElement method in ironpython
            IronPythonEvaluator.EvaluationBegin += (a, b, scope, d, e) =>
            {
                var marshaler = new DataMarshaler();
                marshaler.RegisterMarshaler(
                    (Revit.Elements.Element element) => element.InternalElement);
                marshaler.RegisterMarshaler((Category element) => element.InternalCategory);

                Func <object, object> unwrap = marshaler.Marshal;
                scope.SetVariable("UnwrapElement", unwrap);
            };

            setupPython = true;
        }
Esempio n. 2
0
        public DynamoController_Revit(RevitServicesUpdater updater, string context, IUpdateManager updateManager, string corePath)
            : base(
                context,
                updateManager,
                new RevitWatchHandler(),
                Dynamo.PreferenceSettings.Load(),
                corePath)
        {
            Updater = updater;

            dynRevitSettings.Controller = this;

            DocumentManager.Instance.CurrentUIApplication.Application.DocumentClosed +=
                Application_DocumentClosed;
            DocumentManager.Instance.CurrentUIApplication.Application.DocumentOpened +=
                Application_DocumentOpened;
            DocumentManager.Instance.CurrentUIApplication.ViewActivated += Revit_ViewActivated;

            // Set the intitial document.
            if (DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument != null)
            {
                DocumentManager.Instance.CurrentUIDocument =
                    DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
                dynSettings.DynamoLogger.LogWarning(GetDocumentPointerMessage(), WarningLevel.Moderate);
            }

            TransactionWrapper = TransactionManager.Instance.TransactionWrapper;
            TransactionWrapper.TransactionStarted   += TransactionManager_TransactionCommitted;
            TransactionWrapper.TransactionCancelled += TransactionManager_TransactionCancelled;
            TransactionWrapper.FailuresRaised       += TransactionManager_FailuresRaised;

            MigrationManager.Instance.MigrationTargets.Add(typeof(WorkspaceMigrationsRevit));
            ElementNameStore = new Dictionary <ElementId, string>();

            var revitPath = Path.Combine(DynamoPaths.MainExecPath, @"Revit_2014\RevitNodes.dll");
            var raasPath  = Path.Combine(DynamoPaths.MainExecPath, @"Revit_2014\SimpleRaaS.dll");

            EngineController.ImportLibrary(revitPath);
            EngineController.ImportLibrary(raasPath);

            //IronPythonEvaluator.InputMarshaler.RegisterMarshaler((WrappedElement element) => element.InternalElement);
            IronPythonEvaluator.OutputMarshaler.RegisterMarshaler((Element element) => element.ToDSType(true));
            //IronPythonEvaluator.OutputMarshaler.RegisterMarshaler((IList<Element> elements) => elements.Select(e=>e.ToDSType(true)));

            // Turn off element binding during iron python script execution
            IronPythonEvaluator.EvaluationBegin += (a, b, c, d, e) => ElementBinder.IsEnabled = false;
            IronPythonEvaluator.EvaluationEnd   += (a, b, c, d, e) => ElementBinder.IsEnabled = true;

            // register UnwrapElement method in ironpython
            IronPythonEvaluator.EvaluationBegin += (a, b, scope, d, e) =>
            {
                var marshaler = new DataMarshaler();
                marshaler.RegisterMarshaler((WrappedElement element) => element.InternalElement);

                Func <WrappedElement, object> unwrap = marshaler.Marshal;
                scope.SetVariable("UnwrapElement", unwrap);
            };

            Runner = new DynamoRunner_Revit(this);
        }
Esempio n. 3
0
        public static void MarshalEnumerables()
        {
            var marshaler = new DataMarshaler();
            marshaler.RegisterMarshaler((string s) => s.Length);

            Assert.AreEqual(new[] { 0, 1, 2 }, marshaler.Marshal(new[] { "", " ", "  " }));
            Assert.AreEqual(new[] { 0, 1, 2, 3, 4 }, marshaler.Marshal(new object[] { "", 1, 2, "   ", 4 }));
        }
Esempio n. 4
0
        public static void MarshalEnumerables()
        {
            var marshaler = new DataMarshaler();

            marshaler.RegisterMarshaler((string s) => s.Length);

            Assert.AreEqual(new[] { 0, 1, 2 }, marshaler.Marshal(new[] { "", " ", "  " }));
            Assert.AreEqual(new[] { 0, 1, 2, 3, 4 }, marshaler.Marshal(new object[] { "", 1, 2, "   ", 4 }));
        }
Esempio n. 5
0
        public static void MarshalTest()
        {
            var marshaler = new DataMarshaler();
            marshaler.RegisterMarshaler((double d) => "Double: " + d);
            marshaler.RegisterMarshaler((int i) => "Int: " + i);
            marshaler.RegisterMarshaler((object o) => "Other: " + o);

            Assert.AreEqual("Double: 1", marshaler.Marshal(1.0));
            Assert.AreEqual("Int: 1", marshaler.Marshal(1));
            Assert.AreEqual("Other: hello", marshaler.Marshal("hello"));
        }
Esempio n. 6
0
        public static void MarshalTest()
        {
            var marshaler = new DataMarshaler();

            marshaler.RegisterMarshaler((double d) => "Double: " + d);
            marshaler.RegisterMarshaler((int i) => "Int: " + i);
            marshaler.RegisterMarshaler((object o) => "Other: " + o);

            Assert.AreEqual("Double: 1", marshaler.Marshal(1.0));
            Assert.AreEqual("Int: 1", marshaler.Marshal(1));
            Assert.AreEqual("Other: hello", marshaler.Marshal("hello"));
        }
Esempio n. 7
0
        public static void MarshalSubclass()
        {
            var marshaler = new DataMarshaler();
            marshaler.RegisterMarshaler((Super s) => "Super");
            marshaler.RegisterMarshaler((Sub2 s2) => "Sub2");
            marshaler.RegisterMarshaler((object o) => "Other");

            Assert.AreEqual("Super", marshaler.Marshal(new Super()));
            Assert.AreEqual("Super", marshaler.Marshal(new Sub()));
            Assert.AreEqual("Sub2", marshaler.Marshal(new Sub2()));
            Assert.AreEqual("Sub2", marshaler.Marshal(new Sub3()));
            Assert.AreEqual("Other", marshaler.Marshal(1));
        }
Esempio n. 8
0
        public static void MarshalSubclass()
        {
            var marshaler = new DataMarshaler();

            marshaler.RegisterMarshaler((Super s) => "Super");
            marshaler.RegisterMarshaler((Sub2 s2) => "Sub2");
            marshaler.RegisterMarshaler((object o) => "Other");

            Assert.AreEqual("Super", marshaler.Marshal(new Super()));
            Assert.AreEqual("Super", marshaler.Marshal(new Sub()));
            Assert.AreEqual("Sub2", marshaler.Marshal(new Sub2()));
            Assert.AreEqual("Sub2", marshaler.Marshal(new Sub3()));
            Assert.AreEqual("Other", marshaler.Marshal(1));
        }
Esempio n. 9
0
        private void SetupPython()
        {
            //IronPythonEvaluator.InputMarshaler.RegisterMarshaler((WrappedElement element) => element.InternalElement);
            IronPythonEvaluator.OutputMarshaler.RegisterMarshaler((Element element) => element.ToDSType(true));
            //IronPythonEvaluator.OutputMarshaler.RegisterMarshaler((IList<Element> elements) => elements.Select(e=>e.ToDSType(true)));

            // Turn off element binding during iron python script execution
            IronPythonEvaluator.EvaluationBegin += (a, b, c, d, e) => ElementBinder.IsEnabled = false;
            IronPythonEvaluator.EvaluationEnd += (a, b, c, d, e) => ElementBinder.IsEnabled = true;

            // register UnwrapElement method in ironpython
            IronPythonEvaluator.EvaluationBegin += (a, b, scope, d, e) =>
            {
                var marshaler = new DataMarshaler();
                marshaler.RegisterMarshaler((WrappedElement element) => element.InternalElement);

                Func<object, object> unwrap = marshaler.Marshal;
                scope.SetVariable("UnwrapElement", unwrap);
            };
        }
Esempio n. 10
0
        private void SetupPython()
        {
            if (setupPython) return;

            IronPythonEvaluator.OutputMarshaler.RegisterMarshaler((Autodesk.Revit.DB.Element element) => ElementWrapper.ToDSType(element, (bool)true));

            // Turn off element binding during iron python script execution
            IronPythonEvaluator.EvaluationBegin += (a, b, c, d, e) => ElementBinder.IsEnabled = false;
            IronPythonEvaluator.EvaluationEnd += (a, b, c, d, e) => ElementBinder.IsEnabled = true;

            // register UnwrapElement method in ironpython
            IronPythonEvaluator.EvaluationBegin += (a, b, scope, d, e) =>
            {
                var marshaler = new DataMarshaler();
                marshaler.RegisterMarshaler((Revit.Elements.Element element) => element.InternalElement);
                marshaler.RegisterMarshaler((Revit.Elements.Category element) => element.InternalCategory);

                Func<object, object> unwrap = marshaler.Marshal;
                scope.SetVariable("UnwrapElement", unwrap);
            };

            setupPython = true;
        }