Translating View Crop Coordinates to Model Coordinates for Elevations

This caused me a fair bit of heartburn, and I think I correctly reverse engineered Revit; but I’m hoping someone can confirm who knows the coding better, is there a node or code tool intended to do this? For an elevation view, the view crop bounding box coordinates are specific that view, the below solution is what I found to translate those values to model space to output a surface that reflects the view boundary.

The View.CropBox property is listed in the Revit API Docs: The X direction of the box is right on screen; Y is up; and Z is towards the user. The crop box Z value of a plan view is not meaningful.

However, I couldn’t find any documents how those coordinate relate to model space. After extracting points and tracing them in Revit, this is my understanding:

  • View crop X coordinates are a distance from the View Origin along a vector 90° counter-clockwise in plan from the View Direction.
  • View crop Y coordinates are set a height from the Z coordinates of the View Origin.
  • View crop Z coordinates are the view depth from the view plan (so along the View Direction vector). I disregarded this value in the below graph as it wasn’t needed for my process.

I used the below nodes to do the translation. I’d be grateful if anyone knew a simpler way or if this is the correct strategy to find an elevations view crop in model space.

Thank you and hope this also helps any others trying to understand this issue.

Trevor

Transpose ViewCrop to Model Points.dyn (58.4 KB)

Out of curiousity. What is your end goal?
What are you using that Surface for?
I guess your other topic got something to do
with it :laughing:.

PS
Next time zoom so the titles of your nodes are readable. When you export your workspace all the nodes get exported. So also the ones you
cannot see when exporting :sweat_smile:.

My end goal was to calculate the area of a room intersecting the view. Views in, a surface that matches their area in model space out. Then the graph renames the view based on the intersecting room with highest area value (see also this post: Running if statement logic within list loop still runs the true action even when false - DesignScript - Dynamo).

The entire graph is very large, almost all of it unrelated to the translation of the view boundary, so decided to crop to this only. This function seems to be doing its job of giving a surface that matches the view area. But it seems very complicated and I’ve not been able to confirm if it’s the “correct” approach. Maybe other people have more experience on if this will break in unusual conditions and how to avoid that? Or maybe this is it, I couldn’t find anything in the forum where someone broke down how to translate view coordinate into model coordinates, at least in a language I could understand.

*edit: sorry, the intent is that when the client wants to renumber and rename all the rooms in the project near the end of CD’s and insists that the construction document reflect that, the project team has a quick solution rather than manually do all the renaming. It’s a chore for a project with 100 interior elevation sheets.

Still exporting the whole graph with readable nodes would help a lot. Or, at the very least,
make sure the titles of the nodes of the part you are sharing are readable.

I think you should be able to click the graphic picture to enlarge it right? It lets me do that on my end (see below) The DYN file should also be there if you want to poke at it.

No :sweat_smile:.

This is a common use case, with a VERY simple solution. You have just stumbled off the ‘easy’ road and into the thicket of thorn bushes as you thought you saw a shortcut from ‘previous room number changes to new room number’, and now you’re facing a LOT of cuts as a result. Instead of giving you the solution, I am going to give you some guidance that should help you find the easy road. If you struggle too much I’ll give a more direct answer, but learning to think these things through is a must for any computational designer.

First up, step away from Dynamo and even the computer. Instead go pick up a notebook and pen, or stand at the whiteboard. Now write down every step you think you need the Dynamo graph to do in the order you need it to be done. When a step needs info from a previous step draw an arrow from the proceeding step to the new one. A LOT of my old posts do exactly this. After you do this one of the three ‘easy’ paths will usually reveal itself (none of them involve the view crop). If so, you can then elaborate on the path (note specific nodes or things to watch out for or be careful with), and if the easy path doesn’t reveal itself post the store back here and I’ll add some emphasis to help you see it in a way which will help you learn not just get you the solution.

Jacob, please, enlighten!
I did just that, and the simple solution was to have each view that’s already made find the largest room it intersects, then rename the view based on that room. All other workflows I could think of broke down at one edge case or another, such as views frequently see multi-rooms. The resulting workflow means translating the view into a surface so I can run an intersection with the rooms.

As noted in another recent post, there’s not many resources out there for people who don’t have a coding background, so any information on processes and how-to’s are appreciated. I’ve scoured everything I could find on and off these forums for solutions.

I think what Jacob is getting at is looking a bit more big picture with your start and end goals.

This solution might not be valid for your case, but I’ve somewhat recently renumbered room data sheets for a project after someone renumbered all the rooms. I grabbed the old archive model, generated a csv with the element ids and old room numbers, then compared this in the current model to find which numbers had changed to what, and I could then basically just do a fancy find and replace on view and sheet names.

Something like this:

  1. Get all the rooms.
  2. Get all the current room numbers.
  3. Increment the logic for shifting the numbers around.
  4. Write the new room number back to the room.

First easy path for views: you have the before room numbers (step 2) and the after room numbers (step 3). Read all interior elevation names, parse the number from the title, swap the parsed value to the after paired with the current value.

Second easy path:
Get all the interior elevations tags. Find the point of those tags. Find the room at that point. Get the new room number.

Third easy path: gather the elevations before you apply the room logic. Group the elevations by their matching room name/number. Join the rooms and elevations into the same list. Renumber/remame both at the same time.

Fourth easy path: don’t renumber the rooms, but write out a dictionary set of ‘before : after’ key value pairs to a JSON file. Use that JSON file to build a ‘number adjuster’ graph which gets all elements of a selected category in your default 3D view, wireframes everything else, and sets the names/numbers accordingly. Rooms, elevations, doors, furniture, anything with a room number sequence in the mark, number, or title can be bulk processed this way (remember schedules are views as well)

