revit

Clear Cache in Desktop Connector 13.x

Top tip from a co-worker, the new Desktop Connector 13.x allows you to clear the Desktop Connector cache, so if you’re someone that is limited on space or wants to clear up old project data, then this is for you!

This isn’t the same cache as your C4R/BIM360 cloud model cache, but rather the cache of files from Desktop Connector. This cache would include items such as non-workshared RVT links, DWG, IFC, NWC links or other files that you have been accessing through desktop connector.

It’s a simple enough process to clear up the space, and unlike my C4R Cache Cleaner, you cannot delete individual files, it simply deletes the entire cache for a given project.

Right click on your project of choice, and from there the only menu option that you’re presented with is to free up space.

Confirm that you want to clear the cache and you’re away. Once you see the confirmation notification, you’re all done.

I personally only had 2.9gb of cache for this particular project, but others on my team are reporting upwards of 25gb of files they no longer needed locally cached.

Need to reclaim more space?

If you’re struggling with available space on your system and a hard drive upgrade isn’t an option, I highly recommend Space Sniffer if you’re on Windows. It gives an easy to follow visual representation of what is taking up space on your system and where.

You can take a visual deep dive through your folders to see where data is stored. Just keep in mind some things are critical to the operation of Windows and can’t be deleted, but if you have 7 versions of Revit installed for example, when you see how much room they take up it might finally give you the nudge that you need to uninstall a few versions that you no longer use.

Build Your Own Unassisted PowerShell Uninstallers

A fair chunk of what I do these days in the office is around testing software prior to packaging and deployment.

If you have ever had to install and uninstall Autodesk software for testing purposes, or you just wanted to get rid of an old version of the software you’d know that it’s not as simple as it probably should be. Rather than just uninstall Revit, you need to uninstall Revit and a whole host of other applications.

Yep.. that’s a lot of clicking

A while ago, I posted a solution for how to uninstall the 2015 Building Design Suite with PowerShell, the problem is however that this solution no longer works with the current Powershell; it was written for v2.x and Windows 10 is deployed with v5.x

To get the job done in Windows 10, first we want to get a list of all the installed applications on the machine, I just want the name of each package so we need to type the following at the PowerShell prompt. Of course make sure that you’re running PowerShell as an administrator.

Get-WmiObject -Class Win32_Product -Computer . | select-object Name | Export-CSV -path c:\ListSoftwareResults.csv -notypeinformation

This produces a handy little *.csv file with a list of all the installed applications

You can actually pull more information than just the name, it’s as simple as separating the properties with a comma

Get-WmiObject -Class Win32_Product -Computer . | select-object IdentifyingNumber,Name,Vendor,Version,Caption,LocalPackage | Export-CSV -path c:\ListSoftwareResults.csv -notypeinformation

From here we need to wrap the names of our software into this handy little script.

# Remove applications if installed.
$programs = @(
"Software Name 1",
"Software Name 2"
)
foreach($program in $programs){
Write-Host "Looking for $program."
$app = Get-WmiObject -Class Win32_Product ` -filter "Name = '$program'"
if ($app -ne $Null) {
Write-Host "Uninstalling $program."
$app.Uninstall()
Write-Host "$program uninstalled."
}
else
{
Write-Host "$program not found."
}
}

So for example, if we just wanted to uninstall Revit 2019 and it’s associated packages, we would use the following

# Remove Revit 2019 applications if installed.
$programs = @("Autodesk Revit 2019.2",
"Autodesk Revit 2019.1",
"Autodesk BIM 360 Revit 2019 Add-in 64 bit",
"Autodesk Revit Infraworks Updater",
"FormIt Converter For Revit 2019",
"Revit 2019",
"Autodesk Revit 2019 MEP Fabrication Configuration - Metric",
"Autodesk Advanced Material Library Base Resolution Image Library 2019",
"Batch Print for Autodesk Revit 2019",
"Autodesk Collaboration for Revit 2019",
"Autodesk Material Library Medium Resolution Image Library 2019",
"Worksharing Monitor for Autodesk Revit 2019",
"Autodesk Revit 2019 MEP Fabrication Configuration - Imperial",
"Autodesk Material Library Low Resolution Image Library 2019",
"Autodesk Revit Model Review 2019",
"Autodesk Advanced Material Library Low Resolution Image Library 2019",
"Autodesk Workflows 2019",
"Autodesk Material Library Base Resolution Image Library 2019",
"eTransmit for Autodesk Revit 2019",
"Autodesk Material Library 2019",
"Revit IFC 2019",
"Autodesk Revit Content Libraries 2019",
"BIM Interoperability Tools for Revit 2019",
"Autodesk Advanced Material Library Medium Resolution Image Library 2019")
foreach($program in $programs){
Write-Host "Looking for $program."
$app = Get-WmiObject -Class Win32_Product ` -filter "Name = '$program'"
if ($app -ne $Null) {
Write-Host "Uninstalling $program."
$app.Uninstall()
Write-Host "$program uninstalled."
}
else
{
Write-Host "$program not found."
}
}

