New PC, KLH Snoop, Annotations and Vertex Handling

I have been very busy and motivated indeed setting up a new computer this week.

Nonetheless, I was able to keep going full steam with Revit API related issues as well:

Baby lizard on MacBook

Setting up a New MacBook

I picked up my new computer on Monday, a MacBook Pro.

Migration worked very well so far, installation was easier than ever before, and I am already almost completely done moving over.

These components are now up and running:

A few security related issues remain to do:

I am writing this blog on the new system, with significant help and inspiration provided by my baby lizard friend presented in the image above.

By chance, now that I almost finished, I also just read this helpful article on how to set up your new MacBook for coding by Amber Wilkie on freeCodeCamp.org. I have already completed many of the steps she suggests; still, a few are new and useful for me as well.

KLH Engineers RevitDeveloperTools Snooping Tool

More Revit API related, John D'Alessandro, Software Engineer at KLH Engineers, PSC shared a powerful new Revit database snooping utility, explaining:

We at KLH Engineers decided to roll our own Revit Snoop tool a while ago and we thought we’d show it to you so you can check it out.

KLH Snoop

We released it as a class library on our GitHub so that others can use it in their own tools and solutions.

We’re also accepting issues and PRs, so the more people use the tool the better it’ll get. Let me know if you have any feedback on it or questions.

The repo is at KLH Engineers RevitDeveloperTools.

It has some similarities and overlap with RevitLookup, and adds a number of features not available there.

The README includes a feature list comparing the two snooping tools:

KLH Snoop feature list

Many thanks to John and KLH for implementing and generously sharing this powerful new snooping tool!

Pulling Text from Annotation Tags

One quick note on a small issue that was not discussed in the public Revit API discussion forum seems worthwhile sharing here:

Question: I'm trying to pull the text from the annotation tags on a drawing using the Revit API. Is that possible? How?

Answer: Yes, this is definitely possible.

You can use a filtered element collector to collect all the annotation tags, and then access their text via their properties.

To retrieve the tags, you need to determine what class they have. I assume they are IndependentTag class instances.

The property to access their text is presumably the TagText property.

You can install and use RevitLookup yourself to validate these assumptions of mine in your own specific model.

If these assumptions are correct, the final solution might look something like this in C#:

#region Pull Text from Annotation Tags
/// <summary>
/// Return the text from all annotation tags 
/// in a list of strings
/// </summary>
List<string> PullTextFromAnnotationTags(
  Document doc )
{
  FilteredElementCollector tags
    = new FilteredElementCollector( doc )
      .OfClass( typeofIndependentTag ) );

  return new List<string>( tags
    .Cast<IndependentTag>()
    .Select<IndependentTagstring>(
      t => t.TagText ) );
}
#endregion // Pull Text from Annotation Tags

For future reference, I also added this code to The Building Coder samples in the CmdCollectorPerformance.cs module

Finally, you can use the built-in Revit macro IDE (integrated development environment) to convert this code from C# to Python, if you like.

Vertex Handling

Another recent recurring question on vertex handling may also be of general interest:

Question: When processing meshes or other collections of triangles, is there any way to know if one vertex is shared by multiple triangles?

Thus, the final data does not have to contain duplicate vertices and can reuse the existing vertex indices in order to save data size.

Answer: I have often used strategies similar to the following when collecting mesh data:

The comparison operator needs to accommodate an appropriate amount of fuzz, cf. this dimensioning application.

For some examples, look at GetCanonicVertices for tracking element modification and this post on the XYZ class.

For yet more examples and use cases, you can search The Building Coder for

The True Meaning of Pizza

I am writing this visiting my friend Dani in Verbania, Italy.

Hence, this little note in closing:

Did you ever wonder why pizza is called pizza?

Well, pretty obviously, it simply represents the formula used by a hungry mathematician to determine its volume from its radius z and thickness a:

  Volume = π · z 2 · a = pi · z · z · a

Pizza volume formula

Pizza volume formula V = pi·z·z·a