Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Viewport Types referenced by Schedules?

9 REPLIES 9
Reply
Message 1 of 10
bwinterscheidt
1103 Views, 9 Replies

Viewport Types referenced by Schedules?

I have a few rogue Viewport Types that cannot be purged, even when no views are placed on sheets, so not truly "used" but still referenced somewhere in the database.  I am trying to figure out exactly how they are referenced, and perhaps then change the reference to another type that I do want to keep, so these others can be purged.

 

I have been able to locate the offending Viewport Type definitions (Autodesk.Revit.DB.ElementType), go back to the model, and Select by Element ID.  Manually deleting these Viewport Types takes a large number of my *Schedules* (Autodesk.Revit.DB.ViewSchedule) with them, so I figure that the offending reference must be buried there somewhere.

 

But, the Autodesk.Revit.DB.ViewSchedule does not seem to have any properties/methods that reference these Viewport Types.

 

For comparison, when non-schedule views are placed on a sheet, an Autodesk.Revit.DB.Viewport is created, whose GetTypeId() method *will* return the Autodesk.Revit.DB.ElementType ID of the Viewport Type definition.

 

However, no Autodesk.Revit.DB.Viewport is created for schedule views; only an Autodesk.Revit.DB.ScheduleSheetInstance (and my issue persists with or without ScheduleSheetInstances in the model).

 

I seem to have quickly hit a dead end, and am unsure where to look from here.  Any thoughts?

Perhaps the API doesn't expose what I am trying to find?

9 REPLIES 9
Message 2 of 10

Dear bwinterscheidt,

 

I can indeed well imagine that the API does not provide much heklp on nthis issue. You could take a look at the object relationship analyser:

 

http://thebuildingcoder.typepad.com/blog/2010/03/object-relationships.html

 

Here are some examples of using it and the underlying technique:

 

http://thebuildingcoder.typepad.com/blog/2012/10/the-temporary-transaction-trick-for-gross-slab-data...

 

That might prove a useful tool to support your analysis. More than that, I really don't know. Sounds as if you have done a good job exploring already.

 

Good luck!

 

Cheers,



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 10

Did you ever find a solution for changing the Viewport Type associated with a schedule? I have 20 schedules that I will need to recreate if not. Ugg

Message 4 of 10

Has anyone found a solution to this?

Message 5 of 10

Provide a sample RVT project please.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 6 of 10

Thanks for replying! I can't make a sample file at the moment, because I'm not at the office, and only have access to Revit 2016 in viewer mode. But this can be tested with any schedule: is it possible to change the Viewport Type associated with a schedule?

Message 7 of 10

Ok if I'm getting you right then this code shall help:

#region Namespaces

using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;

using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;

using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;

using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;

#endregion

namespace RevitAddinCS2
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class ExtCmd : IExternalCommand
    {
        #region Cached Variables

        private static ExternalCommandData _cachedCmdData;

        public static UIApplication CachedUiApp
        {
            get
            {
                return _cachedCmdData.Application;
            }
        }

        public static RvtApplication CachedApp
        {
            get
            {
                return CachedUiApp.Application;
            }
        }

        public static RvtDocument CachedDoc
        {
            get
            {
                return CachedUiApp.ActiveUIDocument.Document;
            }
        }

        #endregion

        #region IExternalCommand Members

        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
        {
            _cachedCmdData = cmdData;

            try
            {
                FilteredElementCollector collector = new FilteredElementCollector(CachedDoc);
                collector.OfClass(typeof(Viewport));

                List<Viewport> viewports = collector.Cast<Viewport>().ToList();

                foreach (Viewport v in viewports)
                {
                    try
                    {
                        if (v.GetBoxOutline() == null)
                        {
                            CachedDoc.Delete(v.Id);
                            CachedDoc.Delete(v.GetTypeId());
                        }
                    }
                    catch (Exception ex)
                    {
                        CachedDoc.Delete(v.Id);
                        CachedDoc.Delete(v.GetTypeId());
                    }
                }

                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                return Result.Failed;
            }
        }

        #endregion

    }
}

I also prefer to have a sample RVT file to be ableto reproduce the error.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 8 of 10
ycui
in reply to: bwinterscheidt

Have you find a solution for the connection between Viewport Type and Schedule? I have the same problem now... Will be really appreciated if you could share any suggestion.

 

Thanks,

Yueying

Message 9 of 10
Mustafa.Salaheldin
in reply to: ycui

Have you tried my solution?

If you can supply a sample RVT file this will also help.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 10 of 10
ycui
in reply to: Mustafa.Salaheldin

Hi Mustafa.Salaheldin,

 

Thanks for the quick response. Could you please test the attached RVT?

 

If I delete the "No Title Copy1" Viewport type, it will delete my "FURNITURE SCHEDULE - A" schedule from my project. So I think there are some hidden connection between schedule and viewport type in Revit. If you can provide a way to change the schedule's "viewport type" to "Section 1", it also works for me.

 

Thanks so much for your help. Looking forward to your result.

 

delete viewport type error.png

 

Thanks,

Yueying

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community