Is there a way to create/remove view types through the API?
To clarify what I mean- manual process in Revit is here: (Create a view type)
You can create view types for plans, elevations, sections, 3D views, drafting views, legends, and schedules.
I haven't found reference in the API yet- but just started searching. Seems to be scarce and I am a little concerned as you cannot get view types thorugh a transfer project standards.
Solved! Go to Solution.
Solved by GallowayUS_com_RonAllen1. Go to Solution.
I think you can. How about this:
ElementId viewTypeId = FindViewTypes(level.Document, viewType).First().Id;
ViewPlan view = ViewPlan.Create(level.Document, viewTypeId, level.Id);
view.ViewName = viewName;
return view;
ViewType can be: ViewType.EngineeringPlan, there are some predefined:
public static IEnumerable<ViewFamilyType> FindViewTypes(Document doc, ViewType viewType)
{
IEnumerable<ViewFamilyType> ret = new FilteredElementCollector(doc)
.WherePasses(new ElementClassFilter(typeof(ViewFamilyType), false))
.Cast<ViewFamilyType>();
switch (viewType)
{
case ViewType.AreaPlan:
return ret.Where(e => e.ViewFamily == ViewFamily.AreaPlan);
case ViewType.CeilingPlan:
return ret.Where(e => e.ViewFamily == ViewFamily.CeilingPlan);
case ViewType.ColumnSchedule:
return ret.Where(e => e.ViewFamily == ViewFamily.GraphicalColumnSchedule); //?
case ViewType.CostReport:
return ret.Where(e => e.ViewFamily == ViewFamily.CostReport);
case ViewType.Detail:
return ret.Where(e => e.ViewFamily == ViewFamily.Detail);
case ViewType.DraftingView:
return ret.Where(e => e.ViewFamily == ViewFamily.Drafting);
case ViewType.DrawingSheet:
return ret.Where(e => e.ViewFamily == ViewFamily.Sheet);
case ViewType.Elevation:
return ret.Where(e => e.ViewFamily == ViewFamily.Elevation);
case ViewType.EngineeringPlan:
return ret.Where(e => e.ViewFamily == ViewFamily.StructuralPlan); //?
case ViewType.FloorPlan:
return ret.Where(e => e.ViewFamily == ViewFamily.FloorPlan);
//case ViewType.Internal:
// return ret.Where(e => e.ViewFamily == ViewFamily.Internal); //???
case ViewType.Legend:
return ret.Where(e => e.ViewFamily == ViewFamily.Legend);
case ViewType.LoadsReport:
return ret.Where(e => e.ViewFamily == ViewFamily.LoadsReport);
case ViewType.PanelSchedule:
return ret.Where(e => e.ViewFamily == ViewFamily.PanelSchedule);
case ViewType.PresureLossReport:
return ret.Where(e => e.ViewFamily == ViewFamily.PressureLossReport);
case ViewType.Rendering:
return ret.Where(e => e.ViewFamily == ViewFamily.ImageView); //?
//case ViewType.Report:
// return ret.Where(e => e.ViewFamily == ViewFamily.Report); //???
case ViewType.Schedule:
return ret.Where(e => e.ViewFamily == ViewFamily.Schedule);
case ViewType.Section:
return ret.Where(e => e.ViewFamily == ViewFamily.Section);
case ViewType.ThreeD:
return ret.Where(e => e.ViewFamily == ViewFamily.ThreeDimensional);
case ViewType.Undefined:
return ret.Where(e => e.ViewFamily == ViewFamily.Invalid); //?
case ViewType.Walkthrough:
return ret.Where(e => e.ViewFamily == ViewFamily.Walkthrough);
default:
return ret;
}
}
Let me know if we are heading the right direction.
regards
Christian
That covers the use of a view type to create a new view...
I need to basically View.ViewFamily.NEW "Architectural SiteView" to create a new PLAN.VIEW TYPE of "Architectural SiteView" or whatever the case may be.
This is huge for managing the views in project browser, establishing templates for newly created views by types, etc.
Haven't had a chance to poke around in the API yet and explore to see what is available bu the help files don't help on this one : )
Looking for Revit API help to create/modify a View //Type// name (from which views to place on sheets can be created). Not create a view from a view type.
Tough to spell this one out : )
Ron,
is this what we talk about:
???
ViewType is an Enum and I don't think you can add to this. The above is just duplicating a view and you can set some custom parameters.
This is what I use:
View v = doc.ActiveView; ViewDuplicateOption opt = new ViewDuplicateOption(); ElementId viewId = v.Duplicate(opt); View new_v = doc.GetElement(viewId) as View;
Let me know if we got any further.
regards
Christian
Perhaps you are thinking about something like what the attached images show? The first is of an add-in that tries to do the bulk of the tasks for creating views. This one creates floor plans and ceiling plans for standard MEP disciplines and adds view parameter values for two view parameters. It also can apply a view template. The second image show a add-in for deleting. They both work curiously in a flash.
Yeah it it is not looking good..
Attached the equivalent manual process: (PDF IS EASIER TO READ)
Necessity is the mother of invention. You are showing just five steps. I think I'm showing at least three more. Multiply that by the 270 views shown in the image. That's why we strive to get it all down to one button press. You are welcome to whatever I've got. Maybe 95% of all the various tasks you need to do are already figured out, perhaps not elegantly, but functional. It is just a matter of transmission. I have yet to figure out how to attach a file to a post. How did you attach a PDF? I was thinking maybe I could disguise a zip file as an image file and then attach. It's probably breaking the rules.
Dear Ron, Christian and Aksaks,
Thank you for your query and suggestions.
Ron, can you please confirm whether the suggestions resolve your need?
It looks and sounds to me as if they should.
Thank you.
Ron, you raised a new independent ADN case for this topic, 12126616 [Revit API help to create/modify a View //Type// by name (from which views to place on sheets can be created.)].
That is not necessary. Normally, as an ADN member, any thread you raise here in the forum should be automatically escalated to an ADN case if it remains unanswered for a certain amount of time. No idea why it failed in your case. Probably there is some mixup with different logins or email addresses or something.
You can escalate a thread to an ADN case manually as well (or I can, at least). I did so now for this thread, generating 12132187 [Create VIEW TYPES], so that the association between the thread and the ADN case is clear and visible to all. I closed the case 12126616 as a duplicate of that. I hope that makes sense.
@Anonymous, you can simply attach any files you like when editing your reply to a forum thread:
I hope this helps.
Best regards,
Jeremy
@Anonymous No, Sorry. I am not creating views. I am creating <View Types>
Views are created from <View Types>(that part I can do : )- but I need the prior steps in the API to create VIEW TYPES. Explicitly, I need to know if the API can replicate steps 4 and 5.
Your app could create the view types once the view types were established. I had this conversation about 4 years ago and the it is difficult to convey- hence the PDF.
I may create resort to a screen cast if the PDF is not sufficient.
Ron,
how about this as a start:
FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)); ViewFamilyType old_v = a.FirstOrDefault<Element>(e => e.Name.Equals("Lala")) as ViewFamilyType; ViewFamilyType new_v = old_v.Duplicate("test") as ViewFamilyType;
Didn't test it, but the code looked good in VS.
Hope it helps.
Christian
@jeremytammik Apologies- things sat quiet for a few days, and I am trying to stay ahead of the issue : )
Apologies to all on this thread- It is difficult to convey what I am after : ) - hoping the updated diagram helps (Attached a more readable PDF of it)
Explicitly I am looking to Replicate steps 4 and 5 in the API. Creating a <VIEW TYPE>.
The solutions offered so far show how to create <VIEWS> from <VIEW TYPES>, But I need to create the <VIEW TYPES>.
These are probably the most underused feature of Revit as most people are unaware it is there.
@Anonymous - That may be it!
I will have to check that out tonight and this weekend : )
Thnx!
Christian's steps look reasonable to me regarding view type.
You are not talking about view templates, are you, Ron? We do have an open wish list item concerning those.
Why don't Christian's steps work for you?
@jeremytammik Yes just saw that after my previous reply, looks very promising - may be exactly what I am after- with the class exposed I should be able to manipulate that- hopefully assign new View Templates (Unless that is the wish list item : ( and delete/purge as needed.
Delete should be easy as you can use the ElementId:
FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType));
ViewFamilyType old_v = a.FirstOrDefault<Element>(e => e.Name.Equals("Lala")) as ViewFamilyType; ViewFamilyType new_v = old_v.Duplicate("test") as ViewFamilyType; ICollection<ElementId> delIds = doc.Delete(old_v.Id);
Six years later returning to the same issue...
@Anonymous - That didn't work:
Warning: CPythonEvaluator.EvaluatePythonScript operation failed.
SyntaxError : ('invalid syntax', ('<string>', 12, 26, 'FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType));\n'))
py Code below:
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# The inputs to this node will be stored as a list in the IN variables.
strVIEW_TYPE_Name = IN[0]
strNew_VIEW_TYPE_Name = IN[1]
# Place your code below this line
FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType));
ViewFamilyType old_v = a.FirstOrDefault<Element>(e => e.Name.Equals(strVIEW_TYPE_Name)) as ViewFamilyType;
ViewFamilyType new_v = old_v.Duplicate(strNew_VIEW_TYPE_Name) as ViewFamilyType;
# Assign your output to the OUT variable.
OUT = new_v
Subsequent PY version here that references this doc also didn't work:
Hi, aren't you missing the RevitAPI reference?
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
Nope : (
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# The inputs to this node will be stored as a list in the IN variables.
strVIEW_TYPE_Name = IN[0]
strNew_VIEW_TYPE_Name = IN[1]
# Place your code below this line
FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType));
ViewFamilyType old_v = a.FirstOrDefault<Element>(e => e.Name.Equals(strVIEW_TYPE_Name)) as ViewFamilyType;
ViewFamilyType new_v = old_v.Duplicate(strNew_VIEW_TYPE_Name) as ViewFamilyType;
# Assign your output to the OUT variable.
OUT = new_v
Warning: CPythonEvaluator.EvaluatePythonScript operation failed.
SyntaxError : ('invalid syntax', ('<string>', 13, 26, 'FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType));\n'))
Can't find what you're looking for? Ask the community or share your knowledge.