-
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
1 parent
5545133
commit dbfe47b
Showing
14 changed files
with
215 additions
and
122 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
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 |
---|---|---|
@@ -1,103 +1,91 @@ | ||
using Autodesk.Revit.Attributes; | ||
using Autodesk.Revit.DB; | ||
using Autodesk.Revit.DB.ExtensibleStorage; | ||
using Autodesk.Revit.DB.Mechanical; | ||
using Autodesk.Revit.UI.Selection; | ||
using Autodesk.Revit.UI; | ||
using Nice3point.Revit.Toolkit.External; | ||
using Autodesk.Revit.ApplicationServices; | ||
using System.Diagnostics; | ||
using BimIshou.Utils; | ||
|
||
namespace RevitAddin | ||
{ | ||
[Transaction(TransactionMode.Manual)] | ||
public class TestCreateSchema : ExternalCommand | ||
public class Test : ExternalCommand | ||
{ | ||
public override void Execute() | ||
{ | ||
} } | ||
|
||
[Transaction(TransactionMode.Manual)] | ||
public class SplitDuctV1Cmd : IExternalCommand | ||
{ | ||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) | ||
{ | ||
UIApplication uiapp = commandData.Application; | ||
UIDocument uidoc = uiapp.ActiveUIDocument; | ||
Application app = uiapp.Application; | ||
Document doc = uidoc.Document; | ||
try | ||
var pickob = UiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new SelectionFilter(BuiltInCategory.OST_Roofs)); | ||
var symbol = Document.GetElement(new ElementId(305481)) as FamilySymbol; | ||
var roof = Document.GetElement(pickob) as FootPrintRoof; | ||
var solid = roof.GetSolidsInstance(); | ||
foreach (var sol in solid) | ||
{ | ||
List<Element> element = new List<Element>(); | ||
List<Connector> connectors = new List<Connector>(); | ||
List<Reference> references = uidoc.Selection.PickObjects(ObjectType.Element).ToList(); | ||
foreach (Reference elementrReference in references) | ||
var faces = GetTopFaces(sol); | ||
using (Transaction tran = new Transaction(Document, "new tran")) | ||
{ | ||
Element elementDuct = doc.GetElement(elementrReference); | ||
element.Add(elementDuct); | ||
} | ||
double Lengthft = 1110 / 304.8; | ||
Duct duct1 = null; | ||
Duct duct2 = null; | ||
Duct ductmain = null; | ||
foreach (Element ductElement in element) | ||
{ | ||
ductmain = ductElement as Duct; | ||
Curve curve = ((LocationCurve)ductmain.Location).Curve; | ||
using (Transaction t = new Transaction(doc, "Chia Duct test")) | ||
DiscardWarning(tran); | ||
tran.Start(); | ||
foreach (Face face in faces) | ||
{ | ||
t.Start(); | ||
while (curve.Length > Lengthft) | ||
{ | ||
XYZ startPoint = curve.GetEndPoint(0); | ||
XYZ endPoint = curve.GetEndPoint(1); | ||
XYZ direction = endPoint.Subtract(startPoint).Normalize(); | ||
XYZ breakPoint = startPoint.Add(direction.Multiply(Lengthft)); | ||
|
||
ElementId newductId = MechanicalUtils.BreakCurve(doc, ductmain.Id, breakPoint); | ||
duct1 = ductElement as Duct; | ||
duct2 = doc.GetElement(newductId) as Duct; | ||
curve = ((LocationCurve)ductElement.Location).Curve; | ||
if (curve.Length < Lengthft) | ||
{ | ||
break; | ||
} | ||
doc.Regenerate(); | ||
|
||
var unusedConnectors1 = duct1.ConnectorManager.UnusedConnectors; | ||
var unusedConnectors2 = duct2.ConnectorManager.UnusedConnectors; | ||
foreach (var connector in unusedConnectors1) | ||
{ | ||
if (connector is Connector con) | ||
{ | ||
connectors.Add(con); | ||
Debug.WriteLine(con.Origin); | ||
} | ||
} | ||
foreach (Connector connector in unusedConnectors2) | ||
{ | ||
if (connector is Connector con) | ||
{ | ||
connectors.Add(con); | ||
Debug.WriteLine(con.Origin); | ||
} | ||
} | ||
break; | ||
FamilyInstance familyInstance = doc.Create.NewUnionFitting(connectors[1], connectors[2]); | ||
|
||
} | ||
t.Commit(); | ||
List<XYZ> points = new List<XYZ>(); | ||
foreach (var edgearr in face.GetEdgesAsCurveLoops()) | ||
foreach (Curve edge in edgearr) | ||
points.Add(edge.GetEndPoint(0)); | ||
CreateAdaptiveComponentInstance(Document, symbol, points); | ||
} | ||
|
||
tran.Commit(); | ||
} | ||
return Result.Succeeded; | ||
} | ||
catch (Exception ex) | ||
} | ||
public static List<Face> GetTopFaces(Solid solid) | ||
{ | ||
var faces = new List<Face>(); | ||
for (int i = 0; i < solid.Faces.Size; i++) | ||
{ | ||
ex.Message.ToString(); | ||
throw; | ||
faces.Add(solid.Faces.get_Item(i)); | ||
} | ||
return faces.Where(x => NormalOnMidPoint(x).DotProduct(XYZ.BasisZ) > 0).ToList(); | ||
} | ||
public static XYZ NormalOnMidPoint(Face face) | ||
{ | ||
return face.ComputeNormal(face.GetBoundingBox().Min / 2 + face.GetBoundingBox().Max / 2); | ||
} | ||
private void CreateAdaptiveComponentInstance(Document document, FamilySymbol symbol, List<XYZ> xyzs) | ||
{ | ||
FamilyInstance instance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(document, symbol); | ||
IList<ElementId> placePointIds = new List<ElementId>(); | ||
placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); | ||
int index = 0; | ||
foreach (ElementId id in placePointIds) | ||
{ | ||
ReferencePoint point = document.GetElement(id) as ReferencePoint; | ||
point.Position = xyzs[index]; | ||
++index; | ||
} | ||
} | ||
public static void DiscardWarning(Transaction tr) | ||
{ | ||
var op = tr.GetFailureHandlingOptions(); | ||
var preproccessor = new DiscardAndResolveAllWarning(); | ||
op.SetFailuresPreprocessor(preproccessor); | ||
tr.SetFailureHandlingOptions(op); | ||
} | ||
public class DiscardAndResolveAllWarning : IFailuresPreprocessor | ||
{ | ||
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor) | ||
{ | ||
IList<FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages(); | ||
foreach (FailureMessageAccessor fma in fmas) | ||
{ | ||
if (fma.GetSeverity() == FailureSeverity.Error) | ||
{ | ||
failuresAccessor.ResolveFailure(fma); | ||
return FailureProcessingResult.ProceedWithCommit; | ||
} | ||
else if (fma.GetSeverity() == FailureSeverity.Warning) | ||
{ | ||
failuresAccessor.DeleteWarning(fma); | ||
} | ||
} | ||
return FailureProcessingResult.Continue; | ||
} | ||
|
||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,16 @@ | ||
using Autodesk.Revit.Attributes; | ||
using Nice3point.Revit.Toolkit.External; | ||
|
||
namespace BimIshou.Renamefamilytype | ||
{ | ||
[Transaction(TransactionMode.Manual)] | ||
internal class Cmd : ExternalCommand | ||
{ | ||
public override void Execute() | ||
{ | ||
Viewmodel viewmodel = new Viewmodel(Document); | ||
View view = new View() { DataContext = viewmodel }; | ||
view.ShowDialog(); | ||
} | ||
} | ||
} |
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,25 @@ | ||
<Window x:Class="BimIshou.Renamefamilytype.View" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Title="View" Height="450" Width="800"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition/> | ||
<ColumnDefinition/> | ||
</Grid.ColumnDefinitions> | ||
<ListView x:Name="MyListView" ItemsSource="{Binding ListCategory}"> | ||
<ListView.ItemTemplate> | ||
<DataTemplate> | ||
<Expander Header="{Binding Name}" IsExpanded="{Binding IsExpanded, Mode=TwoWay}"> | ||
<ListView ItemsSource="{Binding MyListView.ItemsSource}"> | ||
|
||
</ListView> | ||
</Expander> | ||
</DataTemplate> | ||
</ListView.ItemTemplate> | ||
</ListView> | ||
</Grid> | ||
</Window> |
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,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Shapes; | ||
|
||
namespace BimIshou.Renamefamilytype | ||
{ | ||
/// <summary> | ||
/// Interaction logic for View.xaml | ||
/// </summary> | ||
public partial class View : Window | ||
{ | ||
public View() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using Autodesk.Revit.DB; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BimIshou.Renamefamilytype | ||
{ | ||
public partial class Viewmodel : ObservableObject | ||
{ | ||
private Document doc; | ||
|
||
[ObservableProperty] | ||
private List<Family> listCategory = new List<Family>(); | ||
|
||
public Viewmodel(Document doc) | ||
{ | ||
this.doc = doc; | ||
ListCategory = new FilteredElementCollector(doc) | ||
.OfClass(typeof(Family)) | ||
.OfType<Family>() | ||
.Where(fa => fa.FamilyCategory.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming) | ||
.ToList(); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.