Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: Sweep: Modify, refactor and integrate the code #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions BIMAPI_HW2/BIMAPI_HW2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ProjectGuid>{1251CFD1-EB24-46F1-9C1A-07773BF85625}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BIMAPI_HW2</RootNamespace>
<RootNamespace>BimApiRevitFamilyParametersGenerator</RootNamespace>
<AssemblyName>BIMAPI_HW2</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
Expand All @@ -17,14 +17,16 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Compile Include="Utils.cs" />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Compile Include="Utils.cs" />
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -38,6 +40,12 @@
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Revit 2019\RevitAPIUI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Utils.cs" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Utils.cs" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
Expand All @@ -49,6 +57,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Utils.cs" />
<Compile Include="GenerateFamilyParameter.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
Expand All @@ -60,6 +69,7 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
<DependentUpon>Utils.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions BIMAPI_HW2/Form1.Designer.cs

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

6 changes: 3 additions & 3 deletions BIMAPI_HW2/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.IWin32Window;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB;

namespace BIMAPI_HW2
namespace BimApiRevitFamilyParametersGenerator
{
public partial class Form1 : System.Windows.Forms.Form
public partial class FamilyParameterGeneratorForm : System.Windows.Forms.Form
{
public Document doc;
public Selection selElement;
Expand Down
37 changes: 19 additions & 18 deletions BIMAPI_HW2/GenerateFamilyParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Collections.Generic;
using BIMAPI_HW2;
using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.DB.Events; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace APIFinal
namespace BimApiRevitFamilyParametersGenerator
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]

public class _0104_test : IExternalCommand
public class FamilyParameterGeneratorForm : System.Windows.Forms.Form
{
private class ObjectType : EqualityComparer<ObjectType>
private class DimensionsComparer : EqualityComparer<DimensionsComparer>
{
int[] _dim = new int[2];

Expand All @@ -37,7 +37,7 @@
get { return H.ToString() + " x " + W.ToString() + "mm"; }
}

public ObjectType(int d1, int d2)
public DimensionsComparer(int d1, int d2)
{
if (d1 > d2)
{
Expand All @@ -60,10 +60,10 @@
}
}

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{

Check notice on line 64 in BIMAPI_HW2/GenerateFamilyParameter.cs

View check run for this annotation

codefactor.io / CodeFactor

BIMAPI_HW2/GenerateFamilyParameter.cs#L64

An opening curly bracket must not be followed by a blank line. (SA1505)

void get_number_of_Object(string path, ref int num)
void GetNumberOfObjects(string path, ref int num)
{
StreamReader reader = new StreamReader(path);
while (reader.Peek() >= 0)
Expand All @@ -75,8 +75,8 @@
reader.Close();
}


Check notice on line 78 in BIMAPI_HW2/GenerateFamilyParameter.cs

View check run for this annotation

codefactor.io / CodeFactor

BIMAPI_HW2/GenerateFamilyParameter.cs#L78

The code must not contain multiple blank lines in a row. (SA1507)
void get_ObjectType(string path, ref int[] L1, ref int[] L2)
void GetObjectTypes(string path, ref int[] L1, ref int[] L2)
{
StreamReader reader = new StreamReader(path);
int count = 0;
Expand All @@ -93,7 +93,8 @@
}

//for loading the BIM model
void load_rfa_element(ref Document document, string path, string name)
void LoadRfaElement(ref Document document, string path, string name)

{
Family family = null;
using (Transaction tx = new Transaction(document))
Expand Down Expand Up @@ -153,12 +154,12 @@
int[] length2 = new int[col_num];
get_ObjectType(Object_type_path, ref length1, ref length2);

List<ObjectType> all = new List<ObjectType>();
List<DimensionsComparer> allDimensions = new List<DimensionsComparer>();
for (int i = 0; i < col_num; ++i)
all.Add(new ObjectType(length1[i], length2[i]));
all = all.Distinct(new ObjectType(0, 0)).ToList();


Check notice on line 162 in BIMAPI_HW2/GenerateFamilyParameter.cs

View check run for this annotation

codefactor.io / CodeFactor

BIMAPI_HW2/GenerateFamilyParameter.cs#L162

The code must not contain multiple blank lines in a row. (SA1507)
load_rfa_element(ref doc, rfa_path, rfa_name);

//change Object's type
Expand All @@ -178,13 +179,13 @@
IEnumerable<FamilySymbol> existing
= symbols.Cast<FamilySymbol>().Where<FamilySymbol>(x => x.FamilyName.Equals(rfa_name));

if (0 == existing.Count())

Check notice on line 182 in BIMAPI_HW2/GenerateFamilyParameter.cs

View check run for this annotation

codefactor.io / CodeFactor

BIMAPI_HW2/GenerateFamilyParameter.cs#L182

Do not use comparison where value goes first, reverse order of operands in '0 == existing.Count()'. (SA1131)
{
return Result.Cancelled;
}

List<ObjectType> AlreadyExists = new List<ObjectType>();
List<ObjectType> ToBeMade = new List<ObjectType>();
List<DimensionsComparer> AlreadyExists = new List<DimensionsComparer>();
List<DimensionsComparer> ToBeGenerated = new List<DimensionsComparer>();

for (int i = 0; i < all.Count; ++i)
{
Expand All @@ -207,7 +208,7 @@
//MessageBox.Show("count= " + ToBeMade.Count);
using (Transaction tx = new Transaction(doc))
{
if (tx.Start("Make types") == TransactionStatus.Started)
if (tx.Start("Create Types") == TransactionStatus.Started)
{
FamilySymbol first = existing.First();
foreach (ObjectType ct in ToBeMade)
Expand Down Expand Up @@ -249,10 +250,10 @@
}
tx.Commit();
}
string ObjectMessageBox = "";
string _objectTypeMessageBox = "";
for (int i = 0; i < col_num; i++)
{
ObjectMessageBox += "Create " + Object + " " + length1[i] + " X " + length2[i] + " mm\n";
_objectTypeMessageBox += "Create " + _objectType + " " + length1[i] + " X " + length2[i] + " mm\n";
}
MessageBox.Show(ObjectMessageBox);
}
Expand All @@ -260,7 +261,7 @@
return Result.Succeeded;
}

catch(Exception e)

Check notice on line 264 in BIMAPI_HW2/GenerateFamilyParameter.cs

View check run for this annotation

codefactor.io / CodeFactor

BIMAPI_HW2/GenerateFamilyParameter.cs#L264

An else, catch, or finally statement must not be preceded by a blank line. (SA1510)
{
Console.WriteLine(e);
}
Expand All @@ -271,8 +272,8 @@


/*
string Object = "Beam";//็ตๆง‹ๆจ‘or็ตๆง‹ๆŸฑ
string rfa_name = "ๆททๅ‡ๅœŸ-็Ÿฉๅฝขๆจ‘";
string rfa_path = "C:/ProgramData/Autodesk/RVT 2019/Libraries/China_Trad/็ตๆง‹ๆง‹ๆžถ/ๆททๅ‡ๅœŸ/ๆททๅ‡ๅœŸ-็Ÿฉๅฝขๆจ‘.rfa";
string Object_type_path = "C:/Users/jim/Desktop/test.txt";
string _objectType = "Beam";//็ตๆง‹ๆจ‘or็ตๆง‹ๆŸฑ
string rfaName = "ๆททๅ‡ๅœŸ-็Ÿฉๅฝขๆจ‘";
string rfaPath = "C:/ProgramData/Autodesk/RVT 2019/Libraries/China_Trad/็ตๆง‹ๆง‹ๆžถ/ๆททๅ‡ๅœŸ/ๆททๅ‡ๅœŸ-็Ÿฉๅฝขๆจ‘.rfa";
string objectTypePath = "C:/Users/jim/Desktop/test.txt";

Check notice on line 278 in BIMAPI_HW2/GenerateFamilyParameter.cs

View check run for this annotation

codefactor.io / CodeFactor

BIMAPI_HW2/GenerateFamilyParameter.cs#L63-L278

Complex Method
*/
3 changes: 2 additions & 1 deletion BIMAPI_HW2/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// ็ต„ไปถ็š„ไธ€่ˆฌ่ณ‡่จŠๆ˜ฏ็”ฑไธ‹ๅˆ—็š„ๅฑฌๆ€ง้›†ๆŽงๅˆถใ€‚
// ่ฎŠๆ›ด้€™ไบ›ๅฑฌๆ€ง็š„ๅ€ผๅณๅฏไฟฎๆ”น็ต„ไปถ็š„็›ธ้—œ
// ่ณ‡่จŠใ€‚
[assembly: AssemblyTitle("BIMAPI_HW2")]
[assembly: AssemblyTitle("BimApiRevitFamilyParametersGenerator")]
[assembly: AssemblyProduct("BimApiRevitFamilyParametersGenerator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
Expand Down
Binary file modified BIMAPI_HW2/ShareParameter.txt
Binary file not shown.
25 changes: 25 additions & 0 deletions BIMAPI_HW2/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Utils.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BimApiRevitFamilyParametersGenerator
{
public static class Utils
{
// Utility functions and helper methods
// ...

// Moved utility functions from Form1.Designer.cs
// ...

// Moved utility functions from Form1.cs
// ...

// Moved utility functions from GenerateFamilyParameter.cs
// ...
}
}