// // (C) Copyright 2003-2023 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. // using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Revit.SDK.Samples.DisallowEndWrapping.CS { class UnownedDisposable where T : IDisposable { private readonly T _value; public UnownedDisposable(T value) { _value = value; } public T Deref() => _value; } /// /// UI to display the wall locations' end wrapping information /// public partial class WallInformationForm : System.Windows.Forms.Form { UnownedDisposable curWall = null; /// /// constructor /// public WallInformationForm() { InitializeComponent(); } /// /// constructor /// /// public WallInformationForm(Wall wall) { InitializeComponent(); updateDisplay(wall); } /// /// display data on the list /// public void updateDisplay(Wall wall) { locationsView.Items.Clear(); if (wall == null) return; curWall = new UnownedDisposable(wall); List wrappingAllowData = new List(); if (wall != null) { var locations = wall.GetValidWrappingLocationIndices(); foreach (var location in locations) { AllowData data = new AllowData(); data.location = location; data.allowed = wall.IsWrappingAtLocationAllowed(location); data.parameter = wall.GetWrappingLocationAsCurveParameter(location); data.faces = wall.GetWrappingLocationAsReferences(location); wrappingAllowData.Add(data); } } foreach (var allowdata in wrappingAllowData) { ListViewItem tmpItem = new ListViewItem(); tmpItem.SubItems.Add(allowdata.location.ToString()); tmpItem.SubItems.Add(allowdata.allowed.ToString()); tmpItem.SubItems.Add(allowdata.parameter.ToString()); tmpItem.SubItems.Add(getFaceTags(allowdata.faces)); tmpItem.SubItems.RemoveAt(0); locationsView.Items.Add(tmpItem); } locationsView.Update(); } private string getFaceTags(IList refs) { string str = ""; foreach(var refface in refs) { var face = curWall.Deref().GetGeometryObjectFromReference(refface) as Face; if (face != null) str += face.Id + " "; } return str; } private int getInputLocation() { int location = -1; bool convert = int.TryParse(textBox1.Text, out location); if (!convert) { Autodesk.Revit.UI.TaskDialog.Show("Revit", "please input a valid number"); return -1; } return location; } private void startTransactionDoSomething(Action f, string transName) { Document doc = curWall.Deref().Document; try { using (Transaction trans = new Transaction(doc, transName)) { trans.Start(); f(0); trans.Commit(); } } catch (Exception ex) { Autodesk.Revit.UI.TaskDialog.Show("Revit", "exception happens: " + ex.ToString()); } } private void button0_Click(object sender, EventArgs e) { if (curWall.Deref() == null) return; int location = getInputLocation(); if (location == -1) return; startTransactionDoSomething((int i) => { curWall.Deref().AllowWrappingAtLocation(location); }, "Revit.SDK.Samples.AllowEndWrapping"); updateDisplay(curWall.Deref()); } private void button1_Click(object sender, EventArgs e) { if (curWall.Deref() == null) return; int location = getInputLocation(); if (location == -1) return; startTransactionDoSomething((int i) => { curWall.Deref().DisallowWrappingAtLocation(location); }, "Revit.SDK.Samples.DisallowEndWrapping"); updateDisplay(curWall.Deref()); } } /// /// /// public class AllowData { /// /// location number /// public int location; /// /// is this location's end wrapping allowed /// public bool allowed; /// /// location's raw parameter on wall's curve /// public double parameter; /// /// related faces at the location /// public IList faces; } }