├── LICENSE.txt
├── README.md
├── Autodesk2024
├── RevitFailuresPreprocessor.cs
├── ProfileView.cs
├── SessionVariables.cs
├── RevitFamilyLoadOptions.cs
├── ProfilePVI.cs
├── ProjectPositionUtils.cs
├── SubassemblyParameter.cs
├── AppliedAssembly.cs
├── PipePlaceHolder.cs
├── Subassembly.cs
├── ShapePointArray.cs
├── AbstractMEPCurve.cs
├── Connector.cs
├── TBMTunnel.cs
├── LandFeatureline.cs
├── MultiPoint.cs
├── CivilApplication.cs
├── SlopedFloor.cs
├── Autodesk2024.csproj
├── OpeningUtils.cs
├── ShapePoint.cs
├── Profile.cs
└── Ring.cs
├── CivilConnection.sln
├── .gitattributes
└── .gitignore
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) [year] [fullname]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CivilConnection
2 |
3 | **CivilConnection** is a Dynamo package originally developed by **Autodesk Consulting** to enable seamless data exchange between **Civil 3D** and **Revit**.
4 |
5 | This repository provides an **updated and extended version** maintained by [Atul Tegar](https://github.com/atultegar), featuring new enhancements and compatibility updates for **Revit and Civil 3D 2023-2026**.
6 |
7 | ---
8 |
9 | ## 📦 Downloads
10 |
11 | - **CivilConnection 2023-2026**
12 | → Available via the **Dynamo Package Manager**
13 |
14 | - **CivilPython 2023-2026** *(required for CivilConnection)*
15 | → [Releases - CivilPython](https://github.com/atultegar/CivilPython/releases)
16 |
17 | ---
18 |
19 | ## 🛠️ How You Can Help
20 |
21 | - Download and test in your Civil 3D and Revit environment.
22 | - Report bugs or suggest features via GitHub Issues:
23 | 👉 [CivilConnectionExtended Issues](https://github.com/atultegar/CivilConnectionExtended/issues)
24 |
25 | Your feedback is valuable and helps improve the package for the entire AEC community.
26 |
27 | ---
28 |
29 | ## 📌 Acknowledgements
30 |
31 | Original development by **Autodesk**
32 | Link to original repository: [Autodesk/civilconnection](https://github.com/Autodesk/civilconnection)
33 | Ongoing updates and maintenance by [Atul Tegar](https://github.com/atultegar)
34 |
35 | ---
36 |
37 | Thank you for using and supporting CivilConnection!
38 |
--------------------------------------------------------------------------------
/Autodesk2024/RevitFailuresPreprocessor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | using Autodesk.Revit.DB;
21 | using Autodesk.DesignScript.Runtime;
22 |
23 | namespace CivilConnection
24 | {
25 | ///
26 | /// Revit Failure Preprocessor.
27 | ///
28 | ///
29 | [IsVisibleInDynamoLibrary(false)]
30 | [SupressImportIntoVM]
31 | public class RevitFailuresPreprocessor : IFailuresPreprocessor
32 | {
33 | ///
34 | /// Initializes a new instance of the class.
35 | ///
36 | public RevitFailuresPreprocessor()
37 | { }
38 |
39 | ///
40 | /// Preprocesses the failures.
41 | ///
42 | /// The failure accessor.
43 | ///
44 | public FailureProcessingResult PreprocessFailures(FailuresAccessor fa)
45 | {
46 | fa.DeleteAllWarnings();
47 |
48 | return FailureProcessingResult.Continue;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/CivilConnection.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.10.34916.146
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autodesk2024", "Autodesk2024\Autodesk2024.csproj", "{CA37A627-5F5A-41E5-8BD4-34808DF29485}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | 2023|AnyCPU = 2023|AnyCPU
11 | 2024|AnyCPU = 2024|AnyCPU
12 | 2025|AnyCPU = 2025|AnyCPU
13 | 2026|AnyCPU = 2026|AnyCPU
14 | Debug|AnyCPU = Debug|AnyCPU
15 | Release|AnyCPU = Release|AnyCPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.2023|AnyCPU.ActiveCfg = 2023|Any CPU
19 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.2023|AnyCPU.Build.0 = 2023|Any CPU
20 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.2024|AnyCPU.ActiveCfg = 2024|Any CPU
21 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.2024|AnyCPU.Build.0 = 2024|Any CPU
22 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.2025|AnyCPU.ActiveCfg = 2025|Any CPU
23 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.2025|AnyCPU.Build.0 = 2025|Any CPU
24 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.2026|AnyCPU.ActiveCfg = 2026|Any CPU
25 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.2026|AnyCPU.Build.0 = 2026|Any CPU
26 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.Debug|AnyCPU.ActiveCfg = 2024|Any CPU
27 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.Debug|AnyCPU.Build.0 = 2024|Any CPU
28 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.Release|AnyCPU.ActiveCfg = Release|Any CPU
29 | {CA37A627-5F5A-41E5-8BD4-34808DF29485}.Release|AnyCPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {E0094915-399F-449C-93AB-483740FBD5F8}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/Autodesk2024/ProfileView.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 |
15 |
16 | using Autodesk.AECC.Interop.Land;
17 |
18 | namespace CivilConnection
19 | {
20 | ///
21 | /// ProfileView object type.
22 | ///
23 | public class ProfileView
24 | {
25 | #region PRIVATE PROPERTIES
26 |
27 | ///
28 | /// The profile view
29 | ///
30 | private AeccProfileView _profileView;
31 | #endregion
32 |
33 | #region PUBLIC PROPERTIES
34 |
35 | ///
36 | /// Gets the name.
37 | ///
38 | ///
39 | /// The name.
40 | ///
41 | public string Name { get { return _profileView.DisplayName; } }
42 | ///
43 | /// Gets the internal element.
44 | ///
45 | ///
46 | /// The internal element.
47 | ///
48 | internal object InternalElement { get { return this._profileView; } }
49 | #endregion
50 |
51 | #region CONSTRUCTOR
52 | ///
53 | /// Initializes a new instance of the class.
54 | ///
55 | /// The profile view.
56 | internal ProfileView(AeccProfileView profileView)
57 | {
58 | this._profileView = profileView;
59 | }
60 |
61 | #endregion
62 |
63 | #region PRIVATE METHODS
64 |
65 |
66 | #endregion
67 |
68 | #region PUBLIC METHODS
69 |
70 | ///
71 | /// Returns a that represents this instance.
72 | ///
73 | ///
74 | /// A that represents this instance.
75 | ///
76 | public override string ToString()
77 | {
78 | return string.Format("ProfileView(Name = {0})", this.Name);
79 | }
80 |
81 | #endregion
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Autodesk2024/SessionVariables.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 |
15 |
16 |
17 |
18 | namespace CivilConnection
19 | {
20 | ///
21 | /// Session Variables utilities.
22 | ///
23 | class SessionVariables
24 | {
25 | #region PRIVATE PROPERTIES
26 |
27 | #endregion
28 |
29 | #region PUBLIC PROPERTIES
30 |
31 | ///
32 | /// Gets or sets the land XML path.
33 | ///
34 | ///
35 | /// The land XML path.
36 | ///
37 | public static string LandXMLPath { get; set; }
38 |
39 | ///
40 | /// Gets or sets a value indicating whether this instance is land XML exported.
41 | ///
42 | ///
43 | /// true if this instance is land XML exported; otherwise, false.
44 | ///
45 | public static bool IsLandXMLExported { get; set; }
46 |
47 | ///
48 | /// Returns the CivilApplication object
49 | ///
50 | public static CivilApplication CivilApplication { get; set; }
51 |
52 | ///
53 | /// Returns true if the shared parameters have been created for this session.
54 | ///
55 | public static bool ParametersCreated { get; set; }
56 |
57 | ///
58 | /// Returns a Dynamo CoordinateSystem that represents the Revit Document Total Transform for the session.
59 | ///
60 | public static Autodesk.DesignScript.Geometry.CoordinateSystem DocumentTotalTransform {get;set;}
61 |
62 | ///
63 | /// Returns a Dynamo CoordinateSystem that represents the Revit Document Total Transform Inverse for the session.
64 | ///
65 | public static Autodesk.DesignScript.Geometry.CoordinateSystem DocumentTotalTransformInverse {get;set;}
66 |
67 | #endregion
68 |
69 | #region CONSTRUCTOR
70 | ///
71 | /// Initializes a new instance of the class.
72 | ///
73 | internal SessionVariables()
74 | {
75 | ParametersCreated = false;
76 | DocumentTotalTransform = null;
77 | DocumentTotalTransformInverse = null;
78 | }
79 |
80 | #endregion
81 |
82 | #region PRIVATE METHODS
83 |
84 |
85 | #endregion
86 |
87 | #region PUBLIC METHODS
88 |
89 |
90 | #endregion
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/Autodesk2024/RevitFamilyLoadOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 |
15 | using Autodesk.DesignScript.Runtime;
16 | using Autodesk.Revit.DB;
17 |
18 | namespace CivilConnection
19 | {
20 | ///
21 | /// FamilyLoadOptions
22 | ///
23 | ///
24 | [IsVisibleInDynamoLibrary(false)]
25 | public class RevitFamilyLoadOptions : IFamilyLoadOptions
26 | {
27 | #pragma warning disable CS0169 // The field 'RevitFamilyLoadOptions.overwriteParameters' is never used
28 | ///
29 | /// The overwrite parameters
30 | ///
31 | bool overwriteParameters;
32 | #pragma warning restore CS0169 // The field 'RevitFamilyLoadOptions.overwriteParameters' is never used
33 |
34 | #pragma warning disable CS0169 // The field 'RevitFamilyLoadOptions.source' is never used
35 | ///
36 | /// The source
37 | ///
38 | FamilySource source;
39 | #pragma warning restore CS0169 // The field 'RevitFamilyLoadOptions.source' is never used
40 |
41 | ///
42 | /// Initializes a new instance of the class.
43 | ///
44 | public RevitFamilyLoadOptions()
45 | { }
46 |
47 | ///
48 | /// Called when [family found].
49 | ///
50 | /// if set to true [family in use].
51 | /// if set to true [overwrite parameters].
52 | ///
53 | public bool OnFamilyFound(bool familyInUse, out bool overwriteParameters)
54 | {
55 | overwriteParameters = true;
56 |
57 | return true;
58 | }
59 |
60 | ///
61 | /// Called when [shared family found].
62 | ///
63 | /// The shared family.
64 | /// if set to true [family in use].
65 | /// The source.
66 | /// if set to true [overwrite parameters].
67 | ///
68 | public bool OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameters)
69 | {
70 | source = FamilySource.Family;
71 | overwriteParameters = true;
72 | return true;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Autodesk2024/ProfilePVI.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | using System.Runtime;
21 | using System.Runtime.InteropServices;
22 |
23 | using Autodesk.AutoCAD.Interop;
24 | using Autodesk.AutoCAD.Interop.Common;
25 | using Autodesk.AECC.Interop.UiRoadway;
26 | using Autodesk.AECC.Interop.Roadway;
27 | using Autodesk.AECC.Interop.Land;
28 | using Autodesk.AECC.Interop.UiLand;
29 | using System.Reflection;
30 |
31 | using Autodesk.DesignScript.Runtime;
32 | using Autodesk.DesignScript.Geometry;
33 |
34 | namespace CivilConnection
35 | {
36 | ///
37 | /// ProfilePVI object type.
38 | ///
39 | [IsVisibleInDynamoLibrary(false)]
40 | public class ProfilePVI
41 | {
42 | #region PRIVATE PROPERTIES
43 | ///
44 | /// The pvi
45 | ///
46 | private AeccProfilePVI _pvi;
47 |
48 | #endregion
49 |
50 | #region PUBLIC PROPERTIES
51 | ///
52 | /// Gets the station.
53 | ///
54 | ///
55 | /// The station.
56 | ///
57 | public double Station { get { return _pvi.Station; } }
58 | ///
59 | /// Gets the internal element.
60 | ///
61 | ///
62 | /// The internal element.
63 | ///
64 | internal object InternalElement { get { return this._pvi; } }
65 | ///
66 | /// Gets the elevation.
67 | ///
68 | ///
69 | /// The elevation.
70 | ///
71 | public double Elevation { get { return _pvi.Elevation; } }
72 | ///
73 | /// Gets the grade in.
74 | ///
75 | ///
76 | /// The grade in.
77 | ///
78 | public double GradeIn { get { return _pvi.GradeIn; } }
79 | ///
80 | /// Gets the grade out.
81 | ///
82 | ///
83 | /// The grade out.
84 | ///
85 | public double GradeOut { get { return _pvi.GradeOut; } }
86 |
87 | #endregion
88 |
89 | #region CONSTRUCTOR
90 | ///
91 | /// Initializes a new instance of the class.
92 | ///
93 | /// The pvi.
94 | internal ProfilePVI(AeccProfilePVI pvi)
95 | {
96 | this._pvi = pvi;
97 | }
98 |
99 | #endregion
100 |
101 | #region PRIVATE METHODS
102 |
103 |
104 | #endregion
105 |
106 | #region PUBLIC METHODS
107 |
108 |
109 | //TODO: Get profile curves
110 |
111 | ///
112 | /// Returns a text representation of the object.
113 | ///
114 | ///
115 | public override string ToString()
116 | {
117 | return string.Format("ProfilePVI(Station = {0}, Elevation = {1}, GradeIn = {2}, GradeOut = {3})", this.Station, this.Elevation, this.GradeIn, this.GradeOut);
118 | }
119 | #endregion
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/Autodesk2024/ProjectPositionUtils.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.DesignScript.Runtime;
15 | using RevitServices.Persistence;
16 | using System;
17 |
18 |
19 |
20 |
21 | namespace CivilConnection
22 | {
23 | ///
24 | /// Static Obejct that returns the ProjectPosition of the Revit Document
25 | ///
26 | [IsVisibleInDynamoLibrary(false)]
27 | class ProjectPositionUtils
28 | {
29 | #region PRIVATE MEMBERS
30 |
31 | private static Autodesk.Revit.DB.ProjectPosition _position;
32 | private static double _angle;
33 | private static ProjectPositionUtils _instance;
34 | private static Autodesk.Revit.DB.ProjectLocation _location;
35 |
36 | #endregion
37 |
38 | #region PUBLIC MEMBERS
39 | ///
40 | /// The ProjectPosition
41 | ///
42 | public Autodesk.Revit.DB.ProjectPosition ProjectPosition
43 | {
44 | get
45 | {
46 | return _position;
47 | }
48 |
49 | }
50 | ///
51 | /// The angle of the Project Position
52 | ///
53 | public double Angle
54 | {
55 | get
56 | {
57 | return _angle;
58 | }
59 |
60 | }
61 | ///
62 | /// The ProjectLocation
63 | ///
64 | public Autodesk.Revit.DB.ProjectLocation ProjectLocation
65 | {
66 | get
67 | {
68 | return _location;
69 | }
70 | }
71 |
72 | ///
73 | /// ProjectPositionUtils Instance
74 | ///
75 | public static ProjectPositionUtils Instance
76 | {
77 | get
78 | {
79 | if (_instance == null)
80 | {
81 | _instance = new ProjectPositionUtils();
82 | }
83 |
84 | return _instance;
85 | }
86 | }
87 |
88 | #endregion
89 |
90 | #region CONSTRUCTOR
91 |
92 | ///
93 | /// Constructor.
94 | ///
95 | protected ProjectPositionUtils()
96 | {
97 | _location = DocumentManager.Instance.CurrentDBDocument.ActiveProjectLocation;
98 |
99 | if (Convert.ToInt32(DocumentManager.Instance.CurrentDBDocument.Application.VersionNumber) <= 2018)
100 | {
101 | //try
102 | //{
103 | // _position = _location.get_ProjectPosition(Autodesk.Revit.DB.XYZ.Zero);
104 | // _angle = _position.Angle;
105 | //}
106 | //catch (Exception ex)
107 | //{
108 | // Utils.Log(string.Format("ERROR {0}: {1}", this, ex.Message));
109 | //}
110 | }
111 | else
112 | {
113 | _position = _location.GetProjectPosition(Autodesk.Revit.DB.XYZ.Zero);
114 | _angle = _position.Angle;
115 | }
116 | }
117 |
118 | #endregion
119 |
120 | #region PUBLIC METHODS
121 | ///
122 | /// String representation
123 | ///
124 | ///
125 | public override string ToString()
126 | {
127 | return base.ToString();
128 | }
129 |
130 | ///
131 | /// Set the new ProjectLocation of the Revit document origin.
132 | ///
133 | /// The ProjectLocation
134 | /// The new ProjectPosition of the document origin.
135 | public void SetProjectPosition(Autodesk.Revit.DB.ProjectLocation location, Autodesk.Revit.DB.ProjectPosition newPosition)
136 | {
137 | Utils.Log(string.Format("ProjectPositionUtils.SetProjectPosition started...", ""));
138 |
139 | // location.set_ProjectPosition(Autodesk.Revit.DB.XYZ.Zero, newPosition); // deprecated
140 | location.SetProjectPosition(Autodesk.Revit.DB.XYZ.Zero, newPosition);
141 |
142 | Utils.Log(string.Format("ProjectPositionUtils.SetProjectPosition completed.", ""));
143 | }
144 |
145 | #endregion
146 |
147 | #region PRIVATE METHODS
148 |
149 |
150 | #endregion
151 |
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/Autodesk2024/SubassemblyParameter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 |
15 |
16 | using Autodesk.AECC.Interop.Roadway;
17 | using Autodesk.AECC.Interop.Land;
18 |
19 | using Autodesk.DesignScript.Runtime;
20 |
21 |
22 |
23 | namespace CivilConnection
24 | {
25 | ///
26 | /// SubassemblyParameter obejct type.
27 | ///
28 | public class SubassemblyParameter
29 | {
30 | #region PRIVATE PROPERTIES
31 | ///
32 | /// The parameter
33 | ///
34 | internal IAeccParam _parameter;
35 | ///
36 | /// The value
37 | ///
38 | internal object _value;
39 | ///
40 | /// The type
41 | ///
42 | internal SubassemblyParameterType _type;
43 | //internal SubassemblyParameter[] _parameters;
44 |
45 | ///
46 | /// Gets the internal element.
47 | ///
48 | ///
49 | /// The internal element.
50 | ///
51 | internal object InternalElement { get { return this._parameter; } }
52 |
53 | #endregion
54 |
55 | #region PUBLIC PROPERTIES
56 | ///
57 | /// Gets the name.
58 | ///
59 | ///
60 | /// The name.
61 | ///
62 | public string Name { get { return this._parameter.DisplayName; } }
63 | ///
64 | /// Gets the Comment.
65 | ///
66 | ///
67 | /// The name.
68 | ///
69 | public string Comment { get { return this._parameter.Comment; } }
70 | ///
71 | /// Gets the Description.
72 | ///
73 | ///
74 | /// The name.
75 | ///
76 | public string Description { get { return this._parameter.Description; } }
77 | ///
78 | /// Gets the value.
79 | ///
80 | ///
81 | /// The value.
82 | ///
83 | public object Value { get { return this._value; } }
84 | ///
85 | /// Gets the type.
86 | ///
87 | ///
88 | /// The type.
89 | ///
90 | public SubassemblyParameterType Type { get { return this._type; } }
91 | //public Parameters[] Parameters {get {return this._parameters}}
92 |
93 | #endregion
94 |
95 | #region CONSTRUCTOR
96 | ///
97 | /// Initializes a new instance of the class.
98 | ///
99 | /// The parameter.
100 | internal SubassemblyParameter(IAeccParam parameter)
101 | {
102 | this._parameter = parameter;
103 |
104 | if (parameter is AeccParamBool)
105 | {
106 | var p = parameter as AeccParamBool;
107 | this._type = SubassemblyParameterType.Bool;
108 | this._value = p.Value;
109 | }
110 | else if (parameter is AeccParamDouble)
111 | {
112 | var p = parameter as AeccParamDouble;
113 | this._type = SubassemblyParameterType.Double;
114 | this._value = p.Value;
115 | }
116 | else if (parameter is AeccParamLong)
117 | {
118 | this._type = SubassemblyParameterType.Long;
119 | var p = parameter as AeccParamLong;
120 | this._value = p.Value;
121 | }
122 | else if (parameter is AeccParamString)
123 | {
124 | this._type = SubassemblyParameterType.String;
125 | var p = parameter as AeccParamString;
126 | this._value = p.Value;
127 | }
128 | }
129 |
130 |
131 | #endregion
132 |
133 | #region PRIVATE METHODS
134 |
135 |
136 | #endregion
137 |
138 | #region PUBLIC METHODS
139 |
140 | ///
141 | /// Returns a that represents this instance.
142 | ///
143 | ///
144 | /// A that represents this instance.
145 | ///
146 | public override string ToString()
147 | {
148 | return string.Format("SubassemblyParameter(Name={0}, Value={1}, Type={2}, Comment={3}, Description={4})", this._parameter.DisplayName, this.Value, this._type, this._parameter.Comment, this._parameter.Description);
149 | }
150 | #endregion
151 | }
152 |
153 | ///
154 | /// SubassemblyParameterType enumerator.
155 | ///
156 | [IsVisibleInDynamoLibrary(false)]
157 | public enum SubassemblyParameterType
158 | {
159 | ///
160 | /// Boolean Type
161 | ///
162 | Bool,
163 | ///
164 | /// Double Type
165 | ///
166 | Double,
167 | ///
168 | /// Long Type
169 | ///
170 | Long,
171 | ///
172 | /// Stirng Type
173 | ///
174 | String
175 | }
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/Autodesk2024/AppliedAssembly.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.AECC.Interop.Roadway;
15 | using Autodesk.DesignScript.Geometry;
16 | using Autodesk.DesignScript.Runtime;
17 | using System.Collections.Generic;
18 |
19 | namespace CivilConnection
20 | {
21 | ///
22 | /// AppliedAssembly object type.
23 | ///
24 | [IsVisibleInDynamoLibrary(false)]
25 | public class AppliedAssembly
26 | {
27 | #region PRIVATE PROPERTIES
28 |
29 | internal AeccAppliedAssembly _assembly;
30 | internal AeccAppliedSubassemblies _appliedSubassemblies;
31 | internal AeccCorridor _corridor;
32 | internal BaselineRegion _region;
33 |
34 | internal object InternalElement { get { return this._assembly; } }
35 |
36 | #endregion
37 |
38 | #region CONSTRUCTOR
39 | ///
40 | /// Internal Constructor.
41 | ///
42 | /// The BaselineRegion
43 | /// the AeccAppliedAssembly form Civil 3D.
44 | /// the AeccCorridor from Civil 3D.
45 | internal AppliedAssembly(BaselineRegion blr, AeccAppliedAssembly appliedAssembly, AeccCorridor corridor)
46 | {
47 | this._region = blr;
48 | this._assembly = appliedAssembly;
49 | this._appliedSubassemblies = appliedAssembly.AppliedSubassemblies;
50 | this._corridor = corridor;
51 | }
52 |
53 | #endregion
54 |
55 | #region PUBLIC METHODS
56 | ///
57 | /// Public textual representation in the Dynamo node preview.
58 | ///
59 | ///
60 | /// A that represents this instance.
61 | ///
62 | public override string ToString()
63 | {
64 | return string.Format("AppliedAssembly");
65 | }
66 | #endregion
67 | }
68 |
69 |
70 | ///
71 | /// Base class for applied subassemblies geometry objects.
72 | ///
73 | [IsVisibleInDynamoLibrary(false)]
74 | public abstract class AbstractAppliedSubassemblyGeometryObject
75 | {
76 | #region PRIVATE PROPERTIES
77 | ///
78 | protected string _name;
79 | ///
80 | protected Geometry _geometry;
81 | ///
82 | protected IList _codes = new List();
83 | ///
84 | protected double _station;
85 | #endregion
86 |
87 | #region PUBLIC PROPERTIES
88 |
89 | #endregion
90 |
91 | #region CONSTRUCTOR
92 | internal AbstractAppliedSubassemblyGeometryObject(string name, Geometry geometry, IList codes, double station)
93 | {
94 | this._name = name;
95 | this._geometry = geometry;
96 | this._codes = codes;
97 | this._station = station;
98 | }
99 | #endregion
100 |
101 | #region PUBLIC METHODS
102 |
103 | #endregion
104 | }
105 |
106 | //[IsVisibleInDynamoLibrary(false)]
107 | ///
108 | ///The Applied Subassembly link object
109 | ///
110 | public class AppliedSubassemblyLink : AbstractAppliedSubassemblyGeometryObject
111 | {
112 | // It's necessary to add these public properties to have them shown in the Dynamo Library
113 | #region PUBLIC PROPERTIES
114 | ///
115 | /// Returns the unique name of the object.
116 | ///
117 | public string Name { get { return this._name; } }
118 |
119 | ///
120 | /// Returns the Dynamo geometry associated to the object.
121 | ///
122 | public Geometry Geometry { get { return this._geometry; } }
123 |
124 | ///
125 | /// Returns the list of codes associated to the object.
126 | ///
127 | public IList Codes { get { return this._codes; } }
128 |
129 | ///
130 | /// Returns the station associated to the object.
131 | ///
132 | public double Station { get { return this._station; } }
133 |
134 | #endregion
135 |
136 | #region CONSTRUCTOR
137 | internal AppliedSubassemblyLink(string name, Geometry geometry, IList codes, double station)
138 | : base(name, geometry, codes, station)
139 | {
140 | }
141 | #endregion
142 |
143 | #region PUBLIC METHODS
144 |
145 | ///
146 | /// Public textual representation of the Dynamo node preview
147 | ///
148 | ///
149 | /// A that represents this instance.
150 | ///
151 | public override string ToString()
152 | {
153 | return string.Format("AppliedSubassemblyLink(Name={0})", this.Name);
154 | }
155 | #endregion
156 | }
157 |
158 | //[IsVisibleInDynamoLibrary(false)]
159 | ///
160 | ///The Applied Subassembly shape object
161 | ///
162 | public class AppliedSubassemblyShape : AbstractAppliedSubassemblyGeometryObject
163 | {
164 | // It's necessary to add these public properties to have them shown in the Dynamo Library
165 | #region PUBLIC PROPERTIES
166 | ///
167 | /// Returns the unique name of the object.
168 | ///
169 | public string Name { get { return this._name; } }
170 |
171 | ///
172 | /// Returns the Dynamo geometry associated to the object.
173 | ///
174 | public Geometry Geometry { get { return this._geometry; } }
175 |
176 | ///
177 | /// Returns the list of codes associated to the object.
178 | ///
179 | public IList Codes { get { return this._codes; } }
180 |
181 | ///
182 | /// Returns the station associated to the object.
183 | ///
184 | public double Station { get { return this._station; } }
185 |
186 | #endregion
187 |
188 | #region CONSTRUCTOR
189 | internal AppliedSubassemblyShape(string name, Geometry geometry, IList codes, double station)
190 | : base(name, geometry, codes, station)
191 | {
192 | }
193 | #endregion
194 |
195 | #region PUBLIC METHODS
196 |
197 | ///
198 | /// Public textual representation of the Dynamo node preview
199 | ///
200 | ///
201 | /// A that represents this instance.
202 | ///
203 | public override string ToString()
204 | {
205 | return string.Format("AppliedSubassemblyShape(Name={0})", this.Name);
206 | }
207 | #endregion
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/Autodesk2024/PipePlaceHolder.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.DesignScript.Runtime;
15 | using Autodesk.Revit.DB;
16 | using Autodesk.Revit.DB.Mechanical;
17 |
18 | using Revit.GeometryConversion;
19 |
20 | using RevitServices.Persistence;
21 | using RevitServices.Transactions;
22 | using Revit.Elements;
23 | using System.Collections.Generic;
24 |
25 |
26 | namespace CivilConnection.MEP
27 | {
28 | ///
29 | /// PipePlaceHolder obejct type.
30 | ///
31 | ///
32 | [DynamoServices.RegisterForTrace()]
33 | [IsVisibleInDynamoLibrary(false)]
34 | public class PipePlaceHolder : AbstractMEPCurve
35 | {
36 | #region PRIVATE PROPERTIES
37 |
38 |
39 | #endregion
40 |
41 | #region PUBLIC PROPERTIES
42 |
43 |
44 | #endregion
45 |
46 | #region CONSTRUCTOR
47 |
48 | ///
49 | /// Initializes a new instance of the class.
50 | ///
51 | /// The instance.
52 | protected PipePlaceHolder(Autodesk.Revit.DB.Plumbing.Pipe instance)
53 | {
54 | SafeInit(() => InitPipe(instance));
55 | }
56 |
57 | ///
58 | /// Initializes a new instance of the class.
59 | ///
60 | /// Type of the pipe.
61 | /// Type of the system.
62 | /// The start.
63 | /// The end.
64 | /// The level.
65 | internal PipePlaceHolder(Autodesk.Revit.DB.Plumbing.PipeType pipeType, Autodesk.Revit.DB.Plumbing.PipingSystemType systemType, XYZ start, XYZ end,
66 | Autodesk.Revit.DB.Level level)
67 | {
68 | InitPipe(pipeType, systemType, start, end, level);
69 | }
70 |
71 | #endregion
72 |
73 | #region PRIVATE METHODS
74 | ///
75 | /// Initialize a Pipe element.
76 | ///
77 | /// The instance.
78 | private void InitPipe(Autodesk.Revit.DB.Plumbing.Pipe instance)
79 | {
80 | InternalSetMEPCurve(instance);
81 | }
82 |
83 | ///
84 | /// Initialize a Pipe element.
85 | ///
86 | /// Type of the pipe.
87 | /// Type of the system.
88 | /// The start.
89 | /// The end.
90 | /// The level.
91 | private void InitPipe(Autodesk.Revit.DB.Plumbing.PipeType pipeType, Autodesk.Revit.DB.Plumbing.PipingSystemType systemType, XYZ start, XYZ end,
92 | Autodesk.Revit.DB.Level level)
93 | {
94 | //Phase 1 - Check to see if the object exists and should be rebound
95 | var oldFam =
96 | ElementBinder.GetElementFromTrace(DocumentManager.Instance.CurrentDBDocument);
97 |
98 | //There was a point, rebind to that, and adjust its position
99 | if (oldFam != null)
100 | {
101 | InternalSetMEPCurve(oldFam);
102 | InternalSetMEPCurveType(pipeType);
103 | InternalSetPosition(start, end);
104 | return;
105 | }
106 |
107 | //Phase 2- There was no existing point, create one
108 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
109 |
110 | Autodesk.Revit.DB.MEPCurve fi;
111 |
112 | if (DocumentManager.Instance.CurrentDBDocument.IsFamilyDocument)
113 | {
114 | fi = null;
115 | }
116 | else
117 | {
118 | fi = Autodesk.Revit.DB.Plumbing.Pipe.CreatePlaceholder(DocumentManager.Instance.CurrentDBDocument, systemType.Id, pipeType.Id, level.Id, start, end);
119 | }
120 |
121 | InternalSetMEPCurve(fi);
122 |
123 | TransactionManager.Instance.TransactionTaskDone();
124 |
125 | ElementBinder.SetElementForTrace(InternalElement);
126 | }
127 |
128 | ///
129 | /// Internals the type of the set piping system.
130 | ///
131 | /// The type.
132 | private void InternalSetPipingSystemType(Autodesk.Revit.DB.Plumbing.PipingSystemType type)
133 | {
134 | if (InternalMEPCurve.MEPSystem.GetTypeId().Value.Equals(type.Id.Value))
135 | return;
136 |
137 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
138 |
139 | InternalMEPCurve.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM).Set(type.Id);
140 |
141 | TransactionManager.Instance.TransactionTaskDone();
142 | }
143 |
144 | #endregion
145 |
146 | #region PUBLIC METHODS
147 |
148 | ///
149 | /// Creates a PipePlaceholder by two points.
150 | ///
151 | /// Type of the pipe.
152 | /// Type of the system.
153 | /// The start.
154 | /// The end.
155 | /// The level.
156 | ///
157 | public static PipePlaceHolder ByPoints(Revit.Elements.Element pipeType, Revit.Elements.Element systemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level)
158 | {
159 | Utils.Log(string.Format("PipePlaceHolder.ByPoints started...", ""));
160 |
161 | var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType;
162 | var oSystemType = systemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType;
163 | var totalTransform = RevitUtils.DocumentTotalTransform();
164 |
165 | var nstart = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
166 | var s = nstart.ToXyz();
167 | var nend = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
168 | var e = nend.ToXyz();
169 | var l = level.InternalElement as Autodesk.Revit.DB.Level;
170 |
171 | if (nstart != null)
172 | {
173 | nstart.Dispose();
174 | }
175 | if (nend != null)
176 | {
177 | nend.Dispose();
178 | }
179 |
180 | Utils.Log(string.Format("PipePlaceHolder.ByPoints completed.", ""));
181 |
182 | return new PipePlaceHolder(oType, oSystemType, s, e, l);
183 | }
184 |
185 | #endregion
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/Autodesk2024/Subassembly.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.AECC.Interop.Land;
15 | using Autodesk.AECC.Interop.Roadway;
16 | using System;
17 | using System.Collections.Generic;
18 | using System.Linq;
19 |
20 | namespace CivilConnection
21 | {
22 | ///
23 | /// Subassembly object type.
24 | ///
25 | public class Subassembly
26 | {
27 | #region PRIVATE PROPERTIES
28 |
29 | ///
30 | /// The subassembly
31 | ///
32 | internal AeccSubassembly _subassembly;
33 | ///
34 | /// The corridor
35 | ///
36 | internal AeccCorridor _corridor;
37 | ///
38 | /// The parameters
39 | ///
40 | internal IList _parameters = new List();
41 |
42 | ///
43 | /// Gets the internal element.
44 | ///
45 | ///
46 | /// The internal element.
47 | ///
48 | internal object InternalElement { get { return this._subassembly; } }
49 |
50 | #endregion
51 |
52 | #region PUBLIC PROPERTIES
53 | ///
54 | /// Gets the name.
55 | ///
56 | ///
57 | /// The name.
58 | ///
59 | public string Name { get { return this._subassembly.Name; } }
60 | ///
61 | /// Gets the parameters.
62 | ///
63 | ///
64 | /// The parameters.
65 | ///
66 | public IList Parameters { get { return this._parameters; } }
67 |
68 | #endregion
69 |
70 | #region CONSTRUCTOR
71 |
72 | ///
73 | /// Initializes a new instance of the class.
74 | ///
75 | /// The subassembly.
76 | /// The corridor.
77 | internal Subassembly(AeccSubassembly subassembly, AeccCorridor corridor)
78 | {
79 | this._subassembly = subassembly;
80 | this._corridor = corridor;
81 |
82 | foreach (var p in subassembly.ParamsBool)
83 | {
84 | this._parameters.Add(new SubassemblyParameter((IAeccParam)p));
85 | }
86 | foreach (var p in subassembly.ParamsDouble)
87 | {
88 | this._parameters.Add(new SubassemblyParameter((IAeccParam)p));
89 | }
90 | foreach (var p in subassembly.ParamsLong)
91 | {
92 | this._parameters.Add(new SubassemblyParameter((IAeccParam)p));
93 | }
94 | foreach (var p in subassembly.ParamsString)
95 | {
96 | this._parameters.Add(new SubassemblyParameter((IAeccParam)p));
97 | }
98 | }
99 |
100 | #endregion
101 |
102 | #region PRIVATE METHODS
103 |
104 |
105 | #endregion
106 |
107 | #region PUBLIC METHODS
108 |
109 | ///
110 | /// Sets SubassemblyParameter value by name.
111 | ///
112 | /// The parameter name.
113 | /// The value.
114 | /// if set to true [rebuild].
115 | ///
116 | ///
117 | /// The parameter name cannot be null
118 | /// or
119 | /// The value cannot be null
120 | /// or
121 | /// or
122 | ///
123 | public Subassembly SetParameterByName(string name, object value, bool rebuild = false)
124 | {
125 | Utils.Log(string.Format("Subassembly.SetParameterByName started...", ""));
126 |
127 | if (null == name)
128 | {
129 | throw new Exception("The parameter name cannot be null");
130 | }
131 |
132 | if (null == value)
133 | {
134 | throw new Exception("The value cannot be null");
135 | }
136 |
137 | SubassemblyParameter parameter = null;
138 |
139 | try
140 | {
141 | parameter = this.Parameters.First(x => x.Name == name);
142 | }
143 | catch (Exception ex)
144 | {
145 | var message = string.Format("No parameter {0} found on this Subassembly", name);
146 |
147 | Utils.Log(string.Format("ERROR: Subassembly.SetParameterByName {0} {1}", message, ex.Message));
148 |
149 | throw new Exception(message);
150 | }
151 |
152 | if (null != parameter)
153 | {
154 | if(parameter.Type == SubassemblyParameterType.Bool && value is bool)
155 | {
156 | var p = parameter.InternalElement as AeccParamBool;
157 | p.Value = Convert.ToBoolean(value);
158 | }
159 |
160 | else if(parameter.Type == SubassemblyParameterType.Double && (value is double || value is int))
161 | {
162 | var p = parameter.InternalElement as AeccParamDouble;
163 | p.Value = Convert.ToDouble(value);
164 | }
165 |
166 | else if (parameter.Type == SubassemblyParameterType.Long && (value is long || value is double || value is int))
167 | {
168 | var p = parameter.InternalElement as AeccParamLong;
169 | p.Value = Convert.ToInt32(value);
170 | }
171 | else if (parameter.Type == SubassemblyParameterType.String && value is string)
172 | {
173 | var p = parameter.InternalElement as AeccParamString;
174 | p.Value = Convert.ToString(value);
175 | }
176 | else
177 | {
178 | var message = string.Format("The value does not match the parameter data type {0}", parameter.Type);
179 |
180 | Utils.Log(string.Format("ERROR: Subassembly.SetParameterByName {0}", message));
181 |
182 | throw new Exception(message);
183 | }
184 | }
185 |
186 | if (rebuild)
187 | {
188 | AeccSubassembly sa = this.InternalElement as AeccSubassembly;
189 | this._corridor.Rebuild();
190 | }
191 |
192 | Utils.Log(string.Format("Subassembly.SetParameterByName completed.", ""));
193 |
194 | return this;
195 | }
196 |
197 | ///
198 | /// Returns a that represents this instance.
199 | ///
200 | ///
201 | /// A that represents this instance.
202 | ///
203 | public override string ToString()
204 | {
205 | return string.Format("Subassembly(Name={0}, Corridor={1})", this.Name, this._corridor.Name);
206 | }
207 | #endregion
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/Autodesk2024/ShapePointArray.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 |
18 |
19 | namespace CivilConnection
20 | {
21 | ///
22 | /// Collection of ShapePoints
23 | ///
24 | [Newtonsoft.Json.JsonConverter(typeof(ShapePointArrayConverter))]
25 | public class ShapePointArray
26 | {
27 | #region PRIVATE PROPERTIES
28 |
29 |
30 | #endregion
31 |
32 | #region PUBLIC PROPERTIES
33 | ///
34 | /// Gets the points.
35 | ///
36 | ///
37 | /// The points.
38 | ///
39 | ///
40 | [Newtonsoft.Json.JsonProperty("Points")]
41 | public IList Points { get; set; }
42 |
43 | ///
44 | /// Gets the count.
45 | ///
46 | ///
47 | /// The count.
48 | ///
49 | [Newtonsoft.Json.JsonIgnore]
50 | public int Count { get { return this.Points.Count; } }
51 |
52 | #endregion
53 |
54 | #region CONSTRUCTOR
55 | ///
56 | internal ShapePointArray() { }
57 |
58 | #endregion
59 |
60 | #region PRIVATE METHODS
61 |
62 | ///
63 | private ShapePointArray Copy()
64 | {
65 | Utils.Log(string.Format("ShapePointArray.Copy started...", ""));
66 |
67 | ShapePointArray spa = new ShapePointArray();
68 |
69 | spa.Points = new List();
70 |
71 | foreach (ShapePoint p in this.Points)
72 | {
73 | var sp = p.Copy(spa.Points.Count);
74 | spa.Points.Add(sp);
75 | }
76 |
77 | Utils.Log(string.Format("ShapePointArray.Copy completed.", ""));
78 |
79 | return spa;
80 | }
81 |
82 | ///
83 | /// Initializes a new instance of the class.
84 | ///
85 | /// The shape points.
86 | [Newtonsoft.Json.JsonConstructor]
87 | internal ShapePointArray(IList shapePoints)
88 | {
89 | this.Points = new List();
90 |
91 | for (int i = 0; i < shapePoints.Count; ++i)
92 | {
93 | this.Points.Add(shapePoints[i].Copy(i));
94 | }
95 | }
96 | #endregion
97 |
98 | #region PUBLIC METHODS
99 |
100 | ///
101 | /// Returns a ShapePointArray object
102 | ///
103 | /// The list of ShapePoints.
104 | ///
105 | public static ShapePointArray ByShapePointList(IList shapePointList)
106 | {
107 | return new ShapePointArray(shapePointList);
108 | }
109 |
110 | //[IsVisibleInDynamoLibrary(false)]
111 | ///
112 | /// Adds the specified shape point.
113 | ///
114 | /// The shape point.
115 | ///
116 | public ShapePointArray Add(ShapePoint shapePoint)
117 | {
118 | Utils.Log(string.Format("ShapePointArray.Add started...", ""));
119 |
120 | ShapePointArray spa = this.Copy();
121 |
122 | var sp = shapePoint.Copy();
123 | sp.SetId(spa.Points.Count);
124 | spa.Points.Add(sp);
125 |
126 | Utils.Log(string.Format("ShapePointArray.Add completed.", ""));
127 |
128 | return spa;
129 | }
130 |
131 | //[IsVisibleInDynamoLibrary(false)]
132 | ///
133 | /// Renumbers the ShapePoints in the instance.
134 | ///
135 | public ShapePointArray Renumber()
136 | {
137 | Utils.Log(string.Format("ShapePointArray.Renumber started...", ""));
138 |
139 | ShapePointArray spa = this.Copy();
140 |
141 | if (spa.Points.Count > 0)
142 | {
143 | for (int i = 0; i < spa.Points.Count; ++i)
144 | {
145 | spa.Points[i].SetId(i);
146 | }
147 | }
148 | else
149 | {
150 | var message = "The collection is empty";
151 |
152 | Utils.Log(string.Format("ERROR: ShapePointArray.Renumber {0}", message));
153 |
154 | throw new Exception(message);
155 | }
156 |
157 | Utils.Log(string.Format("ShapePointArray.Renumber completed.", ""));
158 |
159 | return spa;
160 | }
161 |
162 | //[IsVisibleInDynamoLibrary(false)]
163 | ///
164 | /// Removes the ShapePoint at index.
165 | ///
166 | /// The index.
167 | ///
168 | public ShapePointArray RemoveAtIndex(int index)
169 | {
170 | Utils.Log(string.Format("ShapePointArray.RemoveAtIndex started...", ""));
171 |
172 | ShapePointArray spa = this.Copy();
173 |
174 | if (index < 0 || index > spa.Count - 1)
175 | {
176 | throw new Exception("Invalid index");
177 | }
178 |
179 | spa.Points.RemoveAt(index);
180 | spa.Renumber();
181 |
182 | Utils.Log(string.Format("ShapePointArray.RemoveAtIndex completed.", ""));
183 |
184 | return spa;
185 | }
186 |
187 | //[IsVisibleInDynamoLibrary(false)]
188 | ///
189 | /// Sorts the by station.
190 | ///
191 | /// The index.
192 | ///
193 | public ShapePointArray SortByStation(int index)
194 | {
195 | Utils.Log(string.Format("ShapePointArray.SortByStation started...", ""));
196 |
197 | ShapePointArray spa = this.Copy();
198 |
199 | spa.Points = spa.Points.OrderBy(p => p.Station).ToList();
200 | spa.Renumber();
201 |
202 | Utils.Log(string.Format("ShapePointArray.SortByStation completed.", ""));
203 |
204 | return spa;
205 | }
206 |
207 | //[IsVisibleInDynamoLibrary(false)]
208 | ///
209 | /// Splits ShpaePoints into subset of ShapePoints by featureline.
210 | ///
211 | ///
212 | public IList SplitByFeatureline()
213 | {
214 | return this.Points.GroupBy(p => p.Featureline).Select(g => new ShapePointArray(g.ToList())).ToList();
215 | }
216 |
217 | //[IsVisibleInDynamoLibrary(false)]
218 | ///
219 | /// Reverses this instance.
220 | ///
221 | ///
222 | public ShapePointArray Reverse()
223 | {
224 | Utils.Log(string.Format("ShapePointArray.Reverse started...", ""));
225 |
226 | ShapePointArray spa = this.Copy();
227 |
228 | spa.Points = spa.Points.Reverse().ToList();
229 | spa.Renumber();
230 |
231 | Utils.Log(string.Format("ShapePointArray.Reverse completed.", ""));
232 |
233 | return spa;
234 | }
235 |
236 | ///
237 | /// Joins two ShapePoints objects into a new one.
238 | ///
239 | /// The other ShapePointArray.
240 | ///
241 | //[IsVisibleInDynamoLibrary(false)]
242 | public ShapePointArray Join(ShapePointArray other)
243 | {
244 | Utils.Log(string.Format("ShapePointArray.Join started...", ""));
245 |
246 | ShapePointArray spa = this.Copy();
247 |
248 | foreach (ShapePoint p in other.Points)
249 | {
250 | var sp = p.Copy(spa.Points.Count);
251 | spa.Points.Add(sp);
252 | }
253 |
254 | Utils.Log(string.Format("ShapePointArray.Join completed.", ""));
255 |
256 | return spa;
257 | }
258 |
259 | ///
260 | /// Returns a that represents this instance.
261 | ///
262 | ///
263 | /// A that represents this instance.
264 | ///
265 | public override string ToString()
266 | {
267 | return string.Format("ShapePointArray(Count={0})", this.Count);
268 | }
269 | #endregion
270 | }
271 | }
272 |
--------------------------------------------------------------------------------
/Autodesk2024/AbstractMEPCurve.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.DesignScript.Runtime;
15 | using Autodesk.Revit.DB;
16 |
17 | using Revit.GeometryConversion;
18 |
19 | using RevitServices.Persistence;
20 | using RevitServices.Transactions;
21 |
22 |
23 | namespace CivilConnection
24 | {
25 | ///
26 | /// AbstratMEPCurve object Type. Base class for Revti MEP Curve objects.
27 | ///
28 | ///
29 | [DynamoServices.RegisterForTrace()]
30 | [IsVisibleInDynamoLibrary(false)]
31 | public abstract class AbstractMEPCurve : Revit.Elements.Element
32 | {
33 | #region PRIVATE MEMBERS
34 |
35 | ///
36 | /// Gets the internal mep curve.
37 | ///
38 | ///
39 | /// The internal mep curve.
40 | ///
41 | internal Autodesk.Revit.DB.MEPCurve InternalMEPCurve
42 | {
43 | get;
44 | private set;
45 | }
46 |
47 | #endregion
48 |
49 | #region PUBLIC PROPERTIES
50 |
51 | ///
52 | /// A reference to the element
53 | ///
54 | public override Autodesk.Revit.DB.Element InternalElement
55 | {
56 | get { return InternalMEPCurve; }
57 | }
58 |
59 | ///
60 | /// Gets or sets the location.
61 | ///
62 | ///
63 | /// The location.
64 | ///
65 | public Autodesk.DesignScript.Geometry.Curve Location
66 | {
67 | get
68 | {
69 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
70 | DocumentManager.Regenerate();
71 | var pos = InternalMEPCurve.Location as LocationCurve;
72 | TransactionManager.Instance.TransactionTaskDone();
73 | return pos.Curve.ToProtoType();
74 | }
75 | set
76 | {
77 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
78 | DocumentManager.Regenerate();
79 | var pos = InternalMEPCurve.Location as LocationCurve;
80 | pos.Curve = value.ToRevitType();
81 | TransactionManager.Instance.TransactionTaskDone();
82 | }
83 | }
84 |
85 | ///
86 | /// Gets the MEP system.
87 | ///
88 | ///
89 | /// The system.
90 | ///
91 | public Revit.Elements.Element System
92 | {
93 | get
94 | {
95 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
96 | DocumentManager.Regenerate();
97 | var sys = InternalMEPCurve.MEPSystem as MEPSystem;
98 | TransactionManager.Instance.TransactionTaskDone();
99 | return Revit.Elements.ElementSelector.ByUniqueId(sys.UniqueId);
100 | }
101 | }
102 |
103 | ///
104 | /// Gets the width.
105 | ///
106 | ///
107 | /// The width.
108 | ///
109 | public double Width
110 | {
111 | get
112 | {
113 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
114 | DocumentManager.Regenerate();
115 | double d = InternalMEPCurve.Width;
116 | TransactionManager.Instance.TransactionTaskDone();
117 | return UtilsObjectsLocation.FeetToMm(d);
118 | }
119 | }
120 |
121 | ///
122 | /// Gets the height.
123 | ///
124 | ///
125 | /// The height.
126 | ///
127 | public double Height
128 | {
129 | get
130 | {
131 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
132 | DocumentManager.Regenerate();
133 | double d = InternalMEPCurve.Height;
134 | TransactionManager.Instance.TransactionTaskDone();
135 | return UtilsObjectsLocation.FeetToMm(d);
136 | }
137 | }
138 |
139 | ///
140 | /// Gets the level offset.
141 | ///
142 | ///
143 | /// The level offset.
144 | ///
145 | public double LevelOffset
146 | {
147 | get
148 | {
149 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
150 | DocumentManager.Regenerate();
151 | double d = InternalMEPCurve.LevelOffset;
152 | TransactionManager.Instance.TransactionTaskDone();
153 | return d;
154 | }
155 | }
156 |
157 | #endregion
158 |
159 | #region CONSTRUCTORS
160 |
161 | ///
162 | /// Internals the set mep curve.
163 | ///
164 | /// The MEPCurve instance
165 | protected void InternalSetMEPCurve(Autodesk.Revit.DB.MEPCurve fi)
166 | {
167 | this.InternalMEPCurve = fi;
168 | this.InternalElementId = fi.Id;
169 | this.InternalUniqueId = fi.UniqueId;
170 | }
171 |
172 | #endregion
173 |
174 | #region PRIVATE METHODS
175 |
176 | ///
177 | /// Internals the type of the set mep curve.
178 | ///
179 | /// The type.
180 | protected void InternalSetMEPCurveType(Autodesk.Revit.DB.MEPCurveType type)
181 | {
182 | if (InternalMEPCurve.GetTypeId().Value.Equals(type.Id.Value))
183 | return;
184 |
185 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
186 |
187 | InternalMEPCurve.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).Set(type.Id);
188 |
189 | TransactionManager.Instance.TransactionTaskDone();
190 | }
191 |
192 | ///
193 | /// Internals the set position.
194 | ///
195 | /// The start point.
196 | /// The end point.
197 | protected void InternalSetPosition(XYZ start, XYZ end)
198 | {
199 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
200 |
201 | var lp = InternalMEPCurve.Location as LocationCurve;
202 | if (lp != null && !lp.Curve.ToProtoType().IsAlmostEqualTo(Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(start.ToPoint(), end.ToPoint()))) lp.Curve = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(start.ToPoint(), end.ToPoint()).ToRevitType();
203 |
204 | TransactionManager.Instance.TransactionTaskDone();
205 | }
206 |
207 | #endregion
208 |
209 | #region PUBLIC METHODS
210 | ///
211 | /// Connectors on the MEPCurve.
212 | ///
213 | ///
214 | public CivilConnection.MEP.Connector[] Connectors()
215 | {
216 | Utils.Log(string.Format("AbstractMEPCurve.Connectors started...", ""));
217 |
218 | CivilConnection.MEP.Connector[] connectors = new CivilConnection.MEP.Connector[InternalMEPCurve.ConnectorManager.Connectors.Size];
219 | int i = 0;
220 |
221 | foreach (Autodesk.Revit.DB.Connector c in InternalMEPCurve.ConnectorManager.Connectors)
222 | {
223 | connectors[i] = new CivilConnection.MEP.Connector(c);
224 | i = i + 1;
225 |
226 | }
227 |
228 | Utils.Log(string.Format("AbstractMEPCurve.Connectors completed.", ""));
229 |
230 | return connectors;
231 | }
232 |
233 | ///
234 | /// Returns a text that represents this instance.
235 | ///
236 | ///
237 | /// A text that represents this instance.
238 | ///
239 | public override string ToString()
240 | {
241 | if (InternalMEPCurve != null && InternalMEPCurve.IsValidObject)
242 | return string.Format("{2}(System={0}, Name={1})", InternalMEPCurve.MEPSystem.Name, InternalMEPCurve.Name, this.Name);
243 |
244 | return string.Format("{2}(System={0}, Name={1})", "empty", "empty", this.Name);
245 | }
246 |
247 | #endregion
248 | }
249 | }
--------------------------------------------------------------------------------
/Autodesk2024/Connector.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.DesignScript.Runtime;
15 | using Autodesk.Revit.DB;
16 |
17 | using RevitServices.Persistence;
18 | using RevitServices.Transactions;
19 |
20 |
21 | namespace CivilConnection.MEP
22 | {
23 | ///
24 | /// Connector object type.
25 | ///
26 | ///
27 | [DynamoServices.RegisterForTrace]
28 | [IsVisibleInDynamoLibrary(false)]
29 | [SupressImportIntoVM]
30 | public class Connector : Revit.Elements.Element
31 | {
32 | #region PRIVATE PROPERTIES
33 |
34 | ///
35 | /// Gets the internal connector.
36 | ///
37 | ///
38 | /// The internal connector.
39 | ///
40 | internal Autodesk.Revit.DB.Connector InternalConnector
41 | {
42 | get;
43 | private set;
44 | }
45 |
46 | #endregion
47 |
48 | #region PUBLIC PROPERTIES
49 |
50 | ///
51 | /// Gets the origin.
52 | ///
53 | ///
54 | /// The origin.
55 | ///
56 | public XYZ Origin { get; private set; }
57 |
58 | ///
59 | /// Gets the mep system.
60 | ///
61 | ///
62 | /// The mep system.
63 | ///
64 | public MEPSystem MEPSystem { get; private set; }
65 |
66 | ///
67 | /// Gets the connector manager.
68 | ///
69 | ///
70 | /// The connector manager.
71 | ///
72 | public ConnectorManager ConnectorManager { get; private set; }
73 |
74 | ///
75 | /// Gets all refs.
76 | ///
77 | ///
78 | /// All refs.
79 | ///
80 | public ConnectorSet AllRefs { get; private set; }
81 |
82 | ///
83 | /// Gets the domain.
84 | ///
85 | ///
86 | /// The domain.
87 | ///
88 | public Autodesk.Revit.DB.Domain Domain { get; private set; }
89 |
90 | ///
91 | /// Gets the direction.
92 | ///
93 | ///
94 | /// The direction.
95 | ///
96 | public XYZ Direction { get; private set; }
97 |
98 | ///
99 | /// Gets the owner.
100 | ///
101 | ///
102 | /// The owner.
103 | ///
104 | public Autodesk.Revit.DB.Element Owner { get; private set; }
105 |
106 | ///
107 | /// Gets the type of the connector.
108 | ///
109 | ///
110 | /// The type of the connector.
111 | ///
112 | public Autodesk.Revit.DB.ConnectorType ConnectorType { get; private set; }
113 |
114 | ///
115 | /// Gets the internal coordiante system.
116 | ///
117 | ///
118 | /// The internal coordiante system.
119 | ///
120 | public Autodesk.Revit.DB.Transform InternalCoordianteSystem { get; private set; }
121 |
122 | ///
123 | /// Gets a value indicating whether this instance is connected.
124 | ///
125 | ///
126 | /// true if this instance is connected; otherwise, false.
127 | ///
128 | public bool IsConnected { get; private set; }
129 |
130 | ///
131 | /// Gets the shape.
132 | ///
133 | ///
134 | /// The shape.
135 | ///
136 | public Autodesk.Revit.DB.ConnectorProfileType Shape { get; private set; }
137 |
138 | ///
139 | /// Gets the connector identifier.
140 | ///
141 | ///
142 | /// The connector identifier.
143 | ///
144 | public int ConnectorId { get; private set; }
145 |
146 | ///
147 | /// A reference to the element
148 | ///
149 | public override Autodesk.Revit.DB.Element InternalElement
150 | {
151 | get
152 | {
153 | return Owner;
154 | }
155 | }
156 |
157 | #endregion
158 |
159 | #region PRIVATE METHODS
160 |
161 | ///
162 | /// Internals the set connector.
163 | ///
164 | /// The Revit connector
165 | protected void InternalSetConnector(Autodesk.Revit.DB.Connector fi)
166 | {
167 | this.InternalConnector = fi;
168 | this.ConnectorId = fi.Id;
169 | this.InternalElementId = fi.Owner.Id;
170 | this.InternalUniqueId = fi.Owner.UniqueId;
171 | this.AllRefs = fi.AllRefs;
172 | this.ConnectorManager = fi.ConnectorManager;
173 | this.ConnectorType = fi.ConnectorType;
174 | this.Domain = fi.Domain;
175 | this.IsConnected = fi.IsConnected;
176 | this.MEPSystem = fi.MEPSystem;
177 | this.Origin = fi.Origin;
178 | this.Owner = fi.Owner;
179 | this.Shape = fi.Shape;
180 | this.InternalCoordianteSystem = fi.CoordinateSystem;
181 | }
182 |
183 | ///
184 | /// Method to set the angle.
185 | ///
186 | /// The angle.
187 | protected void InternalSetAngle(double angle)
188 | {
189 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
190 |
191 | InternalConnector.Angle = angle;
192 |
193 | TransactionManager.Instance.TransactionTaskDone();
194 | }
195 |
196 | ///
197 | /// Method to set the height.
198 | ///
199 | /// The height.
200 | protected void InternalSetHeight(double height)
201 | {
202 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
203 |
204 | if (this.Shape == ConnectorProfileType.Rectangular)
205 | {
206 | InternalConnector.Height = height;
207 | }
208 |
209 | TransactionManager.Instance.TransactionTaskDone();
210 | }
211 |
212 | ///
213 | /// Internals the set origin.
214 | ///
215 | /// The origin.
216 | protected void InternalSetOrigin(Autodesk.Revit.DB.XYZ origin)
217 | {
218 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
219 |
220 | InternalConnector.Origin = origin;
221 |
222 | TransactionManager.Instance.TransactionTaskDone();
223 | }
224 |
225 | ///
226 | /// Method to set the radius.
227 | ///
228 | /// The radius.
229 | protected void InternalSetRadius(double radius)
230 | {
231 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
232 |
233 | if (this.Shape == ConnectorProfileType.Round)
234 | {
235 | InternalConnector.Radius = radius;
236 | }
237 |
238 | TransactionManager.Instance.TransactionTaskDone();
239 | }
240 |
241 | ///
242 | /// Method to set the width.
243 | ///
244 | /// The width.
245 | protected void InternalSetWidth(double width)
246 | {
247 | TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
248 |
249 | if (this.Shape == ConnectorProfileType.Rectangular)
250 | {
251 | InternalConnector.Width = width;
252 | }
253 |
254 | TransactionManager.Instance.TransactionTaskDone();
255 | }
256 |
257 | ///
258 | /// Initialize a Connector
259 | ///
260 | /// The instance.
261 | private void InitObject(Autodesk.Revit.DB.Connector instance)
262 | {
263 | InternalSetConnector(instance);
264 | }
265 |
266 | #endregion
267 |
268 | #region CONSTRUCTOR
269 | ///
270 | /// Initializes a new instance of the class.
271 | ///
272 | /// The instance.
273 | public Connector(Autodesk.Revit.DB.Connector instance)
274 | {
275 | SafeInit(() => InitObject(instance));
276 | }
277 |
278 | #endregion
279 |
280 | #region PUBLIC METHODS
281 |
282 | #endregion
283 | }
284 | }
285 |
--------------------------------------------------------------------------------
/Autodesk2024/TBMTunnel.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using System;
15 | using Autodesk.DesignScript.Geometry;
16 | using System.Collections.Generic;
17 | using System.Linq;
18 | using Autodesk.DesignScript.Runtime;
19 |
20 | namespace CivilConnection.Tunnel
21 | {
22 | ///
23 | /// Tunnel Bored Machine Tunnel object type.
24 | ///
25 | [IsVisibleInDynamoLibrary(true)]
26 | public class TbmTunnel
27 | {
28 | #region PRIVATE PROPERTIES
29 | Solid _ringSolid;
30 | # endregion
31 |
32 | #region PUBLIC PROPERTIES
33 | ///
34 | /// Gets the baseline curve.
35 | ///
36 | ///
37 | /// The baseline.
38 | ///
39 | public Curve Baseline { get; private set; }
40 | ///
41 | /// Gets the length.
42 | ///
43 | ///
44 | /// The length.
45 | ///
46 | public double Length { get { return PolyCurve.ByPoints(this.Points).Length; } }
47 | ///
48 | /// Gets the rings.
49 | ///
50 | ///
51 | /// The rings.
52 | ///
53 | public IList Rings { get; private set;}
54 | ///
55 | /// Gets the ring solids.
56 | ///
57 | ///
58 | /// The ring solids.
59 | ///
60 | public IList RingSolids
61 | {
62 | get
63 | {
64 | IList output = new List();
65 |
66 | foreach (Ring r in this.Rings)
67 | {
68 | Solid rs = this._ringSolid.Transform(r.StartCS) as Solid;
69 |
70 | r.RingSolid = rs;
71 |
72 | output.Add(rs);
73 | }
74 | return output;
75 | }
76 | }
77 | ///
78 | /// Gets the solid of the base ring for the tunnel.
79 | ///
80 | ///
81 | /// The ring solid.
82 | ///
83 | public Solid BaseRingSolid
84 | {
85 | get
86 | {
87 | return this._ringSolid;
88 | }
89 | set
90 | {
91 | this._ringSolid = value;
92 | }
93 | }
94 | ///
95 | /// Gets the angles.
96 | ///
97 | ///
98 | /// The angles.
99 | ///
100 | public IList Angles
101 | {
102 | get
103 | {
104 | return this.Rings.Select(x => x.Angle).ToList();
105 | }
106 | }
107 | ///
108 | /// Gets the points.
109 | ///
110 | ///
111 | /// The points.
112 | ///
113 | public IList Points
114 | {
115 | get
116 | {
117 | var pts = this.Rings.Select(x => x.Line.StartPoint).ToList();
118 | pts.Add(this.Rings.Last().Line.EndPoint);
119 | return pts;
120 | }
121 | }
122 |
123 | #endregion
124 |
125 | #region CONSTRUCTOR
126 | ///
127 | /// Initializes a new instance of the class.
128 | ///
129 | internal TbmTunnel()
130 | {
131 | this.Baseline = null;
132 | this.Rings = new List();
133 | }
134 |
135 | #endregion
136 |
137 | #region PUBLIC CONSTRUCTORS
138 | ///
139 | /// Bies the baseline ring.
140 | ///
141 | /// The baseline.
142 | /// The ring.
143 | ///
144 | public static TbmTunnel ByBaselineRing(Curve baseline, Ring ring)
145 | {
146 | Utils.Log(string.Format("TbmTunnel.ByBaselineRing started...", ""));
147 |
148 | var output = new TbmTunnel();
149 |
150 | try
151 | {
152 | output._ringSolid = new Ring(ring.InternalRadius, ring.Thickness, ring.Offset, ring.Depth, 0, CoordinateSystem.Identity()).RingSolid;
153 |
154 | output.Baseline = baseline;
155 |
156 | var pts = Featureline.PointsByChord(baseline, ring.Line.Length);
157 |
158 | Vector yaxis = Vector.ByTwoPoints(pts[0], pts[1]).Normalized();
159 | Vector xaxis = yaxis.Cross(Vector.ZAxis());
160 |
161 | Utils.Log(string.Format("Points: {0}", pts.Count));
162 |
163 | CoordinateSystem cs = CoordinateSystem.ByOriginVectors(pts[0], xaxis, yaxis);
164 | cs = cs.Rotate(cs.ZXPlane, -ring.Angle);
165 |
166 | Plane plane = null;
167 | Point intersection = null;
168 | Vector v = null;
169 | Point center = null;
170 | Circle circle = null;
171 |
172 | Utils.Log(string.Format("Ring {0}", 0));
173 |
174 | Ring newRing = null;
175 |
176 | newRing = ring.Transform(cs);
177 |
178 | output.Rings.Add(newRing);
179 |
180 | for (int i = 0; i < pts.Count; ++i )
181 | {
182 | Utils.Log(string.Format("Ring {0}", output.Rings.Count));
183 |
184 | try
185 | {
186 | Ring lastRing = output.Rings.Last();
187 |
188 | Utils.Log(string.Format("Last Ring Found", ""));
189 |
190 | plane = lastRing.BackCS.ZXPlane.Offset(ring.Lambda);
191 | center = lastRing.BackCS.Origin.Add(lastRing.BackCS.YAxis.Scale(ring.Lambda));
192 |
193 | if (center.DistanceTo(baseline) > baseline.Length / 2)
194 | {
195 | Utils.Log(string.Format("Projection too far away from baseline: {0}", plane.Origin));
196 |
197 | break;
198 | }
199 |
200 | Utils.Log(string.Format("Center {0}", center));
201 |
202 | plane = Plane.ByOriginNormal(center, lastRing.BackCS.YAxis);
203 |
204 | Utils.Log(string.Format("Plane {0}", plane));
205 |
206 | circle = Circle.ByPlaneRadius(plane, ring.Rho);
207 |
208 | Utils.Log(string.Format("Circle {0}", circle));
209 |
210 | intersection = circle.ClosestPointTo(baseline);
211 |
212 | Utils.Log(string.Format("Intersection {0}", intersection));
213 |
214 | if (null != intersection)
215 | {
216 | double angle = 0;
217 |
218 | if (intersection.DistanceTo(center) > 0.0001)
219 | {
220 | v = Vector.ByTwoPoints(center, intersection);
221 |
222 | Utils.Log(string.Format("Vector {0}", v));
223 |
224 | angle = Math.Round(lastRing.BackCS.ZAxis.AngleAboutAxis(v, plane.Normal), 5);
225 |
226 | Utils.Log(string.Format("Angle {0}", angle));
227 | }
228 |
229 | newRing = lastRing.Following(angle);
230 | }
231 | else
232 | {
233 | Utils.Log(string.Format("Ring calculation stopped!!!", ""));
234 |
235 | break;
236 | }
237 |
238 | intersection = null;
239 |
240 | if (null != newRing)
241 | {
242 | output.Rings.Add(newRing);
243 |
244 | newRing = null;
245 |
246 | Utils.Log(string.Format("Ring added.", ""));
247 | }
248 | else
249 | {
250 | Utils.Log(string.Format("ERROR 2: Ring null.", ""));
251 | break;
252 | }
253 | }
254 | catch (Exception ex)
255 | {
256 | Utils.Log(string.Format("ERROR 1: {0}", ex.Message));
257 | break;
258 | }
259 | }
260 |
261 | // Disposing these objects cause a failure at runtime
262 |
263 | //cs.Dispose();
264 | //plane.Dispose();
265 | //intersection.Dispose();
266 | //v.Dispose();
267 | //yaxis.Dispose();
268 | //xaxis.Dispose();
269 | }
270 | catch (Exception ex)
271 | {
272 | Utils.Log(string.Format("ERROR 0: {0}", ex.Message));
273 | }
274 |
275 | Utils.Log(string.Format("TbmTunnel.ByBaselineRing completed", ""));
276 |
277 | return output;
278 | }
279 |
280 | #endregion
281 |
282 | #region PUBLIC METHODS
283 |
284 | ///
285 | /// Returns a that represents this instance.
286 | ///
287 | ///
288 | /// A that represents this instance.
289 | ///
290 | public override string ToString()
291 | {
292 | return string.Format("TbmTunnel(Baseline = {0}, Length = {1:0.000}, Rings = {2})", this.Baseline, this.Length, this.Rings.Count);
293 | }
294 | #endregion
295 | }
296 | }
297 |
--------------------------------------------------------------------------------
/Autodesk2024/LandFeatureline.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | using System.Runtime;
21 | using System.Runtime.InteropServices;
22 |
23 | using System.IO;
24 | using System.Xml;
25 |
26 | using Autodesk.AutoCAD.Interop;
27 | using Autodesk.AutoCAD.Interop.Common;
28 | using Autodesk.AECC.Interop.UiRoadway;
29 | using Autodesk.AECC.Interop.Roadway;
30 | using Autodesk.AECC.Interop.Land;
31 | using Autodesk.AECC.Interop.UiLand;
32 | using System.Reflection;
33 |
34 | using Autodesk.DesignScript.Runtime;
35 | using Autodesk.DesignScript.Geometry;
36 | using Autodesk.DesignScript.Interfaces;
37 |
38 | using System.Dynamic;
39 |
40 | namespace CivilConnection
41 | {
42 | ///
43 | /// LandFeatureline object type.
44 | ///
45 | public class LandFeatureline
46 | {
47 | #region PRIVATE PROPERTIES
48 | ///
49 | /// The name
50 | ///
51 | string _name;
52 | ///
53 | /// The polycurve
54 | ///
55 | PolyCurve _polycurve;
56 | ///
57 | /// The LandFeatureline
58 | ///
59 | internal AeccLandFeatureLine _featureline;
60 | ///
61 | /// The minimum grade
62 | ///
63 | double _minGrade;
64 | ///
65 | /// The minimum elevation
66 | ///
67 | double _minElevation;
68 | ///
69 | /// The maximum grade
70 | ///
71 | double _maxGrade;
72 | ///
73 | /// The maximum elevation
74 | ///
75 | double _maxElevation;
76 | ///
77 | /// The coordinates
78 | ///
79 | double[] _coordinates;
80 | ///
81 | /// The style
82 | ///
83 | string _style;
84 | ///
85 | /// The points of the LandFeatureline
86 | ///
87 | IList _points = new List();
88 | #endregion
89 |
90 | #region PUBLIC PROPERTIES
91 | ///
92 | /// Gets the name.
93 | ///
94 | ///
95 | /// The name.
96 | ///
97 | public string Name { get { return this._name; } set { this._name = value; } }
98 | ///
99 | /// Gets the curve.
100 | ///
101 | ///
102 | /// The curve.
103 | ///
104 | public PolyCurve Curve { get { return this._polycurve; } }
105 | ///
106 | /// Gets the style.
107 | ///
108 | ///
109 | /// The style.
110 | ///
111 | public string Style { get { return this._style; } }
112 | ///
113 | /// Gets the minimum grade.
114 | ///
115 | ///
116 | /// The minimum grade.
117 | ///
118 | public double MinGrade { get { return this._minGrade; } }
119 | ///
120 | /// Gets the maximum grade.
121 | ///
122 | ///
123 | /// The maximum grade.
124 | ///
125 | public double MaxGrade { get { return this._maxGrade; } }
126 | ///
127 | /// Gets the minimum elevation.
128 | ///
129 | ///
130 | /// The minimum elevation.
131 | ///
132 | public double MinElevation { get { return this._minElevation; } }
133 | ///
134 | /// Gets the maximum elevation.
135 | ///
136 | ///
137 | /// The maximum elevation.
138 | ///
139 | public double MaxElevation { get { return this._maxElevation; } }
140 |
141 | ///
142 | /// Gets the LandFeatureline points.
143 | ///
144 | public IList Points
145 | {
146 | get
147 | {
148 | if (this._points.Count == 0)
149 | {
150 | foreach (Curve c in this._polycurve.Curves())
151 | {
152 | this._points.Add(c.StartPoint);
153 | }
154 |
155 | this._points.Add(this._polycurve.EndPoint);
156 | }
157 |
158 | return this._points;
159 | }
160 | }
161 | #endregion
162 |
163 | #region CONSTRUCTOR
164 |
165 | ///
166 | /// Initializes a new instance of the class.
167 | ///
168 | /// The AeccLandFeatureline.
169 | /// The PolyCurve.
170 | /// The style name.
171 | internal LandFeatureline(AeccLandFeatureLine fl, PolyCurve pc, string style = "")
172 | {
173 | this._featureline = fl;
174 | this._name = fl.Name;
175 | this._minGrade = fl.MiniGrade;
176 | this._minElevation = fl.MiniElevation;
177 | this._maxElevation = fl.MaxElevation;
178 | this._maxGrade = fl.MaxGrade;
179 | this._polycurve = pc;
180 | this._style = style;
181 | }
182 |
183 | ///
184 | /// Initializes a new instance of the class.
185 | ///
186 | /// The AeccLandFeatureline.
187 | /// The style name.
188 | ///
189 | [SupressImportIntoVM]
190 | internal LandFeatureline(AeccLandFeatureLine fl, string style = "")
191 | {
192 | if (fl == null)
193 | {
194 | return;
195 | }
196 |
197 | this._featureline = fl;
198 | this._name = fl.Name;
199 | this._minGrade = fl.MiniGrade;
200 | this._minElevation = fl.MiniElevation;
201 | this._maxElevation = fl.MaxElevation;
202 | this._maxGrade = fl.MaxGrade;
203 |
204 | this._style = style;
205 |
206 | // Andrew Milford - Using reflection does not crash Dynamo
207 | Type fltype = fl.GetType();
208 |
209 | if (fltype != null)
210 | {
211 | try
212 | {
213 | dynamic coord = fltype.InvokeMember("GetPoints",
214 | BindingFlags.InvokeMethod,
215 | System.Type.DefaultBinder,
216 | fl,
217 | new object[] { AeccLandFeatureLinePointType.aeccLandFeatureLinePointPI });
218 |
219 | IList points = new List();
220 |
221 | for (int i = 0; i < coord.Length; i = i + 3)
222 | {
223 | double x = coord[i];
224 | double y = coord[i + 1];
225 | double z = coord[i + 2];
226 |
227 | points.Add(Point.ByCoordinates(x, y, z));
228 | }
229 |
230 | if (points.Count > 1)
231 | {
232 | try
233 | {
234 | PolyCurve pc = PolyCurve.ByPoints(Point.PruneDuplicates(points));
235 | this._polycurve = pc;
236 | }
237 | catch
238 | {
239 | // Not all Polycurves are branching
240 | this._polycurve = null;
241 | }
242 | }
243 | }
244 | catch { }
245 | }
246 | }
247 | #endregion
248 |
249 | #region PRIVATE METHODS
250 |
251 |
252 | #endregion
253 |
254 | #region PUBLIC METHODS
255 |
256 | ///
257 | /// Gets all the LandFeaturelines from a CivilDocument.
258 | /// The Style will be empty by default.
259 | /// Not all the PolyCurves will be branching and it is to be expected to have null values.
260 | ///
261 | /// The CivilDocument
262 | ///
263 | public static IList GetDocumentLandFeaturelines(CivilDocument civilDocument)
264 | {
265 | Utils.Log(string.Format("LandFeatureline.GetDocumentLandFeaturelines started...", ""));
266 |
267 | IList output = civilDocument.GetLandFeaturelines();
268 |
269 | Utils.Log(string.Format("LandFeatureline.GetDocumentLandFeaturelines completed.", ""));
270 |
271 | return output;
272 | }
273 |
274 | ///
275 | /// Creates LandFeatureline
276 | ///
277 | /// The featureline COM object
278 | /// The polycurve
279 | ///
280 | ///
281 | [IsVisibleInDynamoLibrary(false)]
282 | public static LandFeatureline ByObjectPolyCurve(AeccLandFeatureLine fl, PolyCurve polyCurve)
283 | {
284 | return new LandFeatureline(fl, polyCurve);
285 | }
286 |
287 | ///
288 | /// Returns a that represents this instance.
289 | ///
290 | ///
291 | /// A that represents this instance.
292 | ///
293 | public override string ToString()
294 | {
295 | return string.Format("LandFeatureline(Name = {0}, Style = {1})", this.Name, this.Style);
296 | }
297 |
298 | #endregion
299 | }
300 | }
301 |
--------------------------------------------------------------------------------
/Autodesk2024/MultiPoint.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com, atul.tegar@gmail.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.DesignScript.Geometry;
15 | using Autodesk.DesignScript.Runtime;
16 | using DynamoServices;
17 | using Revit.Elements;
18 | using RevitServices.Persistence;
19 | using System;
20 | using System.IO;
21 | using System.Linq;
22 | using System.Xml;
23 | using System.Xml.Serialization;
24 | using ADSK_Parameters = CivilConnection.UtilsObjectsLocation.ADSK_Parameters;
25 |
26 | namespace CivilConnection
27 | {
28 | ///
29 | /// Shape Point Class
30 | ///
31 | //[IsVisibleInDynamoLibrary(false)]
32 | [RegisterForTrace()]
33 | [Newtonsoft.Json.JsonConverter(typeof(MultiPointConverter))]
34 | public class MultiPoint
35 | {
36 | #region PRIVATE PROPERTIES
37 |
38 |
39 | #endregion
40 |
41 | #region PUBLIC PROPERTIES
42 |
43 | ///
44 | /// Gets or sets the shape points.
45 | ///
46 | ///
47 | /// The shape points.
48 | ///
49 | ///
50 | [Newtonsoft.Json.JsonProperty("ShapePoints")]
51 | public ShapePointArray ShapePoints { get; set; }
52 |
53 | #endregion
54 |
55 | #region CONSTRUCTOR
56 |
57 | internal MultiPoint() { }
58 |
59 | ///
60 | /// Initializes a new instance of the class.
61 | ///
62 | /// A ShapePointArray object.
63 | [Newtonsoft.Json.JsonConstructor]
64 | internal MultiPoint(ShapePointArray shapePointArray)
65 | {
66 | this.ShapePoints = shapePointArray;
67 | }
68 |
69 | #endregion
70 |
71 | #region PRIVATE METHODS
72 |
73 | ///
74 | private Element ToHorizontalFloor(FloorType floorType, Level level)
75 | {
76 | Utils.Log(string.Format("MultiPoint.ToHorizontalFloor started...", ""));
77 |
78 | try
79 | {
80 | if (!SessionVariables.ParametersCreated)
81 | {
82 | UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
83 | }
84 |
85 | PolyCurve outline = PolyCurve.ByPoints(this.ShapePoints.Points.Select(p => p.RevitPoint).ToList(), true);
86 |
87 | outline = PolyCurve.ByJoinedCurves(outline.PullOntoPlane(Plane.XY()).Explode().Cast().ToList(),0.001,false,0);
88 |
89 | var output = Floor.ByOutlineTypeAndLevel(outline, floorType, level);
90 |
91 | output.SetParameterByName(ADSK_Parameters.Instance.MultiPoint.Name, SerializeJSON());
92 |
93 | Utils.Log(string.Format("MultiPoint.ToHorizontalFloor completed.", ""));
94 |
95 | return output;
96 | }
97 | catch (Exception ex)
98 | {
99 | Utils.Log(string.Format("ERROR: MultiPoint.ToHorizontalFloor {0}", ex.Message));
100 | throw ex;
101 | }
102 |
103 |
104 | }
105 |
106 | #endregion
107 |
108 | #region PUBLIC METHODS
109 |
110 | ///
111 | /// Returns a MultiPoint by a collection of shape points.
112 | ///
113 | /// The shape points.
114 | ///
115 | public static MultiPoint ByShapePointArray(ShapePointArray shapePointArray)
116 | {
117 | return new MultiPoint(shapePointArray);
118 | }
119 |
120 | ///
121 | /// Returns a MultiPoint by a collection of shape points.
122 | ///
123 | /// The Revit element.
124 | ///
125 | public static MultiPoint ByElement(Element element)
126 | {
127 | string parameter = element.GetParameterValueByName(ADSK_Parameters.Instance.MultiPoint.Name) as string;
128 |
129 | if (parameter != "" && parameter != null)
130 | {
131 | return Newtonsoft.Json.JsonConvert.DeserializeObject(parameter);
132 | }
133 |
134 | return null;
135 | }
136 |
137 | ///
138 | /// Converts the MultiPoint into a floor of the specified type.
139 | ///
140 | /// Type of the floor.
141 | /// The level.
142 | /// if set to true [structural].
143 | ///
144 | public Element ToFloor(FloorType floorType, Level level, bool structural = true)
145 | {
146 | Utils.Log(string.Format("MultiPoint.ToFloor started...", ""));
147 |
148 | try
149 | {
150 | if (!SessionVariables.ParametersCreated)
151 | {
152 | UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
153 | }
154 |
155 | PolyCurve outline = PolyCurve.ByPoints(this.ShapePoints.Points.Select(p => p.RevitPoint).ToList(), true);
156 |
157 | if (null == outline)
158 | {
159 | Utils.Log($"Outline is null");
160 | System.Windows.Forms.MessageBox.Show("Outline is null");
161 | }
162 |
163 | Element output = null;
164 |
165 | try
166 | {
167 | output = SlopedFloor.ByOutlineTypeAndLevel(outline, floorType, level, structural);
168 | }
169 | catch (Exception ex)
170 | {
171 | Utils.Log(string.Format("ERROR: MultiPoint.ToFloor {0}", ex.Message));
172 |
173 | output = Floor.ByOutlineTypeAndLevel(outline, floorType, level);
174 | }
175 |
176 | output.SetParameterByName(ADSK_Parameters.Instance.MultiPoint.Name, this.SerializeJSON());
177 | output.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1);
178 | output.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0);
179 |
180 | Utils.Log(string.Format("MultiPoint.ToFloor completed.", ""));
181 |
182 | return output;
183 | }
184 | catch (Exception ex)
185 | {
186 | Utils.Log(string.Format("ERROR: MultiPoint.ToFloor {0}", ex.Message));
187 | throw ex;
188 | }
189 |
190 |
191 | }
192 |
193 | ///
194 | /// Converts the MultiPoint into an adaptive component of the specified type.
195 | ///
196 | /// Type of the family.
197 | ///
198 | public AdaptiveComponent ToAdaptiveComponent(FamilyType familyType)
199 | {
200 | Utils.Log(string.Format("MultiPoint.ToAdaptiveComponent started...", ""));
201 |
202 | AdaptiveComponent output = null;
203 |
204 | try
205 | {
206 | if (!SessionVariables.ParametersCreated)
207 | {
208 | UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
209 | }
210 |
211 | output = AdaptiveComponent.ByPoints(new Point[][] { this.ShapePoints.Points.Select(p => p.RevitPoint).ToArray() }, familyType)[0];
212 | output.SetParameterByName(ADSK_Parameters.Instance.MultiPoint.Name, this.SerializeJSON());
213 | output.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1);
214 | output.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0);
215 | }
216 | catch (Exception ex)
217 | {
218 | Utils.Log(ex.Message);
219 | }
220 |
221 | Utils.Log(string.Format("MultiPoint.ToAdaptiveComponent completed.", ""));
222 |
223 | return output;
224 | }
225 |
226 | ///
227 | /// Serializes this instance.
228 | ///
229 | ///
230 | [IsVisibleInDynamoLibrary(false)]
231 | public string SerializeXML()
232 | {
233 | Utils.Log(string.Format("MultiPoint.SerializeXML started...", ""));
234 |
235 | XmlSerializer serializer = new XmlSerializer(typeof(MultiPoint));
236 | string xml = "";
237 | using (StringWriter sw = new StringWriter())
238 | {
239 | using (XmlWriter xw = XmlWriter.Create(sw))
240 | {
241 | serializer.Serialize(xw, this);
242 | xml = serializer.ToString();
243 | }
244 | }
245 |
246 | Utils.Log(string.Format("MultiPoint.SerializeXML completed.", ""));
247 |
248 | return xml;
249 | }
250 |
251 | ///
252 | /// Serializes to json.
253 | ///
254 | ///
255 | [IsVisibleInDynamoLibrary(false)]
256 | public string SerializeJSON()
257 | {
258 | Utils.Log(string.Format("MultiPoint.SerializeJSON started...", ""));
259 |
260 | string serialized = "";
261 |
262 | try
263 | {
264 | serialized = Newtonsoft.Json.JsonConvert.SerializeObject(this);
265 | }
266 | catch (Exception ex)
267 | {
268 | serialized = ex.Message;
269 | }
270 |
271 | Utils.Log(serialized);
272 |
273 | Utils.Log(string.Format("MultiPoint.SerializeJSON completed.", ""));
274 |
275 | return serialized;
276 | }
277 |
278 | ///
279 | /// Returns a that represents this instance.
280 | ///
281 | ///
282 | /// A that represents this instance.
283 | ///
284 | public override string ToString()
285 | {
286 | return string.Format("MultiPoint({0})",
287 | this.ShapePoints);
288 | }
289 |
290 | #endregion
291 | }
292 | }
--------------------------------------------------------------------------------
/Autodesk2024/CivilApplication.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com, atul.tegar@gmail.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.AECC.Interop.Land;
15 | using Autodesk.AECC.Interop.UiRoadway;
16 | using Autodesk.AutoCAD.Interop;
17 | using Autodesk.DesignScript.Runtime;
18 | using Autodesk.Revit.DB;
19 | using System;
20 | using System.Collections;
21 | using System.Collections.Generic;
22 | using System.Linq;
23 | using System.Runtime.InteropServices;
24 |
25 | namespace CivilConnection
26 | {
27 | ///
28 | /// CivilApplication object type.
29 | ///
30 | public class CivilApplication
31 | {
32 | ///
33 | /// The documents in Civil 3D.
34 | ///
35 | public IList Documents;
36 | ///
37 | /// The land XML path.
38 | ///
39 | public string LandXMLPath;
40 | ///
41 | /// The active document
42 | ///
43 | AcadDocument ActiveDocument;
44 | ///
45 | /// The active application
46 | ///
47 | AeccRoadwayApplication mApp;
48 | ///
49 | /// Gets the internal element.
50 | ///
51 | ///
52 | /// The internal element.
53 | ///
54 | internal object InternalElement { get { return this.mApp; } }
55 |
56 | ///
57 | ///
58 | ///
59 | ///
60 | ///
61 | ///
62 | ///
63 | [DllImport("ole32.dll")]
64 | public static extern int GetActiveObjectExt(ref Guid rclsid, IntPtr reserved, [MarshalAs(UnmanagedType.Interface)] out object ppunk);
65 |
66 | ///
67 | /// Gets the application
68 | ///
69 | ///
70 | ///
71 | internal AeccRoadwayApplication GetApplication()
72 | {
73 | Utils.Log($"GetApplication started...");
74 | string m_sAcadProdID = "AutoCAD.Application";
75 |
76 | string[] progids = null;
77 |
78 | #if C2023
79 | progids = new string[] {"AeccXUiRoadway.AeccRoadwayApplication.13.5"}; // 2023
80 | #elif C2024
81 | progids = new string[] { "AeccXUiRoadway.AeccRoadwayApplication.13.6" }; // 2024
82 | #elif C2025
83 | progids = new string[] { "AeccXUiRoadway.AeccRoadwayApplication.13.7" }; // 2025
84 | #elif C2026
85 | progids = new string[] { "AeccXUiRoadway.AeccRoadwayApplication.13.8" }; // 2026
86 | #endif
87 | AcadApplication m_oAcadApp = null;
88 | try
89 | {
90 | object obj = null;
91 | var type = Type.GetTypeFromProgID(m_sAcadProdID);
92 | var guid = type.GUID;
93 | int result = GetActiveObjectExt(ref guid, IntPtr.Zero, out obj);
94 |
95 | if (obj != null)
96 | {
97 | m_oAcadApp = obj as AcadApplication;
98 | }
99 | }
100 | catch (Exception ex)
101 | {
102 | throw new Exception(ex.Message);
103 | }
104 |
105 | // Roadway Application
106 |
107 | dynamic output = null;
108 |
109 | foreach (string r_sAeccAppProgId in progids)
110 | {
111 | try
112 | {
113 | output = m_oAcadApp.GetInterfaceObject(r_sAeccAppProgId);
114 |
115 | if (output != null)
116 | {
117 | break;
118 | }
119 | }
120 | catch (COMException ex)
121 | {
122 | if (!ex.ToString().Contains("0x800401E3"))
123 | {
124 | throw new Exception("Civil 3D Communication Error");
125 | }
126 | }
127 | catch (Exception)
128 | {
129 |
130 | }
131 | }
132 |
133 | Utils.Log($"GetApplication completed.");
134 | return output;
135 | }
136 |
137 | ///
138 | /// Creates the connection with the running session of Civil 3D.
139 | ///
140 | ///
141 | public CivilApplication()
142 | {
143 | Utils.InitializeLog();
144 | Utils.Log($"CivilApplication.CivilApplication started...");
145 | try
146 | {
147 | this.mApp = this.GetApplication();
148 | }
149 | catch (Exception ex)
150 | {
151 | Utils.Log($"EXCEPTION: {ex.Message}");
152 | }
153 |
154 | if (this.mApp == null)
155 | {
156 | Utils.Log($"ERROR: Cannot connect to the Civil 3D Application");
157 | return;
158 | }
159 |
160 | IList documents = new List();
161 |
162 | foreach (var doc in this.mApp.Documents)
163 | {
164 | documents.Add(new CivilDocument(doc as AeccRoadwayDocument));
165 | }
166 |
167 | this.Documents = documents;
168 | this.ActiveDocument = mApp.ActiveDocument;
169 |
170 | var revitDoc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
171 |
172 | RevitServices.Transactions.TransactionManager.Instance.EnsureInTransaction(revitDoc);
173 |
174 | SetUnits(revitDoc);
175 |
176 | RevitServices.Transactions.TransactionManager.Instance.TransactionTaskDone();
177 |
178 | Utils.Log($"CivilApplication.Units completed.");
179 |
180 | SessionVariables.LandXMLPath = System.IO.Path.GetTempPath();
181 | SessionVariables.IsLandXMLExported = false;
182 | SessionVariables.CivilApplication = this;
183 | SessionVariables.ParametersCreated = false;
184 | SessionVariables.DocumentTotalTransform = null;
185 | RevitUtils.DocumentTotalTransform();
186 | }
187 |
188 | ///
189 | /// Returns the list of Civil Documents opened in Civil 3D.
190 | ///
191 | ///
192 | public IList GetDocuments()
193 | {
194 | return this.Documents;
195 | }
196 |
197 | ///
198 | /// Returns the Civil Documents opened in Civil 3D with the same name.
199 | ///
200 | ///
201 | ///
202 | public CivilDocument GetDocumentByName(string name)
203 | {
204 | return this.Documents.First(x => x.Name == name);
205 | }
206 |
207 | ///
208 | /// Enables the Run Periodically mode and updates the connection with Civil 3D.
209 | ///
210 | ///
211 | [CanUpdatePeriodicallyAttribute(true)]
212 | public CivilApplication UpdatePeriodically()
213 | {
214 | Utils.Log($"CivilApplication.UpdatePeriodically started...");
215 |
216 | return new CivilApplication();
217 | }
218 |
219 | ///
220 | /// Writes a message to the log file
221 | ///
222 | /// The data that is passed through
223 | /// An optional message to write to the log.
224 | ///
225 | public static object WriteToLog(object data, string message = "")
226 | {
227 | Utils.Log(string.Format("{0}{1}", message.Length > 0 ? message + " " : "", data));
228 |
229 | return data;
230 | }
231 |
232 | ///
233 | /// Public textual representation of the Dynamo node preview.
234 | ///
235 | ///
236 | public override string ToString()
237 | {
238 | return $"CivilApplication(ActiveDocument = {this.ActiveDocument.Name})";
239 | }
240 |
241 | ///
242 | /// Setting Revit units based on Civil 3D document units
243 | ///
244 | ///
245 | ///
246 | private void SetUnits(Autodesk.Revit.DB.Document revitDoc)
247 | {
248 | Autodesk.Revit.DB.Units units = revitDoc.GetUnits();
249 | var du = this.Documents.First()._document.Settings.DrawingSettings.UnitZoneSettings.DrawingUnits;
250 | var distPrecision = this.Documents.First()._document.Settings.DrawingSettings.AmbientSettings.DistanceSettings.Precision.Value;
251 | double accuracy = Math.Pow(10, -distPrecision);
252 |
253 | Utils.Log($"CivilApplication.Units started...");
254 |
255 | var unitTypeMapping = new Dictionary
256 | {
257 | {AeccDrawingUnitType.aeccDrawingUnitMeters, UnitTypeId.Meters },
258 | {AeccDrawingUnitType.aeccDrawingUnitDecimeters, UnitTypeId.Decimeters },
259 | {AeccDrawingUnitType.aeccDrawingUnitCentimeters, UnitTypeId.Centimeters },
260 | {AeccDrawingUnitType.aeccDrawingUnitMillimeters, UnitTypeId.Millimeters },
261 | {AeccDrawingUnitType.aeccDrawingUnitFeet, UnitTypeId.Feet },
262 | {AeccDrawingUnitType.aeccDrawingUnitInches, UnitTypeId.Inches }
263 | };
264 |
265 | if(unitTypeMapping.TryGetValue(du,out var unitTypeId))
266 | {
267 | Utils.Log($"Civil Document in {unitTypeId.ToString()}");
268 |
269 | var formatOptions = new FormatOptions(unitTypeId) { Accuracy = accuracy };
270 |
271 | units.SetFormatOptions(SpecTypeId.Length, formatOptions);
272 | }
273 | else
274 | {
275 | throw new Exception("UNITS ERROR\nThe Civil 3D units of the Active Document are not supported in Revit.\nChange the Civil 3D Units to continue");
276 | }
277 |
278 | revitDoc.SetUnits(units);
279 | }
280 | }
281 | }
--------------------------------------------------------------------------------
/Autodesk2024/SlopedFloor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.DesignScript.Geometry;
15 | using Autodesk.DesignScript.Runtime;
16 | using Autodesk.Revit.DB;
17 | using Revit.GeometryConversion;
18 | using RevitServices.Persistence;
19 | using RevitServices.Transactions;
20 | using System;
21 | using System.Linq;
22 |
23 |
24 | namespace CivilConnection
25 | {
26 | ///
27 | /// AbstratMEPCurve object Type. Base class for Revti MEP Curve objects.
28 | ///
29 | ///
30 | [DynamoServices.RegisterForTrace()]
31 | //[IsVisibleInDynamoLibrary(false)]
32 | public class SlopedFloor : Revit.Elements.Element
33 | {
34 | #region PRIVATE PROPERTIES
35 |
36 | ///
37 | /// An internal handle on the Revit floor
38 | ///
39 | internal Autodesk.Revit.DB.Floor InternalFloor
40 | {
41 | get;
42 | private set;
43 | }
44 |
45 | ///
46 | /// Reference to the Element
47 | ///
48 | [SupressImportIntoVM]
49 | public override Autodesk.Revit.DB.Element InternalElement
50 | {
51 | get { return InternalFloor; }
52 | }
53 |
54 | #endregion
55 |
56 | #region PUBLIC PROPERTIES
57 |
58 | ///
59 | /// Gets and sets the FloorType
60 | ///
61 | public Revit.Elements.FloorType Floortype { get; set; }
62 | ///
63 | /// Gets and sets the Level
64 | ///
65 | public Revit.Elements.Level Level { get; set; }
66 | ///
67 | /// Gets and sets if the floor is structural
68 | ///
69 | public bool Structural { get; set; }
70 |
71 | #endregion
72 |
73 | #region CONSTRUCTOR
74 |
75 | ///
76 | /// Private constructor
77 | ///
78 | private SlopedFloor(Autodesk.Revit.DB.Floor floor)
79 | {
80 | SafeInit(() => InitFloor(floor));
81 | }
82 |
83 | ///
84 | /// Private constructor
85 | ///
86 | private SlopedFloor(CurveArray curveArray, Autodesk.Revit.DB.Line slopeArrow, double slope, Autodesk.Revit.DB.FloorType floorType, Autodesk.Revit.DB.Level level, bool structural)
87 | {
88 | SafeInit(() => InitFloor(curveArray, floorType, level, slopeArrow, slope, structural));
89 | }
90 |
91 | #endregion
92 |
93 | #region PRIVATE METHODS
94 |
95 | ///
96 | /// Set the InternalFloor property and the associated element id and unique id
97 | ///
98 | ///
99 | private void InternalSetFloor(Autodesk.Revit.DB.Floor floor)
100 | {
101 | InternalFloor = floor;
102 | InternalElementId = floor.Id;
103 | InternalUniqueId = floor.UniqueId;
104 | }
105 |
106 | ///
107 | /// Initialize a floor element
108 | ///
109 | private void InitFloor(Autodesk.Revit.DB.Floor floor)
110 | {
111 | InternalSetFloor(floor);
112 | }
113 |
114 | ///
115 | /// Initialize a floor element
116 | ///
117 | private void InitFloor(CurveArray curveArray, Autodesk.Revit.DB.FloorType floorType, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Line slopeArrow, double slope, bool structural)
118 | {
119 | Document doc = DocumentManager.Instance.CurrentDBDocument;
120 |
121 | TransactionManager.Instance.EnsureInTransaction(doc);
122 |
123 | if (!SessionVariables.ParametersCreated)
124 | {
125 | UtilsObjectsLocation.CheckParameters(doc);
126 | }
127 |
128 | Autodesk.Revit.DB.Floor floor = null;
129 |
130 | var list = new System.Collections.Generic.List();
131 | foreach (Autodesk.Revit.DB.Curve c in curveArray)
132 | {
133 | list.Add(c);
134 | }
135 |
136 | var cl = CurveLoop.Create(list);
137 |
138 | if (floorType.IsFoundationSlab)
139 | {
140 | // Foundation Slabs require that the profile curves are planar and horizontal
141 | // The normal must be orthogonal to the profile, hence the only possible normal is the Z Axis
142 |
143 | floor = Floor.Create(doc, new System.Collections.Generic.List() {cl}, floorType.Id, level.Id);
144 |
145 | }
146 | else
147 | {
148 | floor = Floor.Create(doc, new System.Collections.Generic.List() { cl }, floorType.Id, level.Id, structural, slopeArrow, slope);
149 |
150 | }
151 |
152 | InternalSetFloor(floor);
153 |
154 | TransactionManager.Instance.TransactionTaskDone();
155 |
156 | ElementBinder.CleanupAndSetElementForTrace(doc, InternalFloor);
157 | }
158 |
159 | #endregion
160 |
161 | #region PUBLIC METHODS
162 |
163 | ///
164 | /// Create a Revit Floor given it's curve outline and Level
165 | ///
166 | /// The outline.
167 | /// Type of the floor.
168 | /// The level.
169 | /// if set to true [structural].
170 | ///
171 | /// The floor
172 | ///
173 | public static SlopedFloor ByOutlineTypeAndLevel(Autodesk.DesignScript.Geometry.PolyCurve outline, Revit.Elements.FloorType floorType, Revit.Elements.Level level, bool structural)
174 | {
175 | Utils.Log(string.Format("SlopedFloor.ByOutlineTypeAndLevel started...", ""));
176 |
177 | try
178 | {
179 | var profile = new CurveArray();
180 |
181 | Autodesk.DesignScript.Geometry.Plane plane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(
182 | outline.Curves().Cast().Select(x => x.StartPoint));
183 |
184 | Vector normal = plane.Normal;
185 | if (normal.Dot(Vector.ZAxis()) <= 0)
186 | {
187 | normal = normal.Reverse();
188 | }
189 |
190 | Autodesk.DesignScript.Geometry.Point origin = plane.Origin;
191 | Autodesk.DesignScript.Geometry.Point end = origin.Add(normal);
192 | Autodesk.DesignScript.Geometry.Point projection = Autodesk.DesignScript.Geometry.Point.ByCoordinates(end.X, end.Y, -1000);
193 | end = Autodesk.DesignScript.Geometry.Point.ByCoordinates(end.X, end.Y, end.Z + 1000);
194 | Autodesk.DesignScript.Geometry.Point intersection = null;
195 | var result = plane.Intersect(Autodesk.DesignScript.Geometry
196 | .Line.ByStartPointEndPoint(end, projection));
197 |
198 | if (result.Length > 0)
199 | {
200 | intersection = result[0] as Autodesk.DesignScript.Geometry.Point;
201 | }
202 | else
203 | {
204 | var message = "Couldn't find intersection";
205 |
206 | Utils.Log(string.Format("ERROR: SlopedFloor.ByOutlineTypeAndLevel {0}", message));
207 |
208 | throw new Exception(message);
209 | }
210 |
211 | Autodesk.DesignScript.Geometry.Curve temp = Autodesk.DesignScript.Geometry.Line.ByBestFitThroughPoints(new Autodesk.DesignScript.Geometry.Point[] { origin, intersection });
212 |
213 | PolyCurve flat = PolyCurve.ByJoinedCurves(outline.PullOntoPlane(Autodesk.DesignScript.Geometry.Plane.XY()
214 | .Offset(temp.StartPoint.Z)).Explode().Cast().ToList(), 0.001, false, 0);
215 |
216 | Autodesk.DesignScript.Geometry.Curve flatLine = temp.PullOntoPlane(Autodesk.DesignScript.Geometry.Plane.XY().Offset(temp.StartPoint.Z));
217 |
218 | if (Math.Abs(Math.Abs(plane.Normal.Dot(Vector.ZAxis())) - 1) < 0.00001)
219 | {
220 | var f = Revit.Elements.Floor.ByOutlineTypeAndLevel(flat, floorType, level);
221 | f.InternalElement.Parameters.Cast()
222 | .First(x => x.Id.Value.Equals(Autodesk.Revit.DB.BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL))
223 | .Set(structural ? 1 : 0);
224 |
225 | plane.Dispose();
226 | flatLine.Dispose();
227 | flat.Dispose();
228 | origin.Dispose();
229 | end.Dispose();
230 | projection.Dispose();
231 | intersection.Dispose();
232 | temp.Dispose();
233 |
234 | return new SlopedFloor(f.InternalElement as Autodesk.Revit.DB.Floor);
235 | }
236 |
237 | double slope = (temp.EndPoint.Z - temp.StartPoint.Z) / flatLine.Length;
238 |
239 | foreach (Autodesk.DesignScript.Geometry.Curve c in flat.Curves())
240 | {
241 | profile.Append(c.ToRevitType());
242 | }
243 |
244 | Autodesk.Revit.DB.Line slopeArrow = flatLine.ToRevitType() as Autodesk.Revit.DB.Line;
245 |
246 | var ft = floorType.InternalElement as Autodesk.Revit.DB.FloorType;
247 | var lvl = level.InternalElement as Autodesk.Revit.DB.Level;
248 |
249 | var floor = new SlopedFloor(profile, slopeArrow, slope, ft, lvl, structural);
250 |
251 | floor.Level = level;
252 | floor.Floortype = floorType;
253 | floor.Structural = structural;
254 |
255 | plane.Dispose();
256 | flatLine.Dispose();
257 | flat.Dispose();
258 | origin.Dispose();
259 | end.Dispose();
260 | projection.Dispose();
261 | intersection.Dispose();
262 | temp.Dispose();
263 |
264 | Utils.Log(string.Format("SlopedFloor.ByOutlineTypeAndLevel completed.", ""));
265 |
266 | return floor;
267 | }
268 | catch (Exception ex)
269 | {
270 | Utils.Log(string.Format("ERROR: SlopedFloor.ByOutlineTypeAndLevel {0}", ex.Message));
271 |
272 | throw ex;
273 | }
274 | }
275 |
276 |
277 | #endregion
278 | }
279 | }
280 |
--------------------------------------------------------------------------------
/Autodesk2024/Autodesk2024.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CivilConnection
5 | net48
6 | true
7 | Debug;Release;2024;2025;2023;2026
8 | 7.3.0.0
9 | 7.3.0.0
10 | true
11 |
12 |
13 | C2023
14 | bin\2023\
15 | bin\2023\Autodesk2023.xml
16 | net48
17 | Autodesk2023
18 |
19 |
20 | C2024
21 | bin\2024\
22 | bin\2024\Autodesk2024.xml
23 | net48
24 | Autodesk2024
25 |
26 |
27 | C2025
28 | bin\2025\
29 | bin\2025\Autodesk2025.xml
30 | net8.0-windows
31 |
32 | true
33 | Autodesk2025
34 | 4
35 |
36 |
37 | C2026
38 | bin\2026\
39 | bin\2026\Autodesk2026.xml
40 | net8.0-windows
41 | true
42 | Autodesk2026
43 | 4
44 |
45 |
46 | C2024
47 | bin\2024\
48 | bin\2024\Autodesk2024.xml
49 | CivilConnection
50 |
51 |
52 |
53 | C2025
54 | bin\2025\
55 | bin\2025\Autodesk2025.xml
56 | CivilConnection
57 |
58 |
59 |
60 | 2023
61 | 2024
62 | 2025
63 | 2026
64 |
65 |
66 | 2.13
67 | 2.19
68 | 3.0
69 | 3.4
70 |
71 |
72 | 2.13
73 | 2.19
74 | 3.0
75 | 3.4
76 |
77 |
78 | C:\Program Files\Autodesk\Revit 2023
79 | C:\Program Files\Autodesk\Revit 2024
80 | C:\Program Files\Autodesk\Revit 2025
81 | C:\Program Files\Autodesk\Revit 2026
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\acdbmgd.dll
91 | False
92 | True
93 | False
94 |
95 |
96 |
97 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\ACA\AecPropDataMgd.dll
98 | False
99 | True
100 | False
101 |
102 |
103 |
104 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\ACA\Autodesk.AEC.Interop.Base.dll
105 | True
106 | True
107 | False
108 |
109 |
110 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\ACA\Autodesk.AEC.Interop.UIBase.dll
111 | True
112 | True
113 | False
114 |
115 |
116 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\C3D\Autodesk.AECC.Interop.Roadway.dll
117 | True
118 | True
119 | False
120 |
121 |
122 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\C3D\Autodesk.AECC.Interop.Land.dll
123 | True
124 | True
125 | False
126 |
127 |
128 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\C3D\Autodesk.AECC.Interop.UiLand.dll
129 | True
130 | True
131 | False
132 |
133 |
134 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\C3D\Autodesk.AECC.Interop.UiRoadway.dll
135 | True
136 | True
137 | False
138 |
139 |
140 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\Autodesk.AutoCAD.Interop.dll
141 | True
142 | True
143 | False
144 |
145 |
146 | C:\Program Files\Autodesk\AutoCAD $(C3DVersion)\Autodesk.AutoCAD.Interop.Common.dll
147 | True
148 | True
149 | False
150 |
151 |
152 | $(DynRevitPath)\AddIns\DynamoForRevit\nodes\CoreNodeModels.dll
153 | False
154 | False
155 |
156 |
157 | $(DynRevitPath)\AddIns\DynamoForRevit\nodes\CoreNodeModelsWpf.dll
158 | False
159 | False
160 |
161 |
162 | C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\CustomMarshalers.dll
163 | True
164 |
165 |
166 | $(DynRevitPath)\AddIns\DynamoForRevit\DSCoreNodes.dll
167 | False
168 | False
169 |
170 |
171 | $(DynRevitPath)\AddIns\DynamoForRevit\DynamoCore.dll
172 | False
173 | False
174 |
175 |
176 | $(DynRevitPath)\AddIns\DynamoForRevit\DynamoCoreWpf.dll
177 | False
178 | False
179 |
180 |
181 | $(DynRevitPath)\AddIns\DynamoForRevit\Revit\DynamoRevitDS.dll
182 | False
183 | False
184 |
185 |
186 | $(DynRevitPath)\AddIns\DynamoForRevit\DynamoServices.dll
187 | False
188 | False
189 |
190 |
191 | False
192 | $(DynRevitPath)\AddIns\DynamoForRevit\NewtonSoft.Json.dll
193 | False
194 | False
195 |
196 |
197 | $(DynRevitPath)\AddIns\DynamoForRevit\ProtoCore.dll
198 | False
199 |
200 |
201 | $(DynRevitPath)\AddIns\DynamoForRevit\ProtoGeometry.dll
202 | False
203 | False
204 |
205 |
206 | $(DynRevitPath)\RevitAPI.dll
207 | False
208 | False
209 |
210 |
211 | $(DynRevitPath)\RevitAPIUI.dll
212 | False
213 | False
214 |
215 |
216 | $(DynRevitPath)\AddIns\DynamoForRevit\Revit\RevitNodes.dll
217 | False
218 | False
219 |
220 |
221 | $(DynRevitPath)\AddIns\DynamoForRevit\Revit\RevitServices.dll
222 | False
223 | False
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
--------------------------------------------------------------------------------
/Autodesk2024/OpeningUtils.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 | using System.Xml;
20 | using System.IO;
21 |
22 | using Revit.Application;
23 | using Revit.Elements.Views;
24 | using Revit.Elements;
25 | using Revit.Transaction;
26 | using RevitServices.Transactions;
27 | using RevitServices.Persistence;
28 |
29 | using Autodesk.DesignScript.Runtime;
30 | using Autodesk.DesignScript.Geometry;
31 | using Revit.GeometryConversion;
32 |
33 | using Autodesk.AECC.Interop.Roadway;
34 | using Autodesk.AECC.Interop.UiRoadway;
35 | using Autodesk.AECC.Interop.Land;
36 | using Autodesk.AECC.Interop.UiLand;
37 |
38 | using Autodesk.AutoCAD.Interop.Common;
39 |
40 | using Autodesk.Revit.DB;
41 |
42 | namespace CivilConnection
43 | {
44 | ///
45 | /// OpeningUtils.
46 | ///
47 | public class OpeningUtils
48 | {
49 | #region PRIVATE PROPERTIES
50 |
51 |
52 | #endregion
53 |
54 | #region PUBLIC PROPERTIES
55 |
56 |
57 | #endregion
58 |
59 | #region CONSTRUCTOR
60 |
61 | ///
62 | /// Initializes a new instance of the class.
63 | ///
64 | internal OpeningUtils()
65 | { }
66 |
67 | #endregion
68 |
69 | #region PRIVATE METHODS
70 |
71 |
72 | #endregion
73 |
74 | #region PUBLIC METHODS
75 |
76 |
77 |
78 | ///
79 | /// Gets the rectangular openings.
80 | ///
81 | ///
82 | /// This method uses walls, doors, windows and generic models bounding boxes to determine the rectangles.
83 | /// These objects can be in the host file or in linked Revit files.
84 | public static IList GetRectangularOpenings()
85 | {
86 | Utils.Log(string.Format("OpeningUtils.GetRectangularOpenings started...", ""));
87 |
88 | Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
89 |
90 | //look for Walls, Doors, Windows, Generic Models in the current document and in the linked documents
91 | ElementCategoryFilter wallFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
92 | ElementCategoryFilter doorFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
93 | ElementCategoryFilter windowFilter = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
94 | ElementCategoryFilter genericFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel);
95 |
96 | IList filterList = new List() { wallFilter, doorFilter, windowFilter, genericFilter };
97 |
98 | LogicalOrFilter orFilter = new LogicalOrFilter(filterList);
99 |
100 | IList solids = new List();
101 |
102 | IList output = new List();
103 |
104 | foreach (Autodesk.Revit.DB.Element e in new FilteredElementCollector(doc)
105 | .WherePasses(orFilter)
106 | .WhereElementIsNotElementType()
107 | .Where(x =>
108 | x.Parameters.Cast()
109 | .First(p => p.Id.Value == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).HasValue))
110 | {
111 | string comments = e.Parameters.Cast().First(p => p.Id.Value == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString();
112 |
113 | if (comments.ToLower() != "opening")
114 | {
115 | continue;
116 | }
117 |
118 | Transform tr = Transform.Identity;
119 |
120 | if (e is Instance)
121 | {
122 | Instance instance = e as Instance;
123 | tr = instance.GetTotalTransform();
124 | }
125 |
126 | IList temp = new List();
127 |
128 | foreach (GeometryObject go in e.get_Geometry(new Options()))
129 | {
130 | if (go is GeometryInstance)
131 | {
132 | GeometryInstance geoInstance = go as GeometryInstance;
133 |
134 | foreach (var gi in geoInstance.SymbolGeometry)
135 | {
136 | if (gi is Autodesk.Revit.DB.Solid)
137 | {
138 | Autodesk.Revit.DB.Solid s = gi as Autodesk.Revit.DB.Solid;
139 | s = SolidUtils.CreateTransformed(s, tr);
140 | temp.Add(s);
141 | }
142 | }
143 | }
144 | else
145 | {
146 | if (go is Autodesk.Revit.DB.Solid)
147 | {
148 | Autodesk.Revit.DB.Solid s = go as Autodesk.Revit.DB.Solid;
149 | s = SolidUtils.CreateTransformed(s, tr);
150 | temp.Add(s);
151 | }
152 | }
153 | }
154 |
155 | if (temp.Count > 0)
156 | {
157 | Autodesk.Revit.DB.Solid s0 = temp[0];
158 | for (int i = 1; i < temp.Count; ++i)
159 | {
160 | s0 = BooleanOperationsUtils.ExecuteBooleanOperation(s0, temp[i], BooleanOperationsType.Union);
161 | }
162 |
163 | solids.Add(s0.ToProtoType());
164 | }
165 | }
166 |
167 | foreach (RevitLinkInstance rli in new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance)).WhereElementIsNotElementType())
168 | {
169 | Autodesk.Revit.DB.Document link = rli.GetLinkDocument();
170 |
171 | foreach (Autodesk.Revit.DB.Element e in new FilteredElementCollector(link)
172 | .WherePasses(orFilter)
173 | .WhereElementIsNotElementType()
174 | .Where(x =>
175 | x.Parameters.Cast()
176 | .First(p => p.Id.Value == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).HasValue))
177 | {
178 | Transform tr = rli.GetTotalTransform();
179 |
180 | string comments = e.Parameters.Cast().First(p => p.Id.Value == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString();
181 |
182 | if (comments.ToLower() != "opening")
183 | {
184 | continue;
185 | }
186 |
187 | if (e is Instance)
188 | {
189 | Instance instance = e as Instance;
190 | tr = tr.Multiply(instance.GetTotalTransform());
191 | }
192 |
193 | IList temp = new List();
194 |
195 | foreach (var go in e.get_Geometry(new Options()))
196 | {
197 | if (go is GeometryInstance)
198 | {
199 | GeometryInstance geoInstance = go as GeometryInstance;
200 |
201 | foreach (var gi in geoInstance.SymbolGeometry)
202 | {
203 | if (gi is Autodesk.Revit.DB.Solid)
204 | {
205 | Autodesk.Revit.DB.Solid s = gi as Autodesk.Revit.DB.Solid;
206 | s = SolidUtils.CreateTransformed(s, tr);
207 | temp.Add(s);
208 | }
209 | }
210 | }
211 | else
212 | {
213 | if (go is Autodesk.Revit.DB.Solid)
214 | {
215 | Autodesk.Revit.DB.Solid s = go as Autodesk.Revit.DB.Solid;
216 | s = SolidUtils.CreateTransformed(s, tr);
217 | temp.Add(s);
218 | }
219 | }
220 | }
221 |
222 | if (temp.Count > 0)
223 | {
224 | Autodesk.Revit.DB.Solid s0 = temp[0];
225 | for (int i = 1; i < temp.Count; ++i)
226 | {
227 | s0 = BooleanOperationsUtils.ExecuteBooleanOperation(s0, temp[i], BooleanOperationsType.Union);
228 | }
229 |
230 | solids.Add(s0.ToProtoType());
231 | }
232 | }
233 | }
234 |
235 | foreach (var s in solids)
236 | {
237 | IList points = new List();
238 |
239 | foreach (var v in s.Vertices)
240 | {
241 | points.Add(v.PointGeometry);
242 | }
243 |
244 | points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points);
245 |
246 | Autodesk.DesignScript.Geometry.Plane plane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(points);
247 |
248 | plane = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(points.Last(), plane.Normal);
249 |
250 | IList temp = new List();
251 |
252 | foreach (var p in points)
253 | {
254 | foreach (var q in p.Project(plane, plane.Normal))
255 | {
256 | temp.Add(q as Autodesk.DesignScript.Geometry.Point);
257 | }
258 |
259 | foreach (var q in p.Project(plane, plane.Normal.Reverse()))
260 | {
261 | temp.Add(q as Autodesk.DesignScript.Geometry.Point);
262 | }
263 | }
264 |
265 | temp = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(temp);
266 |
267 | CoordinateSystem cs = CoordinateSystem.ByPlane(plane);
268 |
269 | IList relative = new List();
270 |
271 | foreach (var p in temp)
272 | {
273 | relative.Add(p.Transform(cs.Inverse()) as Autodesk.DesignScript.Geometry.Point);
274 | }
275 |
276 | var min = Autodesk.DesignScript.Geometry.Point.ByCoordinates(relative.Min(p => p.X),
277 | relative.Min(p => p.Y),
278 | relative.Min(p => p.Z));
279 |
280 | var max = Autodesk.DesignScript.Geometry.Point.ByCoordinates(relative.Max(p => p.X),
281 | relative.Max(p => p.Y),
282 | relative.Max(p => p.Z));
283 |
284 | double width = max.X - min.X;
285 | double height = max.Y - min.Y;
286 |
287 | min = min.Transform(cs) as Autodesk.DesignScript.Geometry.Point;
288 | max = max.Transform(cs) as Autodesk.DesignScript.Geometry.Point;
289 |
290 | plane = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(min, max).PointAtParameter(0.5), plane.Normal);
291 |
292 | Autodesk.DesignScript.Geometry.Rectangle rectangle = Autodesk.DesignScript.Geometry.Rectangle.ByWidthLength(plane,
293 | width,
294 | height);
295 |
296 | output.Add(rectangle);
297 |
298 | plane.Dispose();
299 | cs.Dispose();
300 | min.Dispose();
301 | max.Dispose();
302 | }
303 |
304 | Utils.Log(string.Format("OpeningUtils.GetRectangularOpenings completed.", ""));
305 |
306 | return output;
307 | }
308 |
309 | #endregion
310 |
311 |
312 | }
313 |
314 | }
315 |
--------------------------------------------------------------------------------
/Autodesk2024/ShapePoint.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using Autodesk.DesignScript.Geometry;
15 | using Autodesk.DesignScript.Runtime;
16 | using Newtonsoft.Json;
17 | using System;
18 |
19 |
20 | namespace CivilConnection
21 | {
22 | ///
23 | /// Shape Point Class
24 | ///
25 | //[IsVisibleInDynamoLibrary(false)]
26 |
27 | [JsonConverter(typeof(ShapePointConverter))]
28 | public class ShapePoint
29 | {
30 | #region PRIVATE PROPERTIES
31 | [JsonIgnore]
32 | private int _id = 0;
33 |
34 | #endregion
35 |
36 | #region PUBLIC PROPERTIES
37 | ///
38 | /// Gets the unique identifier.
39 | ///
40 | ///
41 | /// The unique identifier.
42 | ///
43 | [JsonProperty("UniqueId")]
44 | public string UniqueId { get; set; }
45 | ///
46 | /// Gets the identifier.
47 | ///
48 | ///
49 | /// The identifier.
50 | ///
51 | ///
52 | [JsonProperty("Id")]
53 | public int Id { get { return this._id; } set { this._id = value; } }
54 | ///
55 | /// Gets the corridor.
56 | ///
57 | ///
58 | /// The corridor.
59 | ///
60 | ///
61 | [JsonProperty("Corridor")]
62 | public string Corridor { get; set; }
63 | ///
64 | /// Gets the index of the baseline.
65 | ///
66 | ///
67 | /// The index of the baseline.
68 | ///
69 | ///
70 | [JsonProperty("BaselineIndex")]
71 | public int BaselineIndex { get; set; }
72 | ///
73 | /// Gets the side.
74 | ///
75 | ///
76 | /// The side.
77 | ///
78 | ///
79 | [JsonProperty("Side")]
80 | public Featureline.SideType Side { get; set; }
81 | ///
82 | /// Gets the code.
83 | ///
84 | ///
85 | /// The code.
86 | ///
87 | ///
88 | [JsonProperty("Code")]
89 | public string Code { get; set; }
90 | ///
91 | /// Gets the station.
92 | ///
93 | ///
94 | /// The station.
95 | ///
96 | ///
97 | [JsonProperty("Station")]
98 | public double Station { get; set; }
99 | ///
100 | /// Gets the offset.
101 | ///
102 | ///
103 | /// The offset.
104 | ///
105 | ///
106 | [JsonProperty("Offset")]
107 | public double Offset { get; set; }
108 | ///
109 | /// Gets the elevation.
110 | ///
111 | ///
112 | /// The elevation.
113 | ///
114 | [JsonProperty("Elevation")]
115 | public double Elevation { get; set; }
116 | ///
117 | /// Gets the point.
118 | ///
119 | ///
120 | /// The point.
121 | ///
122 | [JsonIgnore]
123 | public Point Point { get; private set; }
124 | ///
125 | /// Gets the featureline.
126 | ///
127 | ///
128 | /// The featureline.
129 | ///
130 | [JsonIgnore]
131 | public Featureline Featureline { get; private set; }
132 |
133 | ///
134 | /// Gets the point in Revit local coordinate system.
135 | ///
136 | ///
137 | /// The revit point.
138 | ///
139 | [JsonIgnore]
140 | public Point RevitPoint { get; private set; }
141 |
142 | ///
143 | /// Gets the Featureline region index
144 | ///
145 | [JsonProperty("RegionIndex")]
146 | public int RegionIndex { get; set; }
147 |
148 | ///
149 | /// Gets the Featureline region index
150 | ///
151 | [JsonProperty("RegionRelative")]
152 | public double RegionRelative { get; set; } // 1.1.0
153 |
154 | ///
155 | /// Gets the Featureline region index
156 | ///
157 | [JsonProperty("RegionNormalized")]
158 | public double RegionNormalized { get; set; } // 1.1.0
159 |
160 | #endregion
161 |
162 | #region CONSTRUCTOR
163 | internal ShapePoint() { }
164 |
165 | ///
166 | /// Initializes a new instance of the class.
167 | ///
168 | /// The point.
169 | /// The featureline.
170 | /// The initial ID of the ShapePoint.
171 | internal ShapePoint(Point point, Featureline featureline, int id = 0)
172 | {
173 | this.UniqueId = Guid.NewGuid().ToString();
174 | this._id = id;
175 |
176 | this.Corridor = featureline.Baseline.CorridorName;
177 | this.BaselineIndex = featureline.Baseline.Index;
178 | this.RegionIndex = featureline.BaselineRegionIndex;
179 |
180 | this.Side = featureline.Side;
181 | this.Code = featureline.Code;
182 |
183 | var soe = featureline.GetStationOffsetElevationByPoint(point);
184 | this.Station = (double)soe["Station"];
185 | this.Offset = (double)soe["Offset"];
186 | this.Elevation = (double)soe["Elevation"];
187 |
188 | this.RegionRelative = this.Station - featureline.Start; // 1.1.0
189 | this.RegionNormalized = this.RegionRelative / (featureline.End - featureline.Start); // 1.1.0
190 |
191 | this.Point = point;
192 | this.Featureline = featureline;
193 |
194 | this.RevitPoint = point.Transform(RevitUtils.DocumentTotalTransform()) as Point;
195 | }
196 |
197 | [JsonConstructor]
198 | internal ShapePoint(string guid, int id, string corridor, int baselineIndex, int regionIndex, double regionRelative,
199 | double regionNormalized, string code, int side, double station, double offset, double elevation) // 1.1.0
200 | {
201 | this.UniqueId = guid;
202 | this.Id = id;
203 |
204 | this.Corridor = corridor;
205 | this.BaselineIndex = baselineIndex;
206 | this.RegionIndex = regionIndex;
207 | this.RegionRelative = regionRelative; // 1.1.0
208 | this.RegionNormalized = regionNormalized; // 1.1.0
209 | this.Code = code;
210 | this.Station = station;
211 | this.Offset = offset;
212 | this.Elevation = elevation;
213 |
214 | if (side == 0)
215 | {
216 | this.Side = CivilConnection.Featureline.SideType.None;
217 | }
218 | else if (side == 1)
219 | {
220 | this.Side = CivilConnection.Featureline.SideType.Left;
221 | }
222 | else if (side == 2)
223 | {
224 | this.Side = CivilConnection.Featureline.SideType.Right;
225 | }
226 | }
227 |
228 | #endregion
229 |
230 | #region PRIVATE METHODS
231 |
232 |
233 | #endregion
234 |
235 | #region PUBLIC METHODS
236 |
237 | ///
238 | /// Bies the point featureline.
239 | ///
240 | /// The point.
241 | /// The featureline.
242 | ///
243 | public static ShapePoint ByPointFeatureline(Point point, Featureline featureline)
244 | {
245 | ShapePoint sp = new ShapePoint(point, featureline);
246 |
247 | return sp;
248 | }
249 |
250 | ///
251 | /// Creates the shapepoint
252 | ///
253 | ///
254 | ///
255 | ///
256 | /// The ShapePoint
257 | ///
258 | public static ShapePoint ByFeaturelineStation(Featureline featureline, double station)
259 | {
260 | Point point = featureline.PointAtStation(station);
261 | ShapePoint sp = new ShapePoint(point, featureline);
262 |
263 | return sp;
264 | }
265 |
266 | ///
267 | /// Copies this instance.
268 | ///
269 | ///
270 | [IsVisibleInDynamoLibrary(false)]
271 | public ShapePoint Copy(int id=0)
272 | {
273 | return new ShapePoint(this.Point, this.Featureline, id);
274 | }
275 |
276 | ///
277 | /// Sets the identifier.
278 | ///
279 | /// The new identifier.
280 | ///
281 | [IsVisibleInDynamoLibrary(false)]
282 | public ShapePoint SetId(int newId)
283 | {
284 | this._id = newId;
285 | return this;
286 | }
287 |
288 | ///
289 | /// Sets the point.
290 | ///
291 | ///
292 | [IsVisibleInDynamoLibrary(false)]
293 | public ShapePoint SetPoint(Point point)
294 | {
295 | this.Point = point;
296 | this.RevitPoint = this.Point.Transform(RevitUtils.DocumentTotalTransform()) as Point;
297 | return this;
298 | }
299 |
300 | ///
301 | /// Calculates the new ShapePoint location on the new Featureline using the Station, Offset and Elevation parameters.
302 | ///
303 | /// The featureline used to update the ShapePoint
304 | ///
305 | public ShapePoint UpdateByFeatureline(Featureline featureline)
306 | {
307 | Utils.Log(string.Format("ShapePoint.UpdateByFeatureline started...", ""));
308 |
309 | var p = featureline.PointByStationOffsetElevation(this.Station, this.Offset, this.Elevation, false);
310 | this.Point = p;
311 | this.RevitPoint = this.Point.Transform(RevitUtils.DocumentTotalTransform()) as Point;
312 | this.Featureline = featureline;
313 |
314 | this.BaselineIndex = featureline.Baseline.Index; // 1.1.0
315 | this.RegionIndex = featureline.BaselineRegionIndex; // 1.1.0
316 | this.RegionRelative = this.Station - featureline.Start; // 1.1.0
317 | this.RegionNormalized = this.RegionRelative / (featureline.End - featureline.Start); // 1.1.0
318 | this.Code = featureline.Code; // 1.1.0
319 | this.Corridor = featureline.Baseline.CorridorName; // 1.1.0
320 | this.Side = featureline.Side; // 1.1.0
321 |
322 | Utils.Log(string.Format("ShapePoint.UpdateByFeatureline completed.", ""));
323 |
324 | return this;
325 | }
326 |
327 |
328 | ///
329 | /// Updates the ShapePoint parameters Station, Offset and Elevation against the new Featureline.
330 | ///
331 | /// The featureline assigned to the ShapePoint
332 | ///
333 | public ShapePoint AssignFeatureline(Featureline featureline) // 1.1.0
334 | {
335 | Utils.Log(string.Format("ShapePoint.AssignFeatureline started...", ""));
336 |
337 | this.Featureline = featureline;
338 |
339 | var soe = featureline.GetStationOffsetElevationByPoint(this.Point);
340 | this.Station = (double)soe["Station"];
341 | this.Offset = (double)soe["Offset"];
342 | this.Elevation = (double)soe["Elevation"];
343 |
344 | this.BaselineIndex = featureline.Baseline.Index;
345 | this.RegionIndex = featureline.BaselineRegionIndex;
346 | this.RegionRelative = this.Station - featureline.Start;
347 | this.RegionNormalized = this.RegionRelative / (featureline.End - featureline.Start);
348 | this.Code = featureline.Code;
349 | this.Corridor = featureline.Baseline.CorridorName;
350 | this.Side = featureline.Side;
351 |
352 | Utils.Log(string.Format("ShapePoint.AssignFeatureline completed.", ""));
353 |
354 | return this;
355 | }
356 |
357 | ///
358 | /// Returns a that represents this instance.
359 | ///
360 | ///
361 | /// A that represents this instance.
362 | ///
363 | public override string ToString()
364 | {
365 | return string.Format("ShapePoint({0}, Id={1}, Code={2}, Corridor={3}, Station={4}, Offset={5}, Elevation={6})",
366 | this.Point,
367 | this.Id,
368 | this.Code,
369 | this.Corridor,
370 | this.Station,
371 | this.Offset,
372 | this.Elevation);
373 | }
374 |
375 | #endregion
376 | }
377 | }
378 |
--------------------------------------------------------------------------------
/Autodesk2024/Profile.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | using System.Runtime;
21 | using System.Runtime.InteropServices;
22 |
23 | using Autodesk.AutoCAD.Interop;
24 | using Autodesk.AutoCAD.Interop.Common;
25 | using Autodesk.AECC.Interop.UiRoadway;
26 | using Autodesk.AECC.Interop.Roadway;
27 | using Autodesk.AECC.Interop.Land;
28 | using Autodesk.AECC.Interop.UiLand;
29 | using System.Reflection;
30 |
31 | using Autodesk.DesignScript.Runtime;
32 | using Autodesk.DesignScript.Geometry;
33 |
34 | namespace CivilConnection
35 | {
36 | ///
37 | /// Profile obejct type.
38 | ///
39 | public class Profile
40 | {
41 | #region PRIVATE PROPERTIES
42 |
43 | ///
44 | /// The profile
45 | ///
46 | private AeccProfile _profile;
47 | ///
48 | /// The entities
49 | ///
50 | private AeccProfileEntities _entities;
51 |
52 | #endregion
53 |
54 | #region PUBLIC PROPERTIES
55 | ///
56 | /// Gets the name.
57 | ///
58 | ///
59 | /// The name.
60 | ///
61 | public string Name { get { return _profile.DisplayName; } }
62 | ///
63 | /// Gets the internal element.
64 | ///
65 | ///
66 | /// The internal element.
67 | ///
68 | internal object InternalElement { get { return this._profile; } }
69 | ///
70 | /// Gets the length.
71 | ///
72 | ///
73 | /// The length.
74 | ///
75 | public double Length { get { return _profile.Length; } }
76 | ///
77 | /// Gets the maximum elevation.
78 | ///
79 | ///
80 | /// The maximum elevation.
81 | ///
82 | public double MaxElevation { get { return _profile.ElevationMax; } }
83 | ///
84 | /// Gets the minimum elevation.
85 | ///
86 | ///
87 | /// The minimum elevation.
88 | ///
89 | public double MinElevation { get { return _profile.ElevationMin; } }
90 | ///
91 | /// Gets the start station.
92 | ///
93 | ///
94 | /// The start station.
95 | ///
96 | public double StartStation { get { return _profile.StartingStation; } }
97 | ///
98 | /// Gets the end station.
99 | ///
100 | ///
101 | /// The end station.
102 | ///
103 | public double EndStation { get { return _profile.EndingStation; } }
104 | ///
105 | /// Gets the weed grade factor.
106 | ///
107 | ///
108 | /// The weed grade factor.
109 | ///
110 | public double WeedGradeFactor { get { return _profile.WeedGradeFactor; } }
111 |
112 | ///
113 | /// Gets the stations of the PVIs.
114 | ///
115 | ///
116 | /// The PVIStations.
117 | ///
118 | public double[] PVIStations { get { return _profile.PVIs.Cast().Select(x => x.Station).ToArray(); } }
119 |
120 | ///
121 | /// Gets the elevation of the PVIs.
122 | ///
123 | ///
124 | /// The PVIElevations.
125 | ///
126 | public double[] PVIElevations { get { return _profile.PVIs.Cast().Select(x => x.Elevation).ToArray(); } }
127 |
128 | ///
129 | /// Gets the grade in of the PVIs.
130 | ///
131 | ///
132 | /// The PVIGradeIns.
133 | ///
134 | private double[] PVIGradeIns { get { return _profile.PVIs.Cast().Select(x => x.GradeIn).ToArray(); } }
135 |
136 | ///
137 | /// Gets the grade out of the PVIs.
138 | ///
139 | ///
140 | /// The PVIGradeOuts.
141 | ///
142 | private double[] PVIGradeOuts { get { return _profile.PVIs.Cast().Select(x => x.GradeOut).ToArray(); } }
143 | #endregion
144 |
145 | #region CONSTRUCTOR
146 | ///
147 | /// Initializes a new instance of the class.
148 | ///
149 | /// The profile.
150 | internal Profile(AeccProfile profile)
151 | {
152 | this._profile = profile;
153 | this._entities = profile.Entities;
154 | }
155 |
156 | #endregion
157 |
158 | #region PRIVATE METHODS
159 |
160 | //TODO: Get profile curves
161 | ///
162 | ///
163 | [SupressImportIntoVM]
164 | private void XX()
165 | {
166 | Utils.Log(string.Format("Profile.XX started...", ""));
167 |
168 | IList output = new List();
169 |
170 | for (int i = 0; i < this._entities.Count; ++i)
171 | {
172 | var e = this._entities.Item(i);
173 |
174 | if (e.Type == AeccProfileEntityType.aeccProfileEntityTangent)
175 | {
176 | var tangent = e as aeccProfileTangent;
177 |
178 | var start = Point.ByCoordinates(tangent.StartStation, tangent.StartElevation);
179 | var end = Point.ByCoordinates(tangent.EndStation, tangent.EndElevation);
180 |
181 | output.Add(Line.ByStartPointEndPoint(start, end));
182 | }
183 | else if (e.Type == AeccProfileEntityType.aeccProfileEntityCurveCircular)
184 | {
185 | var arc = e as aeccProfileCurveCircular;
186 |
187 | var start = Point.ByCoordinates(arc.StartStation, arc.StartElevation);
188 | var end = Point.ByCoordinates(arc.EndStation, arc.EndElevation);
189 | var pvi = Point.ByCoordinates(arc.PVIStation, arc.PVIElevation);
190 | double radius = arc.Radius;
191 | }
192 | }
193 |
194 | Utils.Log(string.Format("Profile.XX completed.", ""));
195 | }
196 |
197 | #endregion
198 |
199 | #region PUBLIC METHODS
200 | ///
201 | /// Gets the elevation at station.
202 | ///
203 | /// The station.
204 | ///
205 | public double GetElevationAtStation(double station)
206 | {
207 | return this._profile.ElevationAt(station);
208 | }
209 |
210 | ///
211 | /// Gets the elevations of the entities in the profile.
212 | ///
213 | ///
214 | ///
215 | [SupressImportIntoVM]
216 | public IList GetEntitiesElevations()
217 | {
218 | Utils.Log(string.Format("Profile.GetEntitiesElevations Started...", ""));
219 |
220 | IList elevations = new List();
221 |
222 | Dictionary entities = new Dictionary();
223 |
224 | foreach (IAeccProfileEntity ent in _profile.Entities)
225 | {
226 | double start = 0;
227 |
228 | if (ent.Type == AeccProfileEntityType.aeccProfileEntityTangent)
229 | {
230 | var c = ent as aeccProfileTangent;
231 | start = c.StartStation;
232 | entities.Add(start, c);
233 | }
234 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveSymmetricParabola)
235 | {
236 | var c = ent as AeccProfileCurveParabolic;
237 | start = c.StartStation;
238 | entities.Add(start, c);
239 | }
240 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveCircular)
241 | {
242 | var c = ent as aeccProfileCurveCircular;
243 | start = c.StartStation;
244 | entities.Add(start, c);
245 | }
246 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveAsymmetricParabola)
247 | {
248 | var c = ent as AeccProfileCurveAsymmetric;
249 | start = c.StartStation;
250 | entities.Add(start, c);
251 | }
252 | }
253 |
254 | double[] stations = entities.Keys.OrderBy(x => x).ToArray();
255 |
256 | for (int i = 0; i < stations.Length; ++i )
257 | {
258 | double s = stations[i];
259 |
260 | IAeccProfileEntity ent = entities[s];
261 |
262 | if (ent.Type == AeccProfileEntityType.aeccProfileEntityTangent)
263 | {
264 | var c = ent as aeccProfileTangent;
265 | elevations.Add(c.StartElevation);
266 | if (i == stations.Length - 1)
267 | {
268 | elevations.Add(c.EndElevation);
269 | }
270 | }
271 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveSymmetricParabola)
272 | {
273 | var c = ent as AeccProfileCurveParabolic;
274 | elevations.Add(c.StartElevation);
275 | elevations.Add(c.HighLowPointElevation);
276 | if (i == stations.Length - 1)
277 | {
278 | elevations.Add(c.EndElevation);
279 | }
280 | }
281 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveCircular)
282 | {
283 | var c = ent as aeccProfileCurveCircular;
284 | elevations.Add(c.StartElevation);
285 | elevations.Add(c.HighLowPointElevation);
286 | if (i == stations.Length - 1)
287 | {
288 | elevations.Add(c.EndElevation);
289 | }
290 | }
291 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveAsymmetricParabola)
292 | {
293 | var c = ent as AeccProfileCurveAsymmetric;
294 | elevations.Add(c.StartElevation);
295 | elevations.Add(c.HighLowPointElevation);
296 | if (i == stations.Length - 1)
297 | {
298 | elevations.Add(c.EndElevation);
299 | }
300 | }
301 | }
302 |
303 | Utils.Log(string.Format("Elements: {0}", elevations.Count));
304 |
305 | foreach (double el in elevations)
306 | {
307 | Utils.Log(string.Format("{0}", el));
308 | }
309 |
310 | Utils.Log(string.Format("Profile.GetEntitiesElevations Completed.", ""));
311 |
312 | return elevations;
313 | }
314 |
315 | ///
316 | /// Gets the stations of the entities in the profile.
317 | ///
318 | ///
319 | ///
320 | [SupressImportIntoVM]
321 | public IList GetEntitiesStations()
322 | {
323 | Utils.Log(string.Format("Profile.GetEntitiesStations Started...", ""));
324 |
325 | IList stations = new List();
326 |
327 | foreach (IAeccProfileEntity ent in _profile.Entities)
328 | {
329 | if (ent.Type == AeccProfileEntityType.aeccProfileEntityTangent)
330 | {
331 | var c = ent as aeccProfileTangent;
332 | stations.Add(c.StartStation);
333 | stations.Add(c.EndStation);
334 | }
335 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveSymmetricParabola)
336 | {
337 | var c = ent as AeccProfileCurveParabolic;
338 | stations.Add(c.StartStation);
339 | stations.Add(c.HighLowPointStation);
340 | stations.Add(c.EndStation);
341 | }
342 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveCircular)
343 | {
344 | var c = ent as aeccProfileCurveCircular;
345 | stations.Add(c.StartStation);
346 | stations.Add(c.HighLowPointStation);
347 | stations.Add(c.EndStation);
348 | }
349 | else if (ent.Type == AeccProfileEntityType.aeccProfileEntityCurveAsymmetricParabola)
350 | {
351 | var c = ent as AeccProfileCurveAsymmetric;
352 | stations.Add(c.StartStation);
353 | stations.Add(c.HighLowPointStation);
354 | stations.Add(c.EndStation);
355 | }
356 | }
357 |
358 | stations = stations.Distinct().OrderBy(x => x).ToList();
359 |
360 | Utils.Log(string.Format("Elements: {0}", stations.Count));
361 |
362 | foreach (double el in stations)
363 | {
364 | Utils.Log(string.Format("{0}", el));
365 | }
366 |
367 | Utils.Log(string.Format("Profile.GetEntitiesStations Completed.", ""));
368 |
369 | return stations;
370 | }
371 |
372 |
373 |
374 | ///
375 | /// Returns a that represents this instance.
376 | ///
377 | ///
378 | /// A that represents this instance.
379 | ///
380 | public override string ToString()
381 | {
382 | return string.Format("Profile(Name = {0})", this.Name);
383 | }
384 |
385 | #endregion
386 | }
387 | }
388 |
389 |
--------------------------------------------------------------------------------
/Autodesk2024/Ring.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Autodesk, Inc. All rights reserved.
2 | // Author: paolo.serra@autodesk.com
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License").
5 | // You may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | // implied. See the License for the specific language governing
13 | // permissions and limitations under the License.
14 | using System;
15 | using Autodesk.DesignScript.Geometry;
16 | using Autodesk.DesignScript.Runtime;
17 |
18 | namespace CivilConnection.Tunnel
19 | {
20 | ///
21 | /// Tunnel Ring object type.
22 | ///
23 | [IsVisibleInDynamoLibrary(true)]
24 | public class Ring
25 | {
26 | #region PRIVATE MEMEBERS
27 | double _angle;
28 | double _depth;
29 | double _internalRadius;
30 | double _externalRadius;
31 | double _offset;
32 | double _thickness;
33 | double _faceAngle;
34 | double _rho;
35 | double _lambda;
36 |
37 | CoordinateSystem _frontCS = CoordinateSystem.Identity();
38 | CoordinateSystem _backCS = CoordinateSystem.Identity();
39 | CoordinateSystem _startCS = CoordinateSystem.Identity();
40 | CoordinateSystem _endCS = CoordinateSystem.Identity();
41 | Line _line;
42 |
43 | Solid _solid;
44 |
45 | #endregion
46 |
47 | #region PUBLIC MEMBERS
48 | ///
49 | /// Gets or sets the angle.
50 | ///
51 | ///
52 | /// The angle.
53 | ///
54 | public double Angle
55 | {
56 | get
57 | {
58 | if (this.StartCS != null)
59 | {
60 | Utils.Log(string.Format("Ring.Angle started...", ""));
61 |
62 | var x = this.StartCS.YAxis.Cross(Vector.ZAxis());
63 | var z = x.Cross(this.StartCS.YAxis);
64 | _angle = z.AngleAboutAxis(this.StartCS.ZAxis, this.StartCS.YAxis);
65 |
66 | x.Dispose();
67 | z.Dispose();
68 |
69 | Utils.Log(string.Format("Ring.Angle completed.", ""));
70 | }
71 |
72 | return _angle;
73 | }
74 | set
75 | {
76 | _angle = value;
77 | }
78 | }
79 | ///
80 | /// Gets or sets the depth.
81 | ///
82 | ///
83 | /// The depth.
84 | ///
85 | public double Depth { get { return _depth; } set { _depth = value; } }
86 | ///
87 | /// Gets or sets the internal radius.
88 | ///
89 | ///
90 | /// The internal radius.
91 | ///
92 | public double InternalRadius { get { return _internalRadius; } set { _internalRadius = value; } }
93 | ///
94 | /// Gets or sets the external radius.
95 | ///
96 | ///
97 | /// The external radius.
98 | ///
99 | public double ExternalRadius { get { return _externalRadius; } set { _externalRadius = value; } }
100 | ///
101 | /// Gets the rho.
102 | ///
103 | ///
104 | /// The rho.
105 | ///
106 | public double Rho
107 | {
108 | get
109 | {
110 | _rho = (_depth - _offset) * Math.Sin(Math.Atan((_offset / (2 * _externalRadius))));
111 | return _rho;
112 | }
113 | }
114 |
115 | ///
116 | /// Gets the lambda.
117 | ///
118 | ///
119 | /// The rho.
120 | ///
121 | public double Lambda
122 | {
123 | get
124 | {
125 | _lambda = (_depth - _offset) * Math.Cos(Math.Atan((_offset / (2 * _externalRadius))));
126 | return _lambda;
127 | }
128 | }
129 | ///
130 | /// Gets or sets the offset.
131 | ///
132 | ///
133 | /// The offset.
134 | ///
135 | public double Offset { get { return _offset; } set { _offset = value; } }
136 | ///
137 | /// Gets or sets the thickness.
138 | ///
139 | ///
140 | /// The thickness.
141 | ///
142 | public double Thickness { get { return _thickness; } set { _thickness = value; } }
143 | ///
144 | /// Gets the front cs.
145 | ///
146 | ///
147 | /// The front cs.
148 | ///
149 | public CoordinateSystem FrontCS
150 | {
151 | get
152 | {
153 | return _frontCS;
154 | }
155 | set { _frontCS = value; }
156 | }
157 | ///
158 | /// Gets the back cs.
159 | ///
160 | ///
161 | /// The back cs.
162 | ///
163 | public CoordinateSystem BackCS
164 | {
165 | get
166 | {
167 | return _backCS;
168 | }
169 | set { _backCS = value; }
170 | }
171 | ///
172 | /// Gets the start cs.
173 | ///
174 | ///
175 | /// The start cs.
176 | ///
177 | public CoordinateSystem StartCS
178 | {
179 | get
180 | {
181 | return _startCS;
182 | }
183 | set { _startCS = value; }
184 | }
185 | ///
186 | /// Gets the end cs.
187 | ///
188 | ///
189 | /// The end cs.
190 | ///
191 | public CoordinateSystem EndCS
192 | {
193 | get
194 | {
195 | return _endCS;
196 | }
197 | set { _endCS = value; }
198 | }
199 | ///
200 | /// Gets the ring solid.
201 | ///
202 | ///
203 | /// The ring solid.
204 | ///
205 | public Solid RingSolid
206 | {
207 | get
208 | {
209 | if (this._solid == null)
210 | {
211 | Utils.Log(string.Format("RingSolid started...", ""));
212 |
213 | Circle ci = Circle.ByPlaneRadius(this.StartCS.ZXPlane.Offset(-this._offset / 2), this._internalRadius);
214 | Circle ce = Circle.ByPlaneRadius(this.StartCS.ZXPlane.Offset(-this._offset / 2), this._externalRadius);
215 |
216 | Surface ei = ci.Extrude(this.StartCS.YAxis, this._depth);
217 | Surface ee = ce.Extrude(this.StartCS.YAxis, this._depth);
218 | Curve internalProfileFront = ei.Intersect(this.FrontCS.ZXPlane)[0] as Curve;
219 | Curve internalProfileBack = ei.Intersect(this.BackCS.ZXPlane)[0] as Curve;
220 | Curve externalProfileFront = ee.Intersect(this.FrontCS.ZXPlane)[0] as Curve;
221 | Curve externalProfileBack = ee.Intersect(this.BackCS.ZXPlane)[0] as Curve;
222 |
223 | Solid si = Solid.ByLoft(new Curve[] { internalProfileFront, internalProfileBack });
224 | Solid se = Solid.ByLoft(new Curve[] { externalProfileFront, externalProfileBack });
225 |
226 | this._solid = se.Difference(si).Rotate(this.StartCS.ZXPlane, this._angle) as Solid;
227 |
228 | ci.Dispose();
229 | ce.Dispose();
230 | ei.Dispose();
231 | ee.Dispose();
232 | internalProfileFront.Dispose();
233 | internalProfileBack.Dispose();
234 | externalProfileFront.Dispose();
235 | externalProfileBack.Dispose();
236 | si.Dispose();
237 | se.Dispose();
238 |
239 | Utils.Log(string.Format("RingSolid completed.", ""));
240 | }
241 |
242 | return this._solid;
243 | }
244 |
245 | set { _solid = value; }
246 | }
247 | ///
248 | /// Gets the line.
249 | ///
250 | ///
251 | /// The line.
252 | ///
253 | public Line Line
254 | {
255 | get
256 | {
257 | if (_line == null)
258 | {
259 | _line = Line.ByStartPointDirectionLength(Point.Origin(), Vector.YAxis(), this._depth - this._offset);
260 | }
261 | return _line;
262 | }
263 | set { _line = value; }
264 | }
265 | ///
266 | /// Gets the face angle.
267 | ///
268 | ///
269 | /// The face angle.
270 | ///
271 | public double FaceAngle
272 | {
273 | get
274 | {
275 | _faceAngle = Utils.RadToDeg(Math.Atan(this._offset / (2 * this._externalRadius)));
276 |
277 | return _faceAngle;
278 | }
279 | set { _faceAngle = value; }
280 | }
281 | #endregion
282 |
283 | #region INTERNAL CONSTRUCTORS
284 | ///
285 | /// Initializes a new instance of the class.
286 | ///
287 | internal Ring() { }
288 |
289 | ///
290 | /// Initializes a new isntance of the class.
291 | ///
292 | /// The internal radius.
293 | /// The ring thickness.
294 | /// The ring offset in the narrow side.
295 | /// The ring depth.
296 | /// The ring rotation angle along the tunnel axis.
297 | /// The CoordinateSystem.
298 | internal Ring(double radius, double thickness, double offset, double depth, double angle=0, CoordinateSystem cs = null)
299 | {
300 | Utils.Log(string.Format("Ring started...", ""));
301 |
302 | if (cs == null)
303 | {
304 | cs = CoordinateSystem.Identity();
305 | }
306 |
307 | this._internalRadius = radius;
308 | this._thickness = thickness;
309 | this._externalRadius = this._internalRadius + this._thickness;
310 | this._offset = offset;
311 | this._depth = depth;
312 | this._angle = Math.Abs(angle) > 360 ? (Math.Abs(angle) - Math.Floor(Math.Abs(angle) / 360) * 360) * Math.Sign(angle) : angle;
313 |
314 | double length = this._depth - this._offset;
315 | this._line = Line.ByStartPointDirectionLength(cs.Origin, cs.YAxis, length);
316 |
317 | this._faceAngle = Utils.RadToDeg(Math.Atan(this._offset / (2 * this._externalRadius)));
318 |
319 |
320 |
321 | Point p1 = Point.ByCoordinates(0, -this._offset / 2, -this._externalRadius).Transform(cs) as Point;
322 | Point p2 = Point.ByCoordinates(0, this._offset / 2, this._externalRadius).Transform(cs) as Point;
323 | Point p3 = Point.ByCoordinates(this._externalRadius, 0, 0).Transform(cs) as Point;
324 | Plane front = Plane.ByBestFitThroughPoints(new Point[] { p1, p2, p3 });
325 |
326 | Point p4 = Point.ByCoordinates(0, this._depth - this._offset / 2, -this._externalRadius).Transform(cs) as Point;
327 | Point p5 = Point.ByCoordinates(0, this._depth - 1.5 * this._offset, this._externalRadius).Transform(cs) as Point;
328 | Point p6 = Point.ByCoordinates(this._externalRadius, this._depth - this._offset, 0).Transform(cs) as Point;
329 | Plane back = Plane.ByBestFitThroughPoints(new Point[] { p4, p5, p6 });
330 |
331 | this._startCS = CoordinateSystem.ByOriginVectors(this._line.StartPoint,
332 | cs.XAxis,
333 | cs.YAxis,
334 | cs.ZAxis)
335 | .Rotate(cs.ZXPlane, this._angle);
336 |
337 | this._endCS = CoordinateSystem.ByOriginVectors(this._line.EndPoint,
338 | cs.XAxis,
339 | cs.YAxis,
340 | cs.ZAxis)
341 | .Rotate(cs.ZXPlane, this._angle);
342 |
343 | this._frontCS = CoordinateSystem.ByOriginVectors(this._startCS.Origin, this._startCS.XAxis, front.Normal.Reverse());
344 |
345 | this._backCS = CoordinateSystem.ByOriginVectors(this._endCS.Origin, this._endCS.XAxis, back.Normal.Reverse());
346 |
347 |
348 | p1.Dispose();
349 | p2.Dispose();
350 | p3.Dispose();
351 | p4.Dispose();
352 | p5.Dispose();
353 | p6.Dispose();
354 | front.Dispose();
355 | back.Dispose();
356 |
357 | Utils.Log(string.Format("Ring completed.", ""));
358 | }
359 |
360 | ///
361 | /// Creates a copy of the current Ring.
362 | ///
363 | ///
364 | internal Ring Copy()
365 | {
366 | #region WIP
367 | //Ring copy = new Ring()
368 | //{
369 | // _angle = this._angle,
370 | // _depth = this._depth,
371 | // _externalRadius = this._externalRadius,
372 | // _internalRadius = this._internalRadius,
373 | // _offset = this._offset,
374 | // _thickness = this._thickness,
375 | // //a = this.a,
376 | // Angle = this.Angle,
377 | // //back = this.back,
378 | // //BackCS = this.BackCS,
379 | // //ce = this.ce,
380 | // //ci = this.ci,
381 | // Depth = this.Depth,
382 | // //ee = this.ee,
383 | // //ei = this.ei,
384 | // //EndCS = this.EndCS,
385 | // //externalProfileBack = this.externalProfileBack,
386 | // //externalProfileFront = this.externalProfileFront,
387 | // ExternalRadius = this.ExternalRadius,
388 | // FaceAngle = this.FaceAngle,
389 | // //front = this.front,
390 | // //FrontCS = this.FrontCS,
391 | // //internalProfileBack = this.internalProfileBack,
392 | // //internalProfileFront = this.internalProfileFront,
393 | // InternalRadius = this.InternalRadius,
394 | // //l = this.l,
395 | // //Lambda = this.Lambda,
396 | // //Line = this.Line,
397 | // Offset = this.Offset,
398 | // //p1 = this.p1,
399 | // //p2 = this.p2,
400 | // //p3 = this.p3,
401 | // //p4 = this.p4,
402 | // //p5 = this.p5,
403 | // //p6 = this.p6,
404 | // //Rho = this.Rho,
405 | // //RingSolid = this.RingSolid,
406 | // //se = this.se,
407 | // //si = this.si,
408 | // //solid = this.solid,
409 | // //StartCS = this.StartCS,
410 | // Thickness = this.Thickness
411 | //};
412 | #endregion
413 |
414 | Ring copy = new Ring(this.InternalRadius, this.Thickness, this.Offset, this.Depth, this.Angle);
415 |
416 | Utils.Log("Copy created");
417 |
418 | return copy;
419 | }
420 |
421 | #endregion
422 |
423 | #region PUBLIC METHODS
424 | ///
425 | /// Reutrns a Ring by dimensions.
426 | ///
427 | /// The radius.
428 | /// The thickness.
429 | /// The offset.
430 | /// The depth.
431 | /// The angle.
432 | /// The CoordinateSystem.
433 | ///
434 | public static Ring ByDimensions(double radius, double thickness, double offset, double depth, double angle=0, CoordinateSystem cs=null)
435 | {
436 | return new Ring(radius, thickness, offset, depth, angle, cs);
437 | }
438 |
439 | ///
440 | /// Transforms a Ring by the specified cs.
441 | ///
442 | /// The cs.
443 | ///
444 | public Ring Transform(CoordinateSystem cs)
445 | {
446 | Utils.Log(string.Format("Ring.Transform started...", ""));
447 |
448 | Ring ring = new Ring(this.InternalRadius, this.Thickness, this.Offset, this.Depth, 0, cs);
449 |
450 | Utils.Log(string.Format("Ring.Transform completed.", ""));
451 |
452 | return ring;
453 | }
454 |
455 | ///
456 | /// Rotates the Ring on the starting face by the angle value.
457 | ///
458 | /// The angle.
459 | ///
460 | public Ring RotateOnFace(double angle)
461 | {
462 | Utils.Log(string.Format("Ring.RotateOnFace started...", ""));
463 |
464 | var front = this.FrontCS;
465 | var start = this.StartCS;
466 | var a = this.Angle + angle;
467 | var ring = this.Transform(start.Rotate(front.ZXPlane, angle));
468 |
469 | Utils.Log(string.Format("Ring.RotateOnFace completed.", ""));
470 |
471 | return ring;
472 | }
473 |
474 | ///
475 | /// Returns the followings Ring with face rotated by the specified angle.
476 | ///
477 | /// The angle.
478 | ///
479 | public Ring Following(double angle)
480 | {
481 | CoordinateSystem cs = this.BackCS.Rotate(this.BackCS.YZPlane, this.FaceAngle).Rotate(this.BackCS.ZXPlane, angle);
482 | Ring output = this.Transform(cs);
483 | cs.Dispose();
484 | return output;
485 | }
486 |
487 | ///
488 | /// Returns a that represents this instance.
489 | ///
490 | ///
491 | /// A that represents this instance.
492 | ///
493 | public override string ToString()
494 | {
495 | return string.Format("Ring(InternalRadius = {0:0.000}, Thickness = {1:0.000}, Depth = {2:0.000}, Angle = {3:0.00})", this.InternalRadius, this.Thickness, this.Depth, this.Angle);
496 | }
497 | #endregion
498 | }
499 | }
500 |
--------------------------------------------------------------------------------