Hi i need help coming up with a method to delete elevation views and elevation marker

Hi i need help coming up with a method to delete elevation views and elevation marker

allazaruszcheong_21
Enthusiast Enthusiast
336 Views
1 Reply
Message 1 of 2

Hi i need help coming up with a method to delete elevation views and elevation marker

allazaruszcheong_21
Enthusiast
Enthusiast

Currently i am creating elevation views by creating elevation markers
I have 1 button to create elevation markers -> creating elevation views
I have 1 button to export the view to png/jpg 

now i need a method to check if the elevation view exists, if it does, delete and create new ones, 
if not exist, create new ones

private void button33_Click(object sender, EventArgs e)
// This method exports the elevation views
{
UIDocument uidoc = uiapp2.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = uidoc.Document;

// Get the desktop path
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

// Specify the folder and file name
string folderName = "ETTV DATA";
string filePath = Path.Combine(desktopPath, folderName);

// Create the folder if it doesn't exist
Directory.CreateDirectory(Path.Combine(desktopPath, folderName));

//Root Path
string rootPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\ETTV DATA";

//Filter Elevation
List<Autodesk.Revit.DB.View> viewList = new FilteredElementCollector(doc)
.OfClass(typeof(Autodesk.Revit.DB.View))
.Cast<Autodesk.Revit.DB.View>()
.Where(x => x.ViewType.Equals(ViewType.Elevation))
.Where(x => !x.IsTemplate)
.ToList();

//Itterate Each View and Export as Image
foreach (Autodesk.Revit.DB.View view in viewList)
{

//Make Active View
uidoc.ActiveView = view;
//Export Image
PrintImage(doc, rootPath, view.Name);
}
}

public static void PrintImage(Autodesk.Revit.DB.Document doc, string rootPath, string viewName)
// This method is for the settings of the images' exported
{
// Export the image
ImageExportOptions options = new ImageExportOptions();
options.ZoomType = ZoomFitType.FitToPage;
options.PixelSize = 1080;
options.ImageResolution = ImageResolution.DPI_300;
options.HLRandWFViewsFileType = ImageFileType.PNG;
options.FilePath = $@"{rootPath}\{viewName}";
doc.ExportImage(options);
}

private ViewFamilyType GetViewFamilyType(Autodesk.Revit.DB.Document doc)
{
// Find the ViewFamilyType for Elevation views
ElementId viewFamilyTypeId = new FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
.Cast<ViewFamilyType>()
.FirstOrDefault(x => x.ViewFamily == ViewFamily.Elevation)
?.Id ?? ElementId.InvalidElementId;

return doc.GetElement(viewFamilyTypeId) as ViewFamilyType;
}

private void button34_Click(object sender, EventArgs e)
//This method creates the elevation views
{
UIDocument uidoc = uiapp2.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = uidoc.Document;

// Define the view directions and corresponding offsets
// Origin XYZ is 0,0,0 meaning that x, y, z
// only X and y are set as Z is upward/downward direction
// CropBox editting can be used later
XYZ north = new XYZ(0, 1, 0);
XYZ east = new XYZ(1, 0, 0);
XYZ south = new XYZ(0, -1, 0);
XYZ west = new XYZ(-1, 0, 0);
XYZ northeast = new XYZ(1, 1, 0).Normalize();
XYZ southeast = new XYZ(1, -1, 0).Normalize();
XYZ northwest = new XYZ(-1, 1, 0).Normalize();
XYZ southwest = new XYZ(-1, -1, 0).Normalize();

 

// Select off set distance,
// Select higher offsetDistance for bigger buildings
// for the elevation markers to appear outside the building.

// if the offset distance is high
// might not capture the elevation view

// however there is a fix
// if the offset distance is high
// the solution is to:
// Remove Crop View & Crop Region Visible

// this means to set(0)
// the same thing is also done

// under C# coding,
// to the "No Clip" "Parameter"

// under Revit Software
// Under "Properties" -> "No Clip"

double offsetDistance = 300;

// Start a transaction
using (Transaction t = new Transaction(doc, "Create Elevation Views"))
{
t.Start();

// Create an ElevationMarker for each direction at the specified offset
CreateElevationMarkerAtDirection(doc, north, offsetDistance, 0);
CreateElevationMarkerAtDirection(doc, northeast, offsetDistance, 1);
CreateElevationMarkerAtDirection(doc, east, offsetDistance, 2);
CreateElevationMarkerAtDirection(doc, southeast, offsetDistance, 3);
CreateElevationMarkerAtDirection(doc, south, offsetDistance, 4);
CreateElevationMarkerAtDirection(doc, southwest, offsetDistance, 5);
CreateElevationMarkerAtDirection(doc, west, offsetDistance, 6);
CreateElevationMarkerAtDirection(doc, northwest, offsetDistance, 7);

t.Commit();
}
}