Before you run any of these scripts though, you will need to change your execution policy. You can do this just for the current PowerShell instance rather than permanently allow scripts to be run on the system. To do this, it is as simple as

Set-ExecutionPolicy unrestricted

To run the script you need to include the full location of the script, even if you are running it from the current folder. For example

.\Uninstall_Revit2019.ps1

If you are specifically dealing with Revit software, you can take your uninstall a step further and clean out the associated files along with it. To do this, just add the following to the end of your script.

# Remove Revit 2019 user data.
Write-Host "Cleaning Revit 2019 User Data"
Write-Host "Backing up old user profile"
Move-Item -Path "C:\Users\$env:UserName\AppData\Roaming\Autodesk\Revit\Autodesk Revit 2019" -Destination "C:\Users\$env:UserName\AppData\Roaming\Autodesk\Revit\Autodesk Revit 2019_OLD"
Write-Host "Deleting temp files"
Remove-Item -Path $env:temp -Force -Recurse
Write-Host "Deleting user profile temp files"
Remove-Item -Path "C:\Users\$env:UserName\AppData\Local\Temp" -Force -Recurse
Write-Host "Deleting user profile Revit cache files"
Remove-Item -LiteralPath "C:\Users\$env:UserName\AppData\Local\Autodesk\Revit\Autodesk Revit 2019\CollaborationCache" -Force -Recurse
Write-Host "Deleting local machine Revit cache files"
Remove-Item "C:\Users\$env:UserName\AppData\Local\Autodesk\Revit\Autodesk Revit 2019\CollaborationCache" -Force -Recurse
Write-Host "Deleting Revit journal files"
Remove-Item -Path "C:\Users\$env:UserName\AppData\Local\Autodesk\Revit\Autodesk Revit 2019\Journals" -Force -Recurse

Just make sure that if you remove the user data as part of your script that you need to run it from that user’s profile, not from your administrator profile.

Removing Revit Line Patterns with C# Macros

Sometimes you might encounter an element within Revit giving you grief.

Recently for me it was a line pattern that had been transferred across from an old template. I didn’t want to spend the time to re-create all the old line patterns in a new template, but that time ended up being lost troubleshooting a fatal error.

Lucky for me that the line patterns were named so inconsistently in the old template or I wouldn’t have even discovered the problem; an unexpected benefit to others not being as meticulous as I can be I suppose.

One by one, I check each line pattern I had imported and discovered there was just one causing the problem. I couldn’t change the pattern definition. I couldn’t rename it. I couldn’t delete it. No matter what I did, Revit would crash.

An audit? No. What about a purge? Still no love.

So what do you do in this situation? I ended up turning to the API to obliterate the pesky line pattern. Dynamo is great but you can make a fantastic toolset based around C# macros and it’s a great way to learn the basic of coding with the API.

public void DeleteLinePattern()
{
//Get the current document
	
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
			
/*
my problem line pattern started with a certain prefix, 
so the method i am using is to search for line patterns with that prefix
update your code to prefix that you're looking for
*/
		
var collector = new FilteredElementCollector(doc)
	.OfClass(typeof(LinePatternElement))
	.Where(i => i.Name.StartsWith("PREFIX")).ToList();
			
	List<ElementId> ids = new List<ElementId>();

//Start the transaction that will modify your document
			
	using(Transaction t = new Transaction(doc,"Delete LinePatterns"))
		{
		t.Start();
			
		try
		{
			foreach (ElementId id in ids)
			{
				doc.Delete(id);
			}
		}
		catch (Exception)
				
	t.Commit();
	TaskDialog.Show("Delete LinePatterns","Deletion complete");
	}
}

