Skip to content

Commit 31e026a

Browse files
author
Jeremy Tammik
committed
use Reference.UVPoint directly
1 parent 6f7c794 commit 31e026a

File tree

2 files changed

+66
-53
lines changed

2 files changed

+66
-53
lines changed

BuildingCoder/BuildingCoder/CmdNewLightingFixture.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#region Namespaces
1111
using System;
1212
using System.Collections.Generic;
13+
using System.Diagnostics;
1314
using Autodesk.Revit.ApplicationServices;
1415
using Autodesk.Revit.Attributes;
1516
using Autodesk.Revit.DB;
@@ -126,8 +127,6 @@ FamilyInstance PlaceFamilyInstanceOnFace(
126127
GeometryObject obj
127128
= e.GetGeometryObjectFromReference( r );
128129

129-
XYZ p = r.GlobalPoint;
130-
131130
if( obj is PlanarFace )
132131
{
133132
PlanarFace planarFace = obj as PlanarFace;
@@ -146,9 +145,23 @@ GeometryObject obj
146145
// for each specific case, handle the general
147146
// case in a generic fashion.
148147

148+
Debug.Assert(
149+
ElementReferenceType.REFERENCE_TYPE_SURFACE
150+
== r.ElementReferenceType,
151+
"expected PickObject with ObjectType.Face to "
152+
+ "return a surface reference" );
153+
149154
Face face = obj as Face;
155+
UV q = r.UVPoint;
156+
157+
#if DEBUG
158+
XYZ p = r.GlobalPoint;
150159
IntersectionResult ir = face.Project( p );
151-
UV q = ir.UVPoint;
160+
UV q2 = ir.UVPoint;
161+
Debug.Assert( q.IsAlmostEqualTo( q2 ),
162+
"expected same UV point" );
163+
#endif // DEBUG
164+
152165
Transform t = face.ComputeDerivatives( q );
153166
XYZ v = t.BasisX; // or BasisY, or whatever...
154167

BuildingCoder/BuildingCoder/Creator.cs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Creator( Document doc )
3636

3737
/// <summary>
3838
/// Determine the plane that a given curve resides in and return its normal vector.
39-
/// Ask the curve for its start and end points and some curve in the middle.
39+
/// Ask the curve for its start and end points and some point in the middle.
4040
/// The latter can be obtained by asking the curve for its parameter range and
4141
/// evaluating it in the middle, or by tessellation. In case of tessellation,
4242
/// you could iterate through the tessellation points and use each one together
@@ -70,7 +70,7 @@ XYZ GetCurveNormal( Curve curve )
7070
"expected non-line element to have "
7171
+ "more than two tessellation points" );
7272

73-
// for non-vertical lines, use Z axis to
73+
// For non-vertical lines, use Z axis to
7474
// span the plane, otherwise Y axis:
7575

7676
double dxy = Math.Abs( v.X ) + Math.Abs( v.Y );
@@ -95,7 +95,7 @@ XYZ GetCurveNormal( Curve curve )
9595
}
9696
}
9797

98-
#if DEBUG
98+
#if DEBUG
9999
{
100100
XYZ normal2;
101101
while( ++i < n - 1 )
@@ -108,69 +108,69 @@ XYZ GetCurveNormal( Curve curve )
108108
+ "lie in same plane" );
109109
}
110110
}
111-
#endif // DEBUG
111+
#endif // DEBUG
112112

113113
}
114114
return normal;
115115
}
116116