private void CreateElevationMarkerAtDirection(Autodesk.Revit.DB.Document doc, XYZ direction, double offsetDistance, int index)
// Settings for elevation views created
{
// Calculate new marker location && it multiplies like a vector
XYZ newLocation = direction.Multiply(offsetDistance);

// Create the ElevationMarker at new
// Create a view at the marker
// https://maciejglowka.com/blog/creating-elevation-views-with-api/#:~:text=ElevationMarker%20marker%20...
// by Maciej Główka
ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, GetViewFamilyType(doc).Id, newLocation, 100);
ViewSection elevationView = marker.CreateElevation(doc, doc.ActiveView.Id, index % 4); // Use modulo to ensure index is within 0-3

//to name the views
//after creation
// using elevationView.Name = $"Elevation {direction.ToString()}";

//method to rotate
/*
https://forums.autodesk.com/t5/revit-api-forum/elevationmarker-not-rotating/m-p/7114473/highlight/tr...
by mehdi.blanchard
currently rotates by ANTICLOCKWISE
double rotation = Math.PI / 2;
Line lineAsAxis = Line.CreateBound(new XYZ(newLocation.X, newLocation.Y, newLocation.Z), new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));
marker.Location.Rotate(lineAsAxis, rotation);
*/

//NORTH
if (index == 0)
{
elevationView.Name = $"ETTV ELEVATION North";
double rotation = Math.PI / 2;
Line lineAsAxis = Line.CreateBound(
new XYZ(newLocation.X, newLocation.Y, newLocation.Z),
new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));


//Basically creates a "Line" at the new location
//The x and y location stay the same but Z changes
// This creates a length "10" line in the Z axis
// the element at NORTH is then rotated among the axis.

marker.Location.Rotate(lineAsAxis, rotation);
}

//NORTHEAST
else if (index == 1)
{
elevationView.Name = $"ETTV ELEVATION NorthEast";
double rotation = 3 * Math.PI / 4;
Line lineAsAxis = Line.CreateBound(
new XYZ(newLocation.X, newLocation.Y, newLocation.Z),
new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));


//Basically creates a "Line" at the new location
//The x and y location stay the same but Z changes
// This creates a length "10" line in the Z axis
// the element at NORTHEAST is then rotated among the axis.


marker.Location.Rotate(lineAsAxis, rotation);
}

//EAST
else if (index == 2)
{
elevationView.Name = $"ETTV ELEVATION East";
double rotation = Math.PI;
Line lineAsAxis = Line.CreateBound(
new XYZ(newLocation.X, newLocation.Y, newLocation.Z),
new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));


//Basically creates a "Line" at the new location
//The x and y location stay the same but Z changes
// This creates a length "10" line in the Z axis
// the element at EAST is then rotated among the axis.


marker.Location.Rotate(lineAsAxis, rotation);
}

//SOUTHEAST
else if (index == 3)
{
elevationView.Name = $"ETTV ELEVATION SouthEast";
double rotation = 5 * Math.PI / 4;
Line lineAsAxis = Line.CreateBound(
new XYZ(newLocation.X, newLocation.Y, newLocation.Z),
new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));


//Basically creates a "Line" at the new location
//The x and y location stay the same but Z changes
// This creates a length "10" line in the Z axis
// the element at SOUTHEAST is then rotated among the axis.


marker.Location.Rotate(lineAsAxis, rotation);
}

//SOUTH
else if (index == 4)
{
elevationView.Name = $"ETTV ELEVATION South";
double rotation = 3 * Math.PI / 2;
Line lineAsAxis = Line.CreateBound(
new XYZ(newLocation.X, newLocation.Y, newLocation.Z),
new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));


//Basically creates a "Line" at the new location
//The x and y location stay the same but Z changes
// This creates a length "10" line in the Z axis
// the element at SOUTH is then rotated among the axis.


marker.Location.Rotate(lineAsAxis, rotation);
}

//SOUTHWEST
else if (index == 5)
{
elevationView.Name = $"ETTV ELEVATION SouthWest";
double rotation = 7 * Math.PI / 4;
Line lineAsAxis = Line.CreateBound(
new XYZ(newLocation.X, newLocation.Y, newLocation.Z),
new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));


