public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument        uidoc = commandData.Application.ActiveUIDocument;
            Document          doc   = uidoc.Document;
            IList <Reference> referenceCollection = uidoc.Selection.PickObjects(ObjectType.Face);

            MessageBox.Show("You have selected total " + referenceCollection.Count.ToString() + " faces.");
            Transaction trans = new Transaction(doc);

            trans.Start("建立網格");
            foreach (Reference face in referenceCollection)
            {
                DividedSurface ds  = DividedSurface.Create(doc, face);
                SpacingRule    srU = ds.USpacingRule;
                srU.SetLayoutFixedDistance(1, SpacingRuleJustification.Center, 0, 0);
                SpacingRule srV = ds.VSpacingRule;
                srV.SetLayoutFixedDistance(1, SpacingRuleJustification.Center, 0, 0);
                Element  host        = ds.Host;
                Face     dividefaces = host.GetGeometryObjectFromReference(ds.HostReference) as Face;
                GridNode node        = new GridNode();
                UV       uv          = ds.GetGridNodeUV(node);
                XYZ      pt          = dividefaces.Evaluate(uv);
                MessageBox.Show(pt.ToString());
            }

            trans.Commit();
            return(Result.Succeeded);
        }
        private void IdentifyTokenSpacing(SyntaxToken token)
        {
            // don't adjust spacing in genernal if there are already line breaks
            if (TextFacts.HasLineBreaks(token.Trivia))
            {
                return;
            }

            // if no previous token then leave as is
            var prev = token.GetPreviousToken();

            if (prev == null)
            {
                return;
            }

            if (IsIdentifierOrKeyword(token) && IsIdentifierOrKeyword(prev))
            {
                // always have space between two adjacent names
                if (token.Trivia != " ")
                {
                    AddRule(token, SpacingRule.From(SpacingKind.SingleSpaceIfOnSameLine));
                }
            }
            else if (token.Parent is BinaryExpression be && be.Operator == token ||
                     prev.Parent is BinaryExpression pbe && pbe.Operator == prev)
            {
                // space before and after binary operator
                if (token.Trivia != " ")
                {
                    AddRule(token, SpacingRule.From(SpacingKind.SingleSpaceIfOnSameLine));
                }
            }
Example #3
0
 private bool TryGetSpacingRule(SyntaxElement element, out SpacingRule rule)
 {
     return(_spacingRules.TryGetValue(element, out rule));
 }