117-
/// <summary>
118-
/// Create a model line between the two given points.
119-
/// Internally, it creates an arbitrary sketch
120-
/// plane given the model line end points.
121-
/// </summary>
122-
public static ModelLine CreateModelLine(
123-
Document doc,
124-
XYZ p,
125-
XYZ q )
126-
{
127-
if( p.DistanceTo( q ) < Util.MinLineLength ) return null;
117+
/// <summary>
118+
/// Create a model line between the two given points.
119+
/// Internally, it creates an arbitrary sketch
120+
/// plane given the model line end points.
121+
/// </summary>
122+
public static ModelLine CreateModelLine(
123+
Document doc,
124+
XYZ p,
125+
XYZ q )
126+
{
127+
if( p.DistanceTo( q ) < Util.MinLineLength ) return null;
128128

129-
// Create sketch plane; for non-vertical lines,
130-
// use Z-axis to span the plane, otherwise Y-axis:
129+
// Create sketch plane; for non-vertical lines,
130+
// use Z-axis to span the plane, otherwise Y-axis:
131131

132-
XYZ v = q - p;
132+
XYZ v = q - p;
133133

134-
double dxy = Math.Abs( v.X ) + Math.Abs( v.Y );
134+
double dxy = Math.Abs( v.X ) + Math.Abs( v.Y );
135135

136-
XYZ w = ( dxy > Util.TolPointOnPlane )
137-
? XYZ.BasisZ
138-
: XYZ.BasisY;
136+
XYZ w = ( dxy > Util.TolPointOnPlane )
137+
? XYZ.BasisZ
138+
: XYZ.BasisY;
139139

140-
XYZ norm = v.CrossProduct( w ).Normalize();
140+
XYZ norm = v.CrossProduct( w ).Normalize();
141141

142-
//Autodesk.Revit.Creation.Application creApp
143-
// = doc.Application.Create;
142+
//Autodesk.Revit.Creation.Application creApp
143+
// = doc.Application.Create;
144144

145-
//Plane plane = creApp.NewPlane( norm, p ); // 2014
146-
Plane plane = new Plane( norm, p ); // 2015
145+
//Plane plane = creApp.NewPlane( norm, p ); // 2014
146+
Plane plane = new Plane( norm, p ); // 2015
147147

148-
//SketchPlane sketchPlane = creDoc.NewSketchPlane( plane ); // 2013
149-
SketchPlane sketchPlane = SketchPlane.Create( doc, plane ); // 2014
148+
//SketchPlane sketchPlane = creDoc.NewSketchPlane( plane ); // 2013
149+
SketchPlane sketchPlane = SketchPlane.Create( doc, plane ); // 2014
150150

151-
//Line line = creApp.NewLine( p, q, true ); // 2013
152-
Line line = Line.CreateBound( p, q ); // 2014
151+
//Line line = creApp.NewLine( p, q, true ); // 2013
152+
Line line = Line.CreateBound( p, q ); // 2014
153153

154-
// The following line is only valid in a project
155-
// document. In a family, it will throw an exception
156-
// saying "Document.Create can only be used with
157-
// project documents. Use Document.FamilyCreate
158-
// in the Family Editor."
154+
// The following line is only valid in a project
155+
// document. In a family, it will throw an exception
156+
// saying "Document.Create can only be used with
157+
// project documents. Use Document.FamilyCreate
158+
// in the Family Editor."
159159

160-
//Autodesk.Revit.Creation.Document creDoc
161-
// = doc.Create;
160+
//Autodesk.Revit.Creation.Document creDoc
161+
// = doc.Create;
162162

163-
//return creDoc.NewModelCurve(
164-
// //creApp.NewLine( p, q, true ), // 2013
165-
// Line.CreateBound( p, q ), // 2014
166-
// sketchPlane ) as ModelLine;
163+
//return creDoc.NewModelCurve(
164+
// //creApp.NewLine( p, q, true ), // 2013
165+
// Line.CreateBound( p, q ), // 2014
166+
// sketchPlane ) as ModelLine;
167167

168-
ModelCurve curve = doc.IsFamilyDocument
169-
? doc.FamilyCreate.NewModelCurve( line, sketchPlane )
170-
: doc.Create.NewModelCurve( line, sketchPlane );
168+
ModelCurve curve = doc.IsFamilyDocument
169+
? doc.FamilyCreate.NewModelCurve( line, sketchPlane )
170+
: doc.Create.NewModelCurve( line, sketchPlane );
171171

172-
return curve as ModelLine;
173-
}
172+
return curve as ModelLine;
173+
}
174174

175175
SketchPlane NewSketchPlanePassLine(
176176
Line line )
@@ -227,8 +227,8 @@ SketchPlane NewSketchPlaneContainCurve(
227227
XYZ normal = GetCurveNormal( curve );
228228
Plane plane = _creapp.NewPlane( normal, p );
229229

230-
#if DEBUG
231-
if( !(curve is Line) )
230+
#if DEBUG
231+
if( !( curve is Line ) )
232232
{
233233
CurveArray a = _creapp.NewCurveArray();
234234
a.Append( curve );
@@ -240,7 +240,7 @@ SketchPlane NewSketchPlaneContainCurve(
240240
Debug.Assert( Util.IsZero( plane2.SignedDistanceTo(
241241
plane.Origin ) ), "expected equal planes" );
242242
}
243-
#endif // DEBUG
243+
#endif // DEBUG
244244

245245
//return _credoc.NewSketchPlane( plane ); // 2013
246246

0 commit comments

Comments
 (0)