//Basically creates a "Line" at the new location
//The x and y location stay the same but Z changes
// This creates a length "10" line in the Z axis
// the element at SOUTHWEST is then rotated among the axis.


marker.Location.Rotate(lineAsAxis, rotation);
}

//WEST
else if (index == 6)
{
elevationView.Name = $"ETTV ELEVATION West";
double rotation = 0;
Line lineAsAxis = Line.CreateBound(
new XYZ(newLocation.X, newLocation.Y, newLocation.Z),
new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));


//Basically creates a "Line" at the new location
//The x and y location stay the same but Z changes
// This creates a length "10" line in the Z axis
// the element at WEST is then rotated among the axis.


marker.Location.Rotate(lineAsAxis, rotation);
}

//NORTHWEST
else if (index == 7)
{
elevationView.Name = $"ETTV ELEVATION NorthWest";
double rotation = Math.PI / 4;
Line lineAsAxis = Line.CreateBound(
new XYZ(newLocation.X, newLocation.Y, newLocation.Z),
new XYZ(newLocation.X, newLocation.Y, newLocation.Z + 10));


//Basically creates a "Line" at the new location
//The x and y location stay the same but Z changes
// This creates a length "10" line in the Z axis
// the element at NORTHWEST is then rotated among the axis.


marker.Location.Rotate(lineAsAxis, rotation);
}

 

//need to add "noclip" to "Far Clipping" in Revit
// this involves basically "changing" the property
//https://forums.autodesk.com/t5/revit-api-forum/how-to-modify-the-far-clip-offset-of-a-view-section/t...
// by mwilson1

Parameter farClipChanger = elevationView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR);
if (farClipChanger != null && farClipChanger.StorageType == StorageType.Integer)
{
farClipChanger.Set(0);

//Set the parameter to "0'
// meaning Extents -> Far Clipping -> no clip
}

Parameter cropViewParameter2 = elevationView.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION);
if (cropViewParameter2 != null && cropViewParameter2.StorageType == StorageType.Integer)
{
cropViewParameter2.Set(0);

//Set the parameter to "0'
// meaning Extents -> no Crop View
}

Parameter cropRegionVisible = elevationView.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION_VISIBLE);
if (cropRegionVisible != null && cropRegionVisible.StorageType == StorageType.Integer)
{
cropRegionVisible.Set(0);

//Set the parameter to "0'
// meaning Extents -> no Crop Region Visible

}

 

// this sets the views to auto zoom with no crop

/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
* Next step is to do coloring
* Currently the wanted process by Saw Tun:
*
* If there is 8 wall types, there shld be 8 colors.
* At elevation view, the same wall type must have the same color.
* To identify the type need to gather all existing EXTERNAL WALL TYPES
* Assign a color to a wall type
* then print (done)
*
* Coding Steps:
* 1. Develop a sorting system that retrieves EXTERNAL WALLS ONLY
* 2. Sort the EXTERNAL WALLS by UNIQUE wall types
* 3. Use comment parameter to "MARK" it, subsequent code will then identify it by code to color
* 4. Figure out how to V/G override, already have the method found in RevitAPIDocs (done)
* 5. Print (done)
*
*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// https://www.youtube.com/watch?v=3kfBpn2kSLw&ab_channel=RevitPure
// First step to Get into Graphic Display Options,
//
// Activate || set Silhouettes
// Option 3 or Option 4 -> 0.35 or 0.5
//
// Activate Cast Shadow
// Set Shadow Intesity at 15 || Default setting usually too dark
//
// Activate Depth Cueing
// Preference settings
//
// DO NOT ACTIVATE LINEWORKS, IT IS NOT COMPATIBLE WITH DEPTH CUEING
// DO NOT ACTIVATE LINEWORKS, IT IS NOT COMPATIBLE WITH DEPTH CUEING
// DO NOT ACTIVATE LINEWORKS, IT IS NOT COMPATIBLE WITH DEPTH CUEING
//
// Set Consistent Colors || Set Realistic

Parameter graphicsStyle = elevationView.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE);
if (graphicsStyle != null && graphicsStyle.StorageType == StorageType.Integer)
{
// Options:
// 1-Wireframe
// 2-Hidden Line
// 3-Shaded
// 4-Consistent colors
// 5-Realistic
graphicsStyle.Set(5);
}
// Set the parameter to the settings
}

0 Likes
Accepted solutions (1)
337 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni
Accepted solution

Determine the elevation views and elevation marker element ids and call Document.Delete:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open