Skip to content

Commit

Permalink
xxxxx
Browse files Browse the repository at this point in the history
  • Loading branch information
NinhPham704 committed Dec 7, 2023
1 parent 5545133 commit dbfe47b
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 122 deletions.
5 changes: 0 additions & 5 deletions BimIshou.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@
<Using Include="JetBrains.Annotations" />
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\Icons\RibbonIcon16.png" />
<Resource Include="Resources\Icons\RibbonIcon32.png" />
</ItemGroup>

<ItemGroup>
<Folder Include="ViewModels\Objects" />
</ItemGroup>
Expand Down
50 changes: 25 additions & 25 deletions BimIshou.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Modeless", "..\PhamNinh\Test_Modeless\Test_Modeless.csproj", "{30E79DB0-703E-4EBE-9DB4-488B759BE709}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TesApp", "..\PhamNinh\TesApp\TesApp.csproj", "{74A86E7E-E131-4079-B38A-7BE05CA89952}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF", "..\PhamNinh\WPF\WPF.csproj", "{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -78,30 +78,30 @@ Global
{30E79DB0-703E-4EBE-9DB4-488B759BE709}.Release R24|Any CPU.Build.0 = Release R24|Any CPU
{30E79DB0-703E-4EBE-9DB4-488B759BE709}.Release|Any CPU.ActiveCfg = Release R20|Any CPU
{30E79DB0-703E-4EBE-9DB4-488B759BE709}.Release|Any CPU.Build.0 = Release R20|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R20|Any CPU.ActiveCfg = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R20|Any CPU.Build.0 = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R21|Any CPU.ActiveCfg = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R21|Any CPU.Build.0 = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R22|Any CPU.ActiveCfg = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R22|Any CPU.Build.0 = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R23|Any CPU.ActiveCfg = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R23|Any CPU.Build.0 = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R24|Any CPU.ActiveCfg = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug R24|Any CPU.Build.0 = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R20|Any CPU.ActiveCfg = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R20|Any CPU.Build.0 = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R21|Any CPU.ActiveCfg = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R21|Any CPU.Build.0 = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R22|Any CPU.ActiveCfg = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R22|Any CPU.Build.0 = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R23|Any CPU.ActiveCfg = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R23|Any CPU.Build.0 = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R24|Any CPU.ActiveCfg = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release R24|Any CPU.Build.0 = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74A86E7E-E131-4079-B38A-7BE05CA89952}.Release|Any CPU.Build.0 = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R20|Any CPU.ActiveCfg = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R20|Any CPU.Build.0 = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R21|Any CPU.ActiveCfg = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R21|Any CPU.Build.0 = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R22|Any CPU.ActiveCfg = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R22|Any CPU.Build.0 = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R23|Any CPU.ActiveCfg = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R23|Any CPU.Build.0 = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R24|Any CPU.ActiveCfg = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug R24|Any CPU.Build.0 = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R20|Any CPU.ActiveCfg = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R20|Any CPU.Build.0 = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R21|Any CPU.ActiveCfg = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R21|Any CPU.Build.0 = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R22|Any CPU.ActiveCfg = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R22|Any CPU.Build.0 = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R23|Any CPU.ActiveCfg = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R23|Any CPU.Build.0 = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R24|Any CPU.ActiveCfg = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release R24|Any CPU.Build.0 = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A97DDC2-9A39-4FA6-B29B-6978C7FFE658}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
150 changes: 69 additions & 81 deletions Commands/test.cs
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;
}

}
}
}
9 changes: 0 additions & 9 deletions Core/RevitApi.cs

This file was deleted.

4 changes: 3 additions & 1 deletion DuplicateSheet/DuplicateSheetCMD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Autodesk.Revit.DB;
using BimIshou.DuplicateSheet.ViewModel;
using Nice3point.Revit.Toolkit.External;
using System.Windows;

namespace BimIshou.DuplicateSheet
{
Expand All @@ -21,9 +22,10 @@ public override void Execute()
dupSheetViewModel.DupSheetView.ShowDialog();
tranG.Assimilate();
}
catch (Exception)
catch (Exception e)
{
tranG.RollBack();
MessageBox.Show(e.Message);
}
}

Expand Down
6 changes: 5 additions & 1 deletion DuplicateSheet/ViewModel/DupSheetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ void UpdateSheetNumer(ViewSheet sourceview, ViewSheet targetview, int i)
void DuplicateSelectedSheet(ViewSheet vs, int i)
{
var title_block = GetSheetTitleBlock(vs.Id);
if (title_block != null)
if (title_block == null)
{
throw new Exception("Khong tim thay TitleBlock");
}
else
{
using (Transaction tran = new Transaction(doc, "create sheet"))
{
Expand Down
16 changes: 16 additions & 0 deletions Renamefamilytype/Cmd.cs
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();
}
}
}
25 changes: 25 additions & 0 deletions Renamefamilytype/View.xaml
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>
27 changes: 27 additions & 0 deletions Renamefamilytype/View.xaml.cs
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();
}
}
}
29 changes: 29 additions & 0 deletions Renamefamilytype/Viewmodel.cs
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 removed Resources/Icons/RibbonIcon16.png
Binary file not shown.
Binary file removed Resources/Icons/RibbonIcon32.png
Binary file not shown.
Binary file removed Resources/nature-desktop-background-1691.jpg
Binary file not shown.
Loading

0 comments on commit dbfe47b

Please sign in to comment.