Skip to content

Commit

Permalink
integrated Alexander Ignatovich ai CmdWallProfile - final.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Tammik committed Apr 10, 2015
1 parent 618f126 commit a4d07fe
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 31 deletions.
55 changes: 26 additions & 29 deletions BuildingCoder/BuildingCoder/CmdWallProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public Result Execute1(
message = ( 0 < sel.GetElementIds().Count )
? "Please select some wall elements."
: "No wall elements found.";

return Result.Failed;
}

Expand Down Expand Up @@ -333,19 +333,21 @@ OverrideGraphicSettings overrides
return Result.Succeeded;
}

void SetModelCurveColor(
ModelCurve modelCurve,
View view,
void SetModelCurvesColor(
ModelCurveArray modelCurves,
View view,
Color color )
{
OverrideGraphicSettings overrides
= view.GetElementOverrides( modelCurve.Id );
foreach( var curve in modelCurves
.Cast<ModelCurve>() )
{
var overrides = view.GetElementOverrides(
curve.Id );

overrides.SetProjectionLineColor(
color );
overrides.SetProjectionLineColor( color );

view.SetElementOverrides(
modelCurve.Id, overrides );
view.SetElementOverrides( curve.Id, overrides );
}
}

/// <summary>
Expand Down Expand Up @@ -391,12 +393,12 @@ Autodesk.Revit.Creation.Document credoc
// Get the external wall face for the profile
// a little bit simpler than in the last realization

Reference sideFaceReference
= HostObjectUtils.GetSideFaces(
Reference sideFaceReference
= HostObjectUtils.GetSideFaces(
wall, ShellLayerType.Exterior )
.First();

Face face = wall.GetGeometryObjectFromReference(
Face face = wall.GetGeometryObjectFromReference(
sideFaceReference ) as Face;

// The normal of the wall external face.
Expand All @@ -423,14 +425,13 @@ IList<CurveLoop> curveLoops
CurveArray curves = creapp.NewCurveArray();

foreach( Curve curve in curveLoop )
curves.Append( curve.CreateTransformed(
curves.Append( curve.CreateTransformed(
offset ) );

var isCounterClockwise = curveLoop
var isCounterClockwize = curveLoop
.IsCounterclockwise( normal );

// Create model lines for a curve loop
// if it is made
// Create model lines for an curve loop if it is made

if( ( (LocationCurve) wall.Location ).Curve
is Line )
Expand All @@ -440,27 +441,23 @@ IList<CurveLoop> curveLoops
SketchPlane sketchPlane
= SketchPlane.Create( doc, plane );

ModelCurveArray curveElements
= credoc.NewModelCurveArray(
curves, sketchPlane );
ModelCurveArray curveElements = credoc
.NewModelCurveArray( curves, sketchPlane );

if( isCounterClockwise )
if( isCounterClockwize )
{
foreach( ModelCurve c in curveElements )
{
SetModelCurveColor( c, view, colorRed );
}
SetModelCurvesColor( curveElements,
view, colorRed );
}
}
else
{
foreach( var curve in curves.Cast<Curve>() )
{
var mc = creator.CreateModelCurve( curve );

if( isCounterClockwise )
var curveElements = creator.CreateModelCurves( curve );
if( isCounterClockwize )
{
SetModelCurveColor( mc, view, colorRed );
SetModelCurvesColor( curveElements, view, colorRed );
}
}
}
Expand Down
66 changes: 66 additions & 0 deletions BuildingCoder/BuildingCoder/Creator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
#endregion // Namespaces
Expand Down Expand Up @@ -253,6 +254,71 @@ public ModelCurve CreateModelCurve( Curve curve )
NewSketchPlaneContainCurve( curve ) );
}

ModelCurve CreateModelCurve(
Curve curve,
XYZ origin,
XYZ normal )
{
Plane plane = _creapp.NewPlane( normal, origin );

SketchPlane sketchPlane = SketchPlane.Create(
_doc, plane );

return _credoc.NewModelCurve(
curve, sketchPlane );
}

public ModelCurveArray CreateModelCurves(
Curve curve )
{
var array = new ModelCurveArray();

var line = curve as Line;
if( line != null )
{
array.Append( CreateModelLine( _doc,
curve.GetEndPoint( 0 ),
curve.GetEndPoint( 1 ) ) );

return array;
}

var arc = curve as Arc;
if( arc != null )
{
var origin = arc.Center;
var normal = arc.Normal;

array.Append( CreateModelCurve(
arc, origin, normal ) );

return array;
}

var ellipse = curve as Ellipse;
if( ellipse != null )
{
var origin = ellipse.Center;
var normal = ellipse.Normal;

array.Append( CreateModelCurve(
ellipse, origin, normal ) );

return array;
}

var points = curve.Tessellate();
var p = points.First();

foreach( var q in points.Skip( 1 ) )
{
array.Append( CreateModelLine( _doc, p, q ) );
p = q;
}

return array;
}

public void DrawPolygon(
List<XYZ> loop )
{
Expand Down
5 changes: 3 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
// 2015-03-25 2015.0.120.3 before Alexander Ignatovich ai CmdWallProfile enhancement
// 2015-03-25 2015.0.120.4 integrated Alexander Ignatovich ai CmdWallProfile - first attempt.cs
// 2015-03-25 2015.0.120.5 integrated Alexander Ignatovich ai CmdWallProfile - second attempt.cs
// 2015-03-25 2015.0.120.6 integrated Alexander Ignatovich ai CmdWallProfile - final.cs
//
[assembly: AssemblyVersion( "2015.0.120.5" )]
[assembly: AssemblyFileVersion( "2015.0.120.5" )]
[assembly: AssemblyVersion( "2015.0.120.6" )]
[assembly: AssemblyFileVersion( "2015.0.120.6" )]

0 comments on commit a4d07fe

Please sign in to comment.