Create views dynamically

Create views dynamically

Anonymous
Not applicable
798 Views
3 Replies
Message 1 of 4

Create views dynamically

Anonymous
Not applicable

I am having trouble changing the scale (width) of my view label. Is there a method/property that I can change the scale and location in relation to the view? I feel like I am missing something here.

 

 

// Start "create view" transation
_transaction.Start("View Creation");

// Create views of assembly
ElementId titleBlockId = new FilteredElementCollector(_doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_TitleBlocks).Cast<FamilySymbol>().FirstOrDefault().Id;

// Create sheet
ViewSheet viewSheet = AssemblyViewUtils.CreateSheet(_doc, _assemblyInstance.Id, titleBlockId);

// Create isometric view
View3D view3d = AssemblyViewUtils.Create3DOrthographic(_doc, _assemblyInstance.Id);
view3d.DetailLevel = ViewDetailLevel.Fine;
view3d.Scale = 10;

///////////////////////////////
// Create orthographic views //
///////////////////////////////
// Top Elevation
ViewSection elevationTop = AssemblyViewUtils.CreateDetailSection(_doc, _assemblyInstance.Id, AssemblyDetailViewOrientation.ElevationTop);
elevationTop.DetailLevel = ViewDetailLevel.Fine;
elevationTop.Scale = 10;

// Left Elevation
ViewSection elevationLeft = AssemblyViewUtils.CreateDetailSection(_doc, _assemblyInstance.Id, AssemblyDetailViewOrientation.ElevationLeft);
elevationLeft.DetailLevel = ViewDetailLevel.Fine;
elevationLeft.Scale = 10;

// Front Elevation
ViewSection elevationFront = AssemblyViewUtils.CreateDetailSection(_doc, _assemblyInstance.Id, AssemblyDetailViewOrientation.ElevationFront);
elevationFront.DetailLevel = ViewDetailLevel.Fine;
elevationFront.Scale = 10;

// Right Elevation
ViewSection elevationRight = AssemblyViewUtils.CreateDetailSection(_doc, _assemblyInstance.Id, AssemblyDetailViewOrientation.ElevationRight);
elevationRight.DetailLevel = ViewDetailLevel.Fine;
elevationRight.Scale = 10;

// Locate all views on sheet at once
Viewport.Create(_doc, viewSheet.Id, view3d.Id, new XYZ(1.751.750));
Viewport.Create(_doc, viewSheet.Id, elevationTop.Id, new XYZ(11.50));
Viewport.Create(_doc, viewSheet.Id, elevationLeft.Id, new XYZ(0.510));
Viewport.Create(_doc, viewSheet.Id, elevationFront.Id, new XYZ(110));
Viewport.Create(_doc, viewSheet.Id, elevationRight.Id, new XYZ(1.510));

// Create material takeoff
ViewSchedule materialTakeoff = AssemblyViewUtils.CreateMaterialTakeoff(_doc, _assemblyInstance.Id );
ScheduleSheetInstance.Create(_doc, viewSheet.Id, materialTakeoff.Id, new XYZ(2.251.50));

// Create parts list (schedule)
ViewSchedule partList = AssemblyViewUtils.CreatePartList(_doc, _assemblyInstance.Id);
ScheduleSheetInstance.Create(_doc, viewSheet.Id, partList.Id, new XYZ(2.2520));

// Close "create view" transation
_transaction.Commit();

 

 

0 Likes
799 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

I would also like to hide the section view lines that create the adjacent views. This is what my view looks like right now.

 

view scale off.png

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi Jeremer,

 

I am not sure if I got it right or not. but if you want to hide the section view lines in your assembly views, I recommend to first create a view template and hide the sections in that template then assign this view template to your assembly view using (for example):

 

elevationfront.ViewTemplateId = my_view_template.Id

 

for finding the view template that you have defined by API, filter all the views:

 

view_collector = FilteredElementCollector(doc).OfClass(View)

for v in view_collector:

      if v.IsTemplate == True and v.Name == 'your view template name':

               my_view_template = v

 

and for changing the scale or anything about your viewport, I suggest that you first create a viewport type that meets your needs and then assign the viewport of your view using Revit API:

 

viewport.ChangeTypeId(my_defined_view_port.Id)

 

for filtering your defined viewport, filter through ElementType and use FamilyName and GetParameters to find your desired viewport.

 

Regards,

Dave

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Dave,

 

Thank you for the info, but I was hoping to not set up a view template to handle this because I want all of it to be dynamically created every time (at some point with user input). I'm sure I can hide the section view lines if I use a view template but even if I do, how do I change the default width of the view label line, below each view?

 

view label lines.png

0 Likes