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: 

Create VIEW TYPES

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
GallowayUS_com_RonAllen1
8286 Views, 25 Replies

Create VIEW TYPES

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.

  1. Open a view for which you want to create a view type, or click the view name in the Project Browser.
  2. In the Properties palette, click Edit Type.
  3. In the Type Properties dialog, click Duplicate.
  4. Enter a name for the new view type and click OK.
  5. In the Type Properties dialog for the new view type, specify a value for each Graphics parameter.

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.

 @jeremytammik 

Ron Allen
Ware Malcomb Bim
25 REPLIES 25
Message 2 of 26
Anonymous

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

Message 3 of 26
GallowayUS_com_RonAllen1
in reply to: Anonymous

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 : )

Ron Allen
Ware Malcomb Bim
Message 4 of 26
GallowayUS_com_RonAllen1
in reply to: Anonymous

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 Allen
Ware Malcomb Bim
Message 5 of 26
Anonymous

Ron,

 

is this what we talk about:

 

https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2016/EN...

 

???

 

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

Message 6 of 26
Anonymous

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.

 

ViewMakerA.PNG

ViewMatic.PNG

Message 7 of 26
GallowayUS_com_RonAllen1
in reply to: Anonymous

Yeah it it is not looking good..

 

Attached the equivalent manual process: (PDF IS EASIER TO READ)

 

API Create View Type.png

 

 

Ron Allen
Ware Malcomb Bim
Message 8 of 26
Anonymous

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.

Message 9 of 26

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:

 

revit_api_forum_attachment2.png

 

 

 

 

I hope this helps.

 

Best regards,

 

Jeremy

 



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

Message 10 of 26
GallowayUS_com_RonAllen1
in reply to: Anonymous

@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 Allen
Ware Malcomb Bim
Message 11 of 26
Anonymous

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

Message 12 of 26

@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.

 

API Create View Type.v2.png

Ron Allen
Ware Malcomb Bim
Message 13 of 26
GallowayUS_com_RonAllen1
in reply to: Anonymous

@Anonymous - That may be it! 

 

I will have to check that out tonight and this weekend : )

Thnx!

Ron Allen
Ware Malcomb Bim
Message 14 of 26

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?



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

Message 15 of 26
Anonymous

Hopefully. Have a good weekend.

Message 16 of 26

@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.

Ron Allen
Ware Malcomb Bim
Message 17 of 26
Anonymous

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);
Message 18 of 26
GallowayUS_com_RonAllen1
in reply to: Anonymous

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:

https://mgfx.co.za/blog/building-architectural-design/revit-view-type-creation-using-excel-with-dynamo-and-python/

Ron Allen
Ware Malcomb Bim
Message 19 of 26

Hi, aren't you missing the RevitAPI reference?

 

 

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

 

 

Message 20 of 26

Nope : (

 

RonAllen_WareMalcombcom_0-1663265683610.png

 

 

 

# 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'))

 

 

Ron Allen
Ware Malcomb Bim

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

Post to forums  

Rail Community


Autodesk Design & Make Report