-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
353 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.cs] | ||
|
||
# CS0162: Unreachable code detected | ||
dotnet_diagnostic.CS0162.severity = silent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Autodesk.Revit.DB; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BimIshou.Commands | ||
{ | ||
internal class Class1 | ||
{ | ||
Document doc; | ||
private void _editPlanRegion(Element planRegion, List<Line> polygon) | ||
{ | ||
using Transaction transTemp = new Transaction(doc, "temp"); | ||
transTemp.Start(); | ||
ICollection<ElementId> ids = doc.Delete(planRegion.Id); | ||
transTemp.RollBack(); | ||
|
||
//Get detailines of plan region | ||
List<DetailLine> detailLines = new List<DetailLine>(); | ||
foreach (ElementId id in ids) | ||
{ | ||
Element ele = doc.GetElement(id); | ||
if (ele is DetailLine) | ||
{ | ||
detailLines.Add(ele as DetailLine); | ||
} | ||
} | ||
|
||
using Transaction trans = new Transaction(doc); | ||
trans.Start("Change Plane Region"); | ||
|
||
//Get 1 detailine | ||
var firstDetailLine = detailLines.FirstOrDefault(); | ||
|
||
//Get z | ||
var z = firstDetailLine.GeometryCurve.GetEndPoint(0).Z; | ||
|
||
//Create new detail line | ||
foreach (var line in polygon) | ||
{ | ||
Transform transform = Transform.CreateTranslation(new XYZ(0, 0, 1)); | ||
var tf = Transform.Identity; | ||
var newID = ElementTransformUtils.CopyElement(doc, firstDetailLine.Id, XYZ.BasisY); | ||
var newLine = doc.GetElement(newID.First()) as DetailLine; | ||
var locCurve = newLine.Location as LocationCurve; | ||
locCurve.Curve = Line.CreateBound(transform.OfPoint(line.GetEndPoint(0)), transform.OfPoint(line.GetEndPoint(1))); | ||
} | ||
|
||
//Delete old detail lines | ||
doc.Delete(detailLines.Select(x => x.Id).ToList()); | ||
|
||
trans.Commit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using Autodesk.Revit.Attributes; | ||
using Autodesk.Revit.DB; | ||
using Autodesk.Revit.DB.Architecture; | ||
using Autodesk.Revit.UI; | ||
using BimIshou.Utils; | ||
using Nice3point.Revit.Toolkit.External; | ||
|
||
namespace BimIshou.Commands | ||
{ | ||
[Transaction(TransactionMode.Manual)] | ||
public class CreateCeilling : ExternalCommand | ||
{ | ||
RevitCommandEndedMonitor revitCommandEndedMonitor; | ||
IList<Reference> selectRooms; | ||
public List<ElementId> AddedElement { get; set; } = new List<ElementId>(); | ||
List<ElementId> Ceillings = new(); | ||
public override void Execute() | ||
{ | ||
try | ||
{ | ||
selectRooms = UiDocument.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element, new SelectionFilter(BuiltInCategory.OST_Rooms, true)); | ||
revitCommandEndedMonitor = new RevitCommandEndedMonitor(UiApplication); | ||
revitCommandEndedMonitor.CommandEnded += OnCommandEnded; | ||
Application.DocumentChanged += Application_DocumentChanged; | ||
UiApplication.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.AutomaticCeiling)); | ||
} | ||
catch (Autodesk.Revit.Exceptions.OperationCanceledException) | ||
{ | ||
return; | ||
} | ||
} | ||
private void Application_DocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e) | ||
{ | ||
AddedElement.AddRange(e.GetAddedElementIds()); | ||
} | ||
private void OnCommandEnded(object sender, EventArgs e) | ||
{ | ||
Application.DocumentChanged -= Application_DocumentChanged; | ||
revitCommandEndedMonitor.CommandEnded -= OnCommandEnded; | ||
foreach (var item in AddedElement) | ||
{ | ||
var ele = Document.GetElement(item); | ||
if (ele is Ceiling) | ||
{ | ||
Ceillings.Add(ele.Id); | ||
break; | ||
} | ||
} | ||
using (TransactionGroup tranG = new TransactionGroup(Document, "Auto Create Ceilling")) | ||
{ | ||
tranG.Start(); | ||
using (Transaction transs = new Transaction(Document, "test")) | ||
{ | ||
transs.Start(); | ||
var opt = new SpatialElementBoundaryOptions(); | ||
for (int i = 1; i < selectRooms.Count; i++) | ||
{ | ||
var tempCeilling = (Document.GetElement(Ceillings.FirstOrDefault())).Copy(XYZ.BasisY * 100 * i).FirstOrDefault(); | ||
Ceillings.Add(tempCeilling); | ||
} | ||
transs.Commit(); | ||
} | ||
for (int i = 0; i < selectRooms.Count; i++) | ||
{ | ||
ICollection<ElementId> ids; | ||
List<Line> polygon = new List<Line>(); | ||
Room room = Document.GetElement(selectRooms[i]) as Room; | ||
IList<IList<BoundarySegment>> loops = room.GetBoundarySegments(new SpatialElementBoundaryOptions()); | ||
foreach (IList<BoundarySegment> loop in loops) | ||
{ | ||
foreach (BoundarySegment seg in loop) | ||
{ | ||
Line line = seg.GetCurve() as Line; | ||
polygon.Add(line); | ||
} | ||
} | ||
using (Transaction transs = new Transaction(Document, "temp")) | ||
{ | ||
transs.Start(); | ||
ids = Document.Delete(Ceillings[i]); | ||
transs.RollBack(); | ||
} | ||
using (Transaction trans = new Transaction(Document, "Change Sketch Ceilling")) | ||
{ | ||
trans.Start(); | ||
EditCeilling(ids, polygon); | ||
trans.Commit(); | ||
} | ||
} | ||
tranG.Assimilate(); | ||
} | ||
} | ||
private void EditCeilling(ICollection<ElementId> elementIds, List<Line> polygon) | ||
{ | ||
List<ModelLine> detailLines = new List<ModelLine>(); | ||
foreach (ElementId id in elementIds) | ||
{ | ||
Element ele = Document.GetElement(id); | ||
if (ele is ModelLine) | ||
{ | ||
detailLines.Add(ele as ModelLine); | ||
} | ||
} | ||
var firstDetailLine = detailLines.FirstOrDefault(); | ||
foreach (var line in polygon) | ||
{ | ||
Transform transform = Transform.CreateTranslation(new XYZ(0, 0, 1)); | ||
var tf = Transform.Identity; | ||
var newID = ElementTransformUtils.CopyElement(Document, firstDetailLine.Id, XYZ.BasisY); | ||
var newLine = Document.GetElement(newID.First()) as ModelLine; | ||
var locCurve = newLine.Location as LocationCurve; | ||
locCurve.Curve = Line.CreateBound(transform.OfPoint(line.GetEndPoint(0)), transform.OfPoint(line.GetEndPoint(1))); | ||
} | ||
Document.Delete(detailLines.Select(x => x.Id).ToList()); | ||
} | ||
} | ||
} |
Oops, something went wrong.