I’m still waiting to hear back from Autodesk as to if I am still at risk of the model becoming corrupt in the future, but in the current state I’m pretty happy as I can continue working without issue.

As you can probably tell, this is quite a simple macro and the API is capable of doing much more. If you’re interested in learning the Revit API, check out these resources on the web

Harry Mattson’s Boost Your BIM
https://boostyourbim.wordpress.com/

Harry’s Udemy Courses
https://www.udemy.com/revitapi/
https://www.udemy.com/revitapi2/
https://www.udemy.com/revit-api-materials/

Danny Bentley’s Channel on Youtube
https://www.youtube.com/channel/UC1Dx-jGyRbvvHzZ8ZyGWF5w

Jeremy Tammik’s Building Coder
https://thebuildingcoder.typepad.com/

Revit API Docs Online
http://www.revitapidocs.com/

Autodesk “My First Revit Plugin”
https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/simplecontent/content/my-first-revit-plug-overview.html

Free C# Courses
https://www.learncs.org/
https://www.sololearn.com/Course/CSharp/

ItzAdam5X on Youtube for learning general C# concepts
https://www.youtube.com/channel/UC9pq4hre8qZI132O4cok5vA

Step by Step Guide – Creating My Iplex FWG Family in Revit

A lot of people ask me if I’ll give them my Iplex floor waste gully family. The answer is always no, not because I don’t want to share, but because I would rather people learn and understand for themselves rather than taking the easy way of “grabbing something from the internet”

I recorded a video on how to create the FWG a long time ago, but after a bit of back and forth discussion on Youtube, I have decided to pull that old video out and record some voice annotation so you can follow along.

I do apologise about the audio quality, I only had my junky work headset to record with.

 

Yes, this is how I spend my nights in hotels when travelling for work.

Fixing SP.Writer Run Time Error 70

If you’re like me, you haven’t used SP.Writer in a while but then if you’re also like me, you will at some point need to use it to generate a project customised shared parameters file. The first thing you do is pull out your trusty SP.Writer only to find that when you create a new parameter you get a run-time error 70.

If you hit the debug button, you will be taken to the mod_GUID module and the 4th line will be highlighted as the problem child.

The function used to create the GUID in SP.Writer was patched in the July 2017 security patches for Microsoft Office so if you’re up to date with your security patches, this is working as intended. That doesn’t help us in the slightest with creating shared parameters though, so what’s the solution?

First if you haven’t already done so, you’ll need to enable the developer toolbar in Excel which you can do by following the instructions over at the Microsoft website.

Once enabled, select Visual Basic from the developer tab on the ribbon. Alternatively you can use the ALT+F11 shortcut on your keyboard.

On the left hand side of your screen, you will see a window titled Project – VBA Project, scroll down until you find Modules. Right click on modules and from the contextual menu select Insert.. -> Module.

Copy and paste the following code into the new module.

Private Type GUID_TYPE
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type

Private Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" (guid As GUID_TYPE) As LongPtr
Private Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" (guid As GUID_TYPE, ByVal lpsGUID As LongPtr, ByVal cbMax As Long) As LongPtr

Function CreateGuidString()
Dim guid As GUID_TYPE
Dim sGUID As String
Dim retValue As LongPtr
Const guidLength As Long = 39 'registry GUID format with null terminator {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
retValue = CoCreateGuid(guid)
If retValue = 0 Then
sGUID = String$(guidLength, vbNullChar)
retValue = StringFromGUID2(guid, StrPtr(sGUID), guidLength)
If retValue = guidLength Then
CreateGuidString = sGUID
End If
End If
End Function

You can also rename the module, I renamed mine to mod_CoCreateGUID as this is will be method we’re using to generate the GUID. If you can’t see your properties window, press the F4 button.

 

Next, open the module mod_GUID and replace the existing code with the code below


Sub GetGUID()
Dim sGUID As String
sGUID = CreateGuidString()
wsData.Cells(LastRow + 1, 2) = "PARAM"
wsData.Cells(LastRow, 3) = Replace(Replace(sGUID, "{", ""), "}", "")

End Sub

 

The final step is to make a small change to the UserParameter form. In the VBA project, find the UserParameter form and right click and select View Code from the contextual menu.

Search for the code


'generate the GUID
GUID

and replace with the code


'generate the GUID
GetGUID

and that’s it! You’re done! You can now start creating shared parameters again. The GUID looks a little longer but it’s actually just the difference in length between upper and lower case with the font used.

