Friday, August 30, 2013

Sorry for the issue- the dynamic blog wasn't working very well

I reskinned my blog and the dynamic version didn't work too well - so I have dropped back to a simple version for now.

Wednesday, August 28, 2013

Ever had any stubborn text styles that wouldn't delete? I did- so I went to Boost Your BIM - Scrubbing Out Dimension Styles and adapted the code there to substitute one text style for another in my first useful macro! 

Start with a sample of text with the text style you want to replace, also add a sample of text style you want to match.

On runing the macro- it prompts in the STATUS BAR (tough to see - working on that) to select a text to replace, then the ext to match. Once completed you can run a purge and Voila! those peskt text styles should be available to purge!

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;

        public void TextSytleScrub()
            Document doc = this.ActiveUIDocument.Document;
            UIDocument uidoc = new UIDocument(doc);
            // Prompt user to select a -text- with an unwanted style
            TextNote selected = doc.GetElement (uidoc.Selection.PickObject (ObjectType.Element , "Select -text- with style to scrub.")) as TextNote ;
            // Get name of the -text- style of this -text-
            string toScrub = selected.TextNoteType.Name;
            // Find the -text- style named "Default" which will be used to replace the unwanted style
            // There must be a style named "Default" for this command to work

            TextNote replacement = doc.GetElement (uidoc.Selection.PickObject (ObjectType.Element , "Select -text- with replacement style.")) as TextNote ;
            // Get name of the -text- style of this -text-
            string toreplace = replacement.TextNoteType.Name;
            TextNoteType defaultType = (from v in new FilteredElementCollector(doc)
                                        where v.Name == replacement.TextNoteType.Name select v).First();
            using (Transaction t = new Transaction(doc,"Change -text- style to default"))
                // loop through all -textnote- with the unwanted style
                foreach (TextNote textnote in (from v in new FilteredElementCollector(doc).OfClass(typeof(TextNote)).Cast<TextNote>()
                                      where v.TextNoteType.Name == toScrub select v))
                    // change the -textnote-'s style to the default style
                    textnote.TextNoteType = defaultType;
            // Text in unplaced groups will not be found by the code above.
            // So we need to place an instance of each of these groups, find any -textnote- in the group, and change their style if needed
            foreach (GroupType groupType in new FilteredElementCollector(doc).OfClass(typeof(GroupType)))
                // if there are already instances of the group then skip to the next group type
                 if (groupType.Groups.Size > 0)
                 using (Transaction t = new Transaction(doc,"Change -textnote- style in unplaced groups"))
                    // use this flag to track if any -textnote- have been changed
                    bool flag = false;
                    // place an instance of the group
                    Group newGroup = doc.Create.PlaceGroup(XYZ.Zero, groupType);
                    // loop through all members in the group
                    foreach (ElementId id in newGroup.GetMemberIds())
                          // identify any -textnote- in the group
                          TextNote textnote = doc.GetElement(id) as TextNote;
                          if (textnote !null)
                              // check if this dimension has the unwanted type
                              if (textnote.TextNoteType.Name == toScrub)
                                  // change the dimension type to the default type
                                  textnote.TextNoteType = defaultType;
                                  flag = true;
                    doc.Delete(newGroup.Id); // delete the newly placed group
                    if (flag)
                          t.Commit(); // commit this transaction if any -textnote-s were changed
                          t.RollBack(); // no -textnote-s were changed, so throw away the entire transaction

Friday, August 23, 2013

Revit and the arch top, the language of arc segments and chord math.

Archtop windows that break... Revit has issues with circles. Sometimes it is very slick in how it maintains fillets, arcs connections and tangential references, other times it flips out at some of the simplest things, and these issues are sometimes random.

The basic language, spring point, rise, radius, intrados, top, creast are for simple arches.

This in geometric language is represented in Dr. Math's pages and on this reference to Chord Math from Open  Math website.

So we need to draw an arc- then make it flex so the width varies, but the rise is the same.

Simple enough right? Until this happens...
same family - at random points flips the arc:

I cannot even begin to explain why this happens.Guessing a glitch in Revit.

I have a workaround-  or more regular results anyways- by teaching Revit Arc's and arches fundamental language:

ARCH_r  = (Width ^ 2 + 4 * H ^ 2) / (8 * H)

r          is the radius of the arc
Width  is the width of the Chord (flat part)

Add this with a little resolution checking, and a variable origin and you should have a stable arc or arch:

Is tied to this detail family:

The trick is to move the origin (red arrow) which is also the geometric chord segment, 
based on the circle crest/top of arch (intrados) relative to the radius of the circle. 

So the circle center stays put- while the flex of the width drives the circle radius, and the Top reference plane.

The top reference plane is constrained back to the reference plane for the Center Elevation (CELE for short) marked by the red arrow with the H or Height of the chord segment. This is the rise of the arch.

The invisible lines are locked to the circle and the CELE reference plane. So in the detail component flexing the width raises the TOP reference plane. Which in turn drags the CELE reference plane. Left, right and center reference planes are set as references, while the construction "reference line" circle is set to not a reference.

Once the detail is in place the chord appears to stay put while the arc width changes.

One last tidbit.

if(not(Width / 2 > Arch Rise), Width / 2, Arch Rise)

If the Width /2 is less than or equal to Arch Rise, then use Width/2 to reference the intrados/crest/top of the arch, otherwise the arch will bulge out beyond creating a moorish arch:

Which you can allow if you wish by setting the H parameter equal to Arch Rise.