public override BasePattern Transform(BasePattern pattern)
        {
            BasePattern transformed = pattern;

            if (pattern.Type == PatternType.Char)
            {
                if (Options.Singleline && transformed is AnyCharPattern)
                    transformed = new AnyCharPattern(true);

                if (Options.IgnoreCase)
                    transformed = ((CharPattern)transformed).CaseInsensitive;
            }
            else if (pattern.Type == PatternType.Anchor)
            {
                AnchorPattern anchor = (AnchorPattern)pattern;

                if (anchor.AnchorType == AnchorType.StartOfStringOrLine)
                    transformed = new AnchorPattern(Options.Multiline ? AnchorType.StartOfLine : AnchorType.StartOfString);
                else if (anchor.AnchorType == AnchorType.EndOfStringOrLine)
                    transformed = new AnchorPattern(Options.Multiline ? AnchorType.EndOfLine : AnchorType.EndOfStringOrBeforeEndingNewline);
            }

            if (transformed != pattern)
                return transformed;
            else
                return base.Transform(pattern);
        }
Esempio n. 2
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public virtual Result Execute(ExternalCommandData commandData
                                      , ref string message, ElementSet elements)
        {
            // Get the document from external command data.
            UIDocument activeDoc = commandData.Application.ActiveUIDocument;

            Autodesk.Revit.DB.Document doc = activeDoc.Document;

            if (null == doc)
            {
                return(Result.Failed);
            }

            try
            {
                // Selecting the elements to create the anchor pattern on
                Reference eRef = activeDoc.Selection.PickObject(ObjectType.Element, "Pick an element to create the anchor pattern on");

                // Start detailed steel modeling transaction
                using (FabricationTransaction trans = new FabricationTransaction(activeDoc.Document, false, "Create anchor pattern"))
                {
                    // We create the anchor pattern using Advance Steel classes and objects only.
                    // for more details, please consult http://www.autodesk.com/adv-steel-api-walkthroughs-2019-enu
                    List <FilerObject> filerObjectList = new List <FilerObject>();
                    FilerObject        filerObj        = Utilities.Functions.GetFilerObject(doc, eRef);

                    if (null == filerObj)
                    {
                        return(Result.Failed);
                    }

                    filerObjectList.Add(filerObj);

                    // Point of reference for the anchor pattern. We use GlobalPoint to create the pattern on the plate. GlobalPoint is the point where the plate is being hit when selected.
                    Point3d       p1            = new Point3d(eRef.GlobalPoint.X, eRef.GlobalPoint.Y, eRef.GlobalPoint.Z);
                    Point3d       p2            = new Point3d(p1.x + 0.5, p1.y + 0.5, p1.z + 0.5);
                    AnchorPattern anchorPattern = new AnchorPattern(p1 * Utilities.Functions.FEET_TO_MM, p2 * Utilities.Functions.FEET_TO_MM, new Vector3d(1, 0, 0), new Vector3d(0, 1, 0));
                    anchorPattern.Connect(filerObjectList.ToArray(), Autodesk.AdvanceSteel.ConstructionTypes.AtomicElement.eAssemblyLocation.kOnSite);
                    anchorPattern.WriteToDb();

                    trans.Commit();
                }
            }

            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            return(Result.Succeeded);
        }
        public override BasePattern Transform(BasePattern pattern)
        {
            BasePattern transformed = pattern;

            if (pattern.Type == PatternType.Char)
            {
                if (Options.Singleline && transformed is AnyCharPattern)
                {
                    transformed = new AnyCharPattern(true);
                }

                if (Options.IgnoreCase)
                {
                    transformed = ((CharPattern)transformed).CaseInsensitive;
                }
            }
            else if (pattern.Type == PatternType.Anchor)
            {
                AnchorPattern anchor = (AnchorPattern)pattern;

                if (anchor.AnchorType == AnchorType.StartOfStringOrLine)
                {
                    transformed = new AnchorPattern(Options.Multiline ? AnchorType.StartOfLine : AnchorType.StartOfString);
                }
                else if (anchor.AnchorType == AnchorType.EndOfStringOrLine)
                {
                    transformed = new AnchorPattern(Options.Multiline ? AnchorType.EndOfLine : AnchorType.EndOfStringOrBeforeEndingNewline);
                }
            }

            if (transformed != pattern)
            {
                return(transformed);
            }
            else
            {
                return(base.Transform(pattern));
            }
        }
        internal static AnchorPattern Ancorare(int index)
        {
            AnchorPattern ap = new AnchorPattern();
            AnchorPoint   apo1, apo2, apo3;

            if (index == 0) //AND
            {
                apo1 = new AnchorPoint(0, 25, true, false, MarkStyle.Circle, Color.Blue);
                apo2 = new AnchorPoint(0, 57, true, false, MarkStyle.Circle, Color.Blue);
                apo3 = new AnchorPoint(89, 42, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                ap.Points.Add(apo2);
                ap.Points.Add(apo3);
                return(ap);
            }
            else if (index == 1) //OR
            {
                apo1 = new AnchorPoint(0, 27, true, false, MarkStyle.Circle, Color.Blue);
                apo2 = new AnchorPoint(0, 59, true, false, MarkStyle.Circle, Color.Blue);
                apo3 = new AnchorPoint(89, 44, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                ap.Points.Add(apo2);
                ap.Points.Add(apo3);
                return(ap);
            }
            else if (index == 2) //XOR
            {
                apo1 = new AnchorPoint(0, 27, true, false, MarkStyle.Circle, Color.Blue);
                apo2 = new AnchorPoint(0, 59, true, false, MarkStyle.Circle, Color.Blue);
                apo3 = new AnchorPoint(89, 44, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                ap.Points.Add(apo2);
                ap.Points.Add(apo3);
                return(ap);
            }
            else if (index == 3) //NOT
            {
                apo1 = new AnchorPoint(0, 45, true, false, MarkStyle.Circle, Color.Blue);
                apo2 = new AnchorPoint(89, 45, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                ap.Points.Add(apo2);
                return(ap);
            }
            else if (index == 4) //INPUT 0
            {
                apo1 = new AnchorPoint(89, 43, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                return(ap);
            }
            else if (index == 5) //INPUT 1
            {
                apo1 = new AnchorPoint(89, 43, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                return(ap);
            }
            else if (index == 6) //OUTPUT (terminator)
            {
                apo1 = new AnchorPoint(0, 43, true, false, MarkStyle.Circle, Color.Blue);

                ap.Points.Add(apo1);
                return(ap);
            }
            else
            {
                return(null);
            }
        }
        private void LoadBasicFlowchartNodes()
        {
            diagram.Behavior = Behavior.DrawLinks;
            shapeLibrary.LoadFromXml(@"../../CustomNodes/CustomLibrary/BasicFlowchart.sl");
            NodesFromLib();
            shapeList.SelectedIndex = 0;

            // Process Node (square anchors)
            AnchorPattern squareAnchors = new AnchorPattern(new AnchorPoint[]
            {
                // if you picture the node as a grid, top left is 0,0
                // bottom right is 100,100, center is 50,50, etc...
                // first value is X axis, 2nd is the Y axis
                // yes i had to figure this out myself, no i dont know what true is for but its true
                // what is documentation
                new AnchorPoint(50, 0, true, true),
                new AnchorPoint(100, 50, true, true),
                new AnchorPoint(50, 100, true, true),
                new AnchorPoint(0, 50, true, true)
            });

            // probably should have a better way of doing this instead of hard coding
            // the getItemAt()

            ShapeNode processNode = shapeList.Items.GetItemAt(0) as ShapeNode;

            processNode.Name                  = "processNode";
            processNode.AnchorPattern         = squareAnchors;
            processNode.TextAlignment         = TextAlignment.Center;
            processNode.TextVerticalAlignment = AlignmentY.Center;
            processNode.ResizeToFitText(FitSize.KeepRatio);

            // Start/End Node (same square anchors)
            ShapeNode startEndNode = shapeList.Items.GetItemAt(4) as ShapeNode;

            startEndNode.Name                  = "startEndNode";
            startEndNode.AnchorPattern         = squareAnchors;
            startEndNode.PolygonalTextLayout   = true;
            startEndNode.TextAlignment         = TextAlignment.Center;
            startEndNode.TextVerticalAlignment = AlignmentY.Center;
            startEndNode.ResizeToFitText(FitSize.KeepRatio);

            // Decision Node
            ShapeNode decisionNode = shapeList.Items.GetItemAt(5) as ShapeNode;

            decisionNode.Name                  = "decisionNode";
            decisionNode.AnchorPattern         = squareAnchors;
            decisionNode.PolygonalTextLayout   = true;
            decisionNode.TextAlignment         = TextAlignment.Center;
            decisionNode.TextVerticalAlignment = AlignmentY.Center;
            decisionNode.ResizeToFitText(FitSize.KeepRatio);

            // Data Node
            ShapeNode dataNode = shapeList.Items.GetItemAt(1) as ShapeNode;

            dataNode.Name                  = "dataNode";
            dataNode.AnchorPattern         = squareAnchors;
            dataNode.PolygonalTextLayout   = true;
            dataNode.TextAlignment         = TextAlignment.Center;
            dataNode.TextVerticalAlignment = AlignmentY.Center;
            dataNode.ResizeToFitText(FitSize.KeepRatio);

            // Subprocess Node
            ShapeNode subprocessNode = shapeList.Items.GetItemAt(2) as ShapeNode;

            subprocessNode.Name                  = "subprocessNode";
            subprocessNode.AnchorPattern         = squareAnchors;
            subprocessNode.TextAlignment         = TextAlignment.Center;
            subprocessNode.TextVerticalAlignment = AlignmentY.Center;
            subprocessNode.ResizeToFitText(FitSize.KeepRatio);

            // Document Node
            ShapeNode documentNode = shapeList.Items.GetItemAt(3) as ShapeNode;

            documentNode.Name                  = "documentNode";
            documentNode.AnchorPattern         = squareAnchors;
            documentNode.AnchorPattern         = squareAnchors;
            documentNode.TextAlignment         = TextAlignment.Center;
            documentNode.TextVerticalAlignment = AlignmentY.Center;
            documentNode.ResizeToFitText(FitSize.KeepRatio);

            diagram.LinkHeadShape     = MindFusion.Diagramming.Wpf.ArrowHeads.Circle;
            diagram.LinkHeadShapeSize = 10; // dont ask me what 10 is refering to in this case.
        }