C4R – I’m Still Missing Too Many Elements! (Part 2)

So last week you went through how to fix the ‘too many missing elements’ error, but after clearing your cache and sourcing replacement files you’re still seeing the error.

This means things are a little more serious, but there is still a potential solution.

Search the Journal for Missing Element Warnings

This time around, you need to review the journal file and look for the error specifically related to missing elements.

The journal file is located in %LOCALAPPDATA%\Autodesk\Revit\Autodesk Revit 201x\Journals you need to be opening the journal file that will have recorded the error. If there error has just occured, it will be recorded in your most recent journal file.

The easiest way to find the most recent file is to change your file sorting by date modified with the newest files at the top.

Open the journal in a text editor (Notepad or Notepad++) and search for the name of the model causing the problem.

This time you want to search for the text missing elem within your journal file.

If you can’t find the text in your most recent journal file, don’t panic! Using Notepad++ you can actually search for a string in all files located in a folder.

The search results will appear at the bottom of Notepad++ showing which files it has found the search string in.

You will soon have a list of elements that are missing from your model. The numbers represent the element ID of the missing elements.

Repairing the damage

To recover your file, locate the most recent backup file that contains the missing elements. You can restore backups from your local cache in the same way you have always been able to restore backups with Revit, it’s just now there is an extra step in finding the GUID of the RVT file before you can restore a backup.

Search for the name of your Revit file in the journal. This will give you the GUID for the project and file.

Once you have found the name of the model,take the model GUID and search for it in your CollaborationCache folder. You need to find the folder named <revit model GUID>_backup

From the Collaborate tab of the ribbon, select Restore Backup

Paste your backup folder path into the folder name location, it should follow the format C:\Users\<user name>\AppData\Local\Autodesk\Revit\Autodesk Revit 201x\CollaborationCache\<local cache id>\<project GUID>\<model GUID>_backup

Select the most recent backup and work your way back until you find a working copy.

Save the file in a new location. Don’t open the file just yet.

Browse to where you have saved your backup file and then open the file with the audit box checked.

Once you have successfully opened the model, using the Select by ID tool, search for the elements in your backup model.

Make sure that all the elements display correctly and work as expected.

The audited model becomes your new central model. You need to run through the process of loading the model onto C4R.

If anyone else is working on the project, their local cache will no longer synchronise with the newly created cloud model. Others in the team will need to rename or delete the folders in both their CollaborationCache and PacCache folders.

And that’s it! You’re done!

One final note..

When speaking with Autodesk, they advised that the best way to prevent this missing elements error is to always open your C4R models with the audit check box ticked. It’s a little bit of extra pain, but if it saves you from having to manually recover models, then happy days!

Final note for real this time..

In addition to the above, both Revit 2017 and 2018 have had updates released since I originally wrote this post. Autodesk’s urge anyone that is experiencing too many missing element errors to update their entire team to Revit 2017.2.2 and/or 2018.1.1. The patches for both fix the problems that cause these errors.

Aligning 3D Section Boxes

A quick one that came up today.. “Ryan, how do I align a 3D section box with an object that is not at right angles to the view?”

So what we’re talking about here is when we have a plan view that is rotated away from a straight up and down orientation.

 

When you create your default 3D view, it might end up looking something like this. You can rotate the section view but it’s a “near enough is good enough” approach and you can never truly align your section box.

 

That is unless you think about things a little differently. I’ve been preaching this method for quite a few years now but it seems be be a tool within Revit that not a lot of people know about.

Simply draw a 2D section that aligns with your building. If you need, you can draw detail lines to help in aligning your section, but Revit should automatically align with elements such as grids and walls in your model.

 

In your 3D view, right click on the view cube and then select Orient to View -> Section -> Section xx

And that’s it! You’re done!

C4R – So You’re Missing Many Elements? (Part 1)

If you’ve been working on C4R for even just a little while, you have probably seen the dreaded ‘too many missing elements’ error.

When you’re opening a Revit model, there could be more elements in the central model than there is in your local model. Usually Revit will synchronise the changes with your local and the endless grind of office life moves on. Sometimes though, things just don’t work out and you’re presented with this

Luckily, there are solutions to get your files working again.

Step 1 – Clearing the Local Cache

First, we need to clear the C4R local cache on your machine. You have two choices here, either blow away everything in the cache, or just try to clean out the file that you’re having issues with.

