Skip to content

Commit

Permalink
update create sections
Browse files Browse the repository at this point in the history
  • Loading branch information
GLOBAL\Giovanni.Brogiolo committed Apr 14, 2021
1 parent be0ea55 commit 5427e73
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 47 deletions.
20 changes: 16 additions & 4 deletions ReviTab/Buttons Tools/CreateSections.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
Expand Down Expand Up @@ -35,17 +36,28 @@ public Result Execute(
}

ViewSection vs = null;

using (var form = new FormCreateSections())

ICollection<ViewFamilyType> allSectionTypes = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast<ViewFamilyType>().Where<ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily).ToList();

using (var form = new FormCreateSections())
{

form.SectionTypes = allSectionTypes;

form.ShowDialog();

if (form.DialogResult == winForm.DialogResult.Cancel)
{
return Result.Cancelled;
}

ViewFamilyType vft = Helpers.viewFamilyType(doc);

if (form.chosenSection != null)
{
vft = form.chosenSection as ViewFamilyType;
}

using (Transaction tx = new Transaction(doc))
{
try
Expand All @@ -56,15 +68,15 @@ public Result Execute(

foreach (Element e in myElements)
{
vs = Helpers.CreateSectionParallel(doc, uidoc, e, form.sectionPositionOffset, form.farClipOffset, form.bottomLevel, form.topLevel, form.columnParameter, form.flipDirection);
vs = Helpers.CreateSectionParallel(doc, uidoc, e, form.sectionPositionOffset, form.farClipOffset, form.bottomLevel, form.topLevel, form.columnParameter, form.flipDirection, form.prefixText, vft);
s += $"{vs.Name}\n";
}

else
{
foreach (Element e in myElements)
{
Helpers.CreateSectionPerpendicular(doc, uidoc, e);
Helpers.CreateSectionPerpendicular(doc, uidoc, e, form.columnParameter, form.prefixText);
s += 1;
}
}
Expand Down
19 changes: 14 additions & 5 deletions ReviTab/Commands/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public static string GetCurrentPrintSetup(Document doc)
/// </summary>
/// <param name="doc"></param>
/// <returns></returns>
private static ViewFamilyType viewFamilyType(Document doc)
public static ViewFamilyType viewFamilyType(Document doc)
{
ViewFamilyType vft = new FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
Expand Down Expand Up @@ -301,7 +301,7 @@ public static View SectionElementToView(List<Autodesk.Revit.DB.View> _views, Ele
/// <param name="doc"></param>
/// <param name="uidoc"></param>
/// <param name="ele"></param>
public static void CreateSectionPerpendicular(Document doc, UIDocument uidoc, Element ele)
public static void CreateSectionPerpendicular(Document doc, UIDocument uidoc, Element ele, string eleParameter, string prefixText)
{
// My library

Expand Down Expand Up @@ -356,6 +356,15 @@ public static void CreateSectionPerpendicular(Document doc, UIDocument uidoc, El
ViewSection vs = null;

vs = ViewSection.CreateSection(doc, vft.Id, sectionBox);

try
{
vs.Name = $"{prefixText} {ele.LookupParameter(eleParameter).AsString()}";
}
catch {

}

}

/// <summary>
Expand All @@ -368,7 +377,7 @@ public static void CreateSectionPerpendicular(Document doc, UIDocument uidoc, El
/// <param name="farClipOffset"></param>
/// <param name="bottomLevel"></param>
/// <param name="topLevel"></param>
public static ViewSection CreateSectionParallel(Document doc, UIDocument uidoc, Element ele, double sectionPosition, double farClipOffset, double bottomLevel, double topLevel, string eleParameter, bool flipDirection)
public static ViewSection CreateSectionParallel(Document doc, UIDocument uidoc, Element ele, double sectionPosition, double farClipOffset, double bottomLevel, double topLevel, string eleParameter, bool flipDirection, string prefixName, ViewFamilyType vft)
{

Element lineBasedElement = ele;
Expand Down Expand Up @@ -429,14 +438,14 @@ public static ViewSection CreateSectionParallel(Document doc, UIDocument uidoc,
sectionBox.Min = min; // scope box start
sectionBox.Max = max; // scope box end

ViewFamilyType vft = viewFamilyType(doc);
// ViewFamilyType vft = viewFamilyType(doc);
ViewSection vs = null;

vs = ViewSection.CreateSection(doc, vft.Id, sectionBox);

try
{
vs.Name = $"Section {ele.LookupParameter(eleParameter).AsString()}";
vs.Name = $"{prefixName} {ele.LookupParameter(eleParameter).AsString()}";
}
catch
{
Expand Down
13 changes: 10 additions & 3 deletions ReviTab/Forms/FormCreateSections.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

Expand All @@ -16,7 +17,9 @@ public partial class FormCreateSections : Form
public double topLevel {get;set;}
public bool flipDirection {get;set;}
public string columnParameter { get; set; }

public string prefixText { get; set; }
public Autodesk.Revit.DB.Element chosenSection { get; set; }
public ICollection<Autodesk.Revit.DB.ViewFamilyType> SectionTypes { get; set; }
public FormCreateSections()
{
//
Expand Down Expand Up @@ -44,8 +47,11 @@ void Ok_buttonClick(object sender, EventArgs e)
bottomLevel = Int16.Parse(bottomLevelTxt.Text)/304.8*1000;
topLevel = Int16.Parse(topLevelTxt.Text)/304.8*1000;
columnParameter = textBoxParameter.Text;
prefixText = textBoxPrefix.Text;
chosenSection = (Autodesk.Revit.DB.Element)comboBoxSectionTypes.SelectedItem;

}

void CheckBoxLong_Click(object sender, EventArgs e)
{
checkBoxCross.Checked = false;
Expand All @@ -61,7 +67,8 @@ void CheckBoxCross_Click(object sender, EventArgs e)

void Form1Load(object sender, EventArgs e)
{

comboBoxSectionTypes.DataSource = SectionTypes;
comboBoxSectionTypes.DisplayMember = "Name";
}

}
Expand Down
129 changes: 94 additions & 35 deletions ReviTab/Forms/FormCreateSections.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5427e73

Please sign in to comment.