Yes, I’ve had to do that before as well, it’s not fun :sob: . This seems to be a consistent issue late in our process when we have hundreds of views already set; our clients are large institutions and are not flexible once their committees finish a “this is the room system now we want and we can no longer live with the version approved yesterday”. I’m trying to develop a script that can do this without needing to cross reference an archived model, it just lets the team implement the room name/number change and hit go and it will update the documents.

Hi,
If the goal is to find the room that contains the view (and then rename this view) while eliminating the room that do not appear completely in the elevation, I do think that calculating by subtracting solids is one of the best solutions.

Section views have a transformation; here is an example of how to find the solid of a section view. You’ll need to adapt the code to your needs.

  1. Retrieve all visible rooms in the section view and obtain their solids (all elements in ActiveView).
  2. Retrieve the corrected solid of the section view (via Transformation).
  3. For each solid room, perform a solid subtraction with the section solid and determine the correct room based on the results.

That is very helpful thank you! I think the mess of the project world makes many of those workflows hard, sadly, buildings and large institutional clients are never as straightforward as to have a “logic” for shifting numbers around and rarely are they a 1 to 1 transition. It’s always messy, limiting options for just a is now b solutions. Ie. “I don’t want my room with that suite number, it should have its own; or the opposite, that reception area can’t have it’s own room, it’s part of this suite…” etc.

I’ve not worked with JSON file & dictionaries, they inherently seem more manual and complicated than just having each view find what rooms it can see and then picking the one that it’s in and then adjusting its name/number. Then all the team can redo the rooms as needed and hit go on the script to have the views & titles match.

I’ve struggled with the elevation tags “point”, I have found almost no documentation about how the room elevation point is created as it never seems to output a point within the actual view area. In my testing, View.Origin seems to return a view near the origin and then the view relies on the view crop to set it’s position in the drawing. I wasn’t able to find any documentation linking the View.Origin to the actual view scope, I spent some time and I may have reverse engineered it, but I’m still not 100% sure it’s correct. But if there’s a confirmed way to do this, that would be a better process.

I’ll double check if I can simplify the overall code to simplify the view to a single point that is in fact in the view area instead of somewhere near the origin and then I can run the script to see what room it’s in instead of using it to create a geometry intersection of all the rooms it can see.

Yes that is the goal - I should have noted I have a *mostly working solution once I get the room surface, I use the geometry intersection to find the room with the largest intersecting area, and then use that room.

The tough one that got me on this is view range, sometimes a room (like a closet) is entirely within the view and would return as valid, even though it’s not within the room.

Thank that link on the solid from view has been part of the item vexing me for a long time! Not being able to find a way to translate a view into a model space object is the reason I did all the research to figure out the view crop transforms! I’m not very good at actual coding, how does the solid_fromBBX automatically make the transformation from view coordinates to model coordinates to create the solid? Or does bbox somehow extract directly in model coordinates while the node View.BoundingBox doesn’t? See below snips from the code link you posted

def solid_fromBBX(bbox):
pt0 = XYZ( bbox.Min.X, bbox.Min.Y, bbox.Min.Z )
pt1 = XYZ( bbox.Max.X, bbox.Min.Y, bbox.Min.Z )
pt2 = XYZ( bbox.Max.X, bbox.Max.Y, bbox.Min.Z )
pt3 = XYZ( bbox.Min.X, bbox.Max.Y, bbox.Min.Z )
#create generator
pairPts = gen_PairPts(pt0, pt1, pt2, pt3)
#Create loop, still in BBox coords
edges = List[Curve]()
for pt1, pt2 in pairPts:
edges.Add(Line.CreateBound( pt1, pt2 ))

height = bbox.Max.Z - bbox.Min.Z
baseLoop = CurveLoop.Create( edges )
loopList = List\[CurveLoop\]()
loopList.Add( baseLoop )
preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry( loopList, XYZ.BasisZ, height )
transformBox = SolidUtils.CreateTransformed( preTransformBox, bbox.Transform )
return transformBox

…
if view_.ViewType == ViewType.Section:
for lnkInstance in linkInstances:
lnk_doc = lnkInstance.GetLinkDocument()
transf = lnkInstance.GetTotalTransform()
bbxView = view_.CropBox
solidbbx = solid_fromBBX(bbxView)
# apply link instance transform and create Filters (Solid + Categories)
solidbbx = DB.SolidUtils.CreateTransformed(solidbbx, transf.Inverse)
filterSolid = ElementIntersectsSolidFilter(solidbbx)
cats = List[BuiltInCategory](catBiplst)
filtercat = ElementMulticategoryFilter(cats)
elemIntersect = FilteredElementCollector(lnk_doc).WherePasses(filterSolid).WherePasses(filtercat).WhereElementIsNotElementType().ToElements()
# FOR DEBUG
#out.append([lnkInstance.Name, elemIntersect, solidbbx.ToProtoType()])
temp.append([lnkInstance.Name, elemIntersect])

The logic is the hard bit - you have to work that process out either way though. Once you do, the data is reusable again and again and again. At a minimum tag location always work (and supports adjusting the the numbers/marks for other element types too.

They’re actually super easy.
Dictionary.ByKeysValues where the keys are the old room number and the values are the new room numbers. The node StringifyJSON will then convert that dictionary to a string which you can save to an external text file with a WriteText node.

The second graph reads that text file (ReadText), and uses a Data.ParseJSON which converts the string you saved into the file into the dictionary. You can then use a Dictionary.ValueAtKey node to get the new room number (the value) by giving any old room number (the key). Works for anything with a derived room number, just be sure to set a parameter for “has room number updated” so you don’t renumber something a second time.

yes