The Cache Location

The local cache is located in %LOCALAPPDATA%\Autodesk\Revit\Autodesk Revit 201x\CollaborationCache where Autodesk Revit 201x is the version of Revit you are using.

The files and folders in the local cache are coded with unique GUIDs.

The first folder is your local machine code

The second level of folders are the projects. The files within the folders are the models related to the project.

 

In addition to the collaboration cache, there is another folder named PacCache which is located in %LOCALAPPDATA%\Autodesk\Revit\PacCache

The PacCache is where all the delta file transfer information is cached for all the C4R models that you have worked on. The PacCache isn’t split into individual projects, or even individual versions of Revit. Everything is lumped in the same folder.

This is where you take the easy way, or the (not really very) hard way.

Method 1 – The easy way.
Just Kill Everything.

It’s listed first simply because it’s easiest. This should actually be the last method you try for clearing out your cache.

The easy way is to just wipe out everything in both the CollaborationCache and PacCache folders. With Revit closed, just browse to the folders in your favourite file explorer you can delete the contents of the PacCache folder and then move everything inside the CollaborationCache folder to another location. You can delete the contents of the CollaborationCache as well, however I highly recommend moving just in case you need to restore backups. That’s right! There are local backups of your C4R projects and they’re located in these folders.

Just keep in mind that when you do this, it means you need to cache all the files with your local machine from the cloud again, so it might take some time the next time you open up your models, especially if you have quite a number of projects and models hosted on the cloud.

Method 2 – Just The (not really very) hard way.
Removing a Single File.

The hard way is to remove just the single file giving you grief. It’s actually not very hard at all, you just have to poke around in the journal file to find the specific GUID for your file.

The journal file is located in %LOCALAPPDATA%\Autodesk\Revit\Autodesk Revit 201x\Journals if you have just experienced the error, then you will need the most recent journal file.

The easiest way to find the most recent file is to change your file sorting by date modified with the newest files at the top.

Open the journal in a text editor (Notepad or Notepad++) and search for the name of the model causing the problem.

Search for the name of your Revit file in the journal. This will give you the GUID for the project and file.

Once you have found the name of the model, you need to search for the GUID by copying and pasting it into the search box and move all the files and folders with that GUID from the local cache folders.

The files and folders will be located in both the CollaborationCache and the PacCache folders. You need to delete the PacCache folder, but for the CollaborationCache you should move the folder that has the same GUID of file that you’re having trouble with without the {curly braces} to another location. Again, you can delete everything but if you do you won’t be able to restore any backups after the files are deleted.

Method 3 – Definitely way harder than it needs to be.
Clearing out a single project.

Clearing the cache for an entire project is quite a bit more difficult due to the PacCache folder is not sorted into Revit versions or even into projects and you need to clear out the PacCache because otherwise you’re going to have a bad time.

If you really want to head down this path, the easiest way to find the project GUID in your journal file.

Get the complete local path to the project folder within your Collaboration cache folder. Move or delete the project from the CollaborationCache folder. Again the same warning applies if you choose to delete the contents of your CollaborationCache.

C:\Users\<user name>\AppData\Local\Autodesk\Revit\Autodesk Revit 201x\CollaborationCache\<your local machine code>\<project guid>

Open up Google Chrome (Edge and Internet Explorer will not work), copy the full folder location to your project and paste it into the address bar in Chrome prefixed with file://

What this does is it lists all the files from the CollaborationCache in your browser. Copy the GUID of each Revit file without the .rvt extension and search for those GUIDs in the PacCache folder.

Delete any results you find from the PacCache folder.

Step 2 – Re-populate your local cache

Method 1 – Just re-open from C4R

The first method is to simply open your file again from C4R. Revit will populate your local cache with brand new copies of the files that you’ve moved or deleted so you can start fresh.

From experience this works maybe 80% of the time.

Method 2 – ‘Borrow’ Someone Else’s File

Borrowing.. Stealing.. Fixing your local C4R cache. Call it what you will. This method only really works if someone else is also currently working on the model. What you’re trying to do here is get yourself the most recent working copy of the file so that you lose as little work as possible.

You need to find someone else that is working on the project without any missing element errors, find who has the most recent copy and take only RVT file only from their CollaborationCache, do not take anything from the PacCache.

From experience this works the other 18% of the time.