/// <summary> /// Convert a GeometryObject to an applicable ProtoGeometry type. /// </summary> /// <param name="geom"></param> /// <param name="reference"></param> /// <param name="transform"></param> /// <returns>A Geometry type. Null if there's no suitable conversion.</returns> public static object Convert(this Autodesk.Revit.DB.GeometryObject geom, Autodesk.Revit.DB.Reference reference = null, Autodesk.DesignScript.Geometry.CoordinateSystem transform = null) { if (geom == null) { return(null); } dynamic dynGeom = geom; dynamic protoGeom = null; try { protoGeom = InternalConvert(dynGeom); return(Tag(Transform(protoGeom, transform), reference)); } catch (Exception e) { DynamoServices.LogWarningMessageEvents.OnLogWarningMessage(Properties.Resources.GeometryConversionFailure + e.Message); return(null); } finally { // Dispose the temporary geometry that has been transformed. DisposeGeometry(protoGeom, transform); } }
/// <summary> /// Create an Advance Steel Rectangular Shear Stud Pattern at a Point /// </summary> /// <param name="connectionPoint"> Input Insertion point of Bolt Pattern </param> /// <param name="shearStudCS"> Input Bolt Coordinate System </param> /// <param name="objectToConnect"> Object to attached ShearStud </param> /// <param name="studLength"> Input Shear Stud Length</param> /// <param name="studDiameter"> Input Shear Stud Diameter</param> /// <param name="noOfShearStudsX"> Input Number of Shear Stud X Direction</param> /// <param name="noOfShearStudsY"> Input Number of Shear Stud Y Direction</param> /// <param name="studSpacingX"> Input Spacing of Shear Stud X Direction</param> /// <param name="studSpacingY"> Input Spacing of Shear Stud Y Direction</param> /// <param name="shearStudConnectionType"> Input Shear Bolt Connection type - Shop Bolt Default</param> /// <param name="additionalShearStudParameters"> Optional Input ShearStud Build Properties </param> /// <returns name="rectangularShearStudsPattern"> rectangularShearStudsPattern</returns> public static RectangularShearStudsPattern AtCentrePoint(Autodesk.DesignScript.Geometry.Point connectionPoint, Autodesk.DesignScript.Geometry.CoordinateSystem shearStudCS, SteelDbObject objectToConnect, double studLength, double studDiameter, [DefaultArgument("2;")] int noOfShearStudsX, [DefaultArgument("2;")] int noOfShearStudsY, double studSpacingX, double studSpacingY, [DefaultArgument("2;")] int shearStudConnectionType, [DefaultArgument("null")] List <Property> additionalShearStudParameters) { List <SteelDbObject> tempList = new List <SteelDbObject>() { objectToConnect }; List <string> handlesList = Utils.GetSteelDbObjectsToConnect(tempList); var vx = Utils.ToAstVector3d(shearStudCS.XAxis, true); var vy = Utils.ToAstVector3d(shearStudCS.YAxis, true); var vz = Utils.ToAstVector3d(shearStudCS.ZAxis, true); Matrix3d matrix3D = new Matrix3d(); matrix3D.SetCoordSystem(Utils.ToAstPoint(connectionPoint, true), vx, vy, vz); additionalShearStudParameters = PreSetValuesInListProps(additionalShearStudParameters, noOfShearStudsX, noOfShearStudsY, Utils.ToInternalDistanceUnits(studLength, true), Utils.ToInternalDistanceUnits(studDiameter, true)); Utils.CheckListUpdateOrAddValue(additionalShearStudParameters, "Dx", Utils.ToInternalDistanceUnits(studSpacingX, true), "Arranger"); Utils.CheckListUpdateOrAddValue(additionalShearStudParameters, "Dy", Utils.ToInternalDistanceUnits(studSpacingY, true), "Arranger"); return(new RectangularShearStudsPattern(handlesList[0], matrix3D, additionalShearStudParameters, shearStudConnectionType)); }
/// <summary> /// Convert a GeometryObject to an applicable ProtoGeometry type. /// </summary> /// <param name="geom"></param> /// <param name="reference"></param> /// <param name="transform"></param> /// <returns>A Geometry type. Null if there's no suitable conversion.</returns> public static object Convert(this Autodesk.Revit.DB.GeometryObject geom, Autodesk.Revit.DB.Reference reference = null, Autodesk.DesignScript.Geometry.CoordinateSystem transform = null) { if (geom == null) { return(null); } dynamic dynGeom = geom; dynamic protoGeom = null; try { protoGeom = InternalConvert(dynGeom); // if protoGeom is null, Transform will be ambiguous between // IEnumerable<Autodesk.DesignScript.Geometry.Geometry> Transform(IEnumerable<Autodesk.DesignScript.Geometry.Geometry> geom, CoordinateSystem coordinateSystem) // and // Autodesk.DesignScript.Geometry.Geometry Transform(Autodesk.DesignScript.Geometry.Geometry geom, CoordinateSystem coordinateSystem) if (protoGeom == null) { throw new ArgumentNullException(); } return(Tag(Transform(protoGeom, transform), reference)); } catch (Exception e) { DynamoServices.LogWarningMessageEvents.OnLogWarningMessage(Properties.Resources.GeometryConversionFailure + e.Message); return(null); } finally { // Dispose the temporary geometry that has been transformed. DisposeGeometry(protoGeom, transform); } }
protected Text(CoordinateSystem contextCoordinateSystem, Orientation orientation, string textString, double fontSize,bool persist) : base(ByCoordinateSystemCore(contextCoordinateSystem, orientation, textString, fontSize),persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; Orientation = orientation; }
protected Point(CoordinateSystem contextCoordinateSystem, double radius, double theta, double phi,bool persist, int unused) : base(BySphericalCoordinatesCore(contextCoordinateSystem, radius, theta, phi),persist) { InitializeGuaranteedProperties(); Radius = radius; Theta = theta; Phi = phi; }
protected Point(CoordinateSystem contextCoordinateSystem, double radius, double theta, double height,bool persist,bool unused) : base(ByCylindricalCoordinatesCore(contextCoordinateSystem, radius, theta, height),true) { InitializeGuaranteedProperties(); Radius = radius; Theta = theta; Height = height; }
protected Cylinder(CoordinateSystem contextCoordinateSystem, double radius, double height,bool persist) : base(CylinderByRadiusHeightCore(contextCoordinateSystem.CSEntity, radius, height),persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; Radius = radius; Height = height; }
/// <summary> /// Create Advance Steel Standard Grating using Dynamo Coordinate System /// </summary> /// <param name="coordinateSystem"> Input Dynamo Corrdinate System</param> /// <param name="gratingClass"> Input Grating Class</param> /// <param name="gratingName"> Input Grating Size</param> /// <param name="additionalGratingParameters"> Optional Input Grating Build Properties </param> /// <returns name="standardGrating"> grating</returns> public static StandardGrating ByCS(Autodesk.DesignScript.Geometry.CoordinateSystem coordinateSystem, string gratingClass, string gratingName, [DefaultArgument("null")] List <Property> additionalGratingParameters) { additionalGratingParameters = PreSetDefaults(additionalGratingParameters, gratingClass, gratingName); return(new StandardGrating(Utils.ToAstPoint(coordinateSystem.Origin, true), Utils.ToAstVector3d(coordinateSystem.ZAxis, true), additionalGratingParameters)); }
protected Point(CoordinateSystem contextCoordinateSystem, double xTranslation, double yTranslation, double zTranslation,bool persist) : base(ByCartesianCoordinatesCore(contextCoordinateSystem,xTranslation,yTranslation,zTranslation),persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; XTranslation = xTranslation; YTranslation = yTranslation; ZTranslation = zTranslation; }
private SurfaceCurvature(Surface contextSurface, double u, double v, ICoordinateSystemEntity coordinateSystemEntity) { FirstPrincipleCurvature = new Vector(coordinateSystemEntity.XAxis); SecondPrincipleCurvature = new Vector(coordinateSystemEntity.YAxis); GaussianCurvature = FirstPrincipleCurvature.Length * SecondPrincipleCurvature.Length; mPointOnSurface = Point.ToGeometry(coordinateSystemEntity.Origin, false, contextSurface) as Point; U = u; V = v; ContextSurface = contextSurface; mCoordinateSystem = CoordinateSystem.ToCS(coordinateSystemEntity, false); }
/// <summary> /// Create Advance Steel Variable Grating by Dynamo Rectangle and Coordinate System /// </summary> /// <param name="coordinateSystem"> Input Dynamo Coordinate System</param> /// <param name="gratingClass"> Input Grating Class</param> /// <param name="gratingName"> Input Grating Size</param> /// <param name="width"> Input Grating Width</param> /// <param name="length"> Input Grating Length</param> /// <param name="additionalGratingParameters"> Optional Input Grating Build Properties </param> /// <returns name="variableGrating"> grating</returns> public static VariableGrating ByRectangularByCS(Autodesk.DesignScript.Geometry.CoordinateSystem coordinateSystem, string gratingClass, string gratingName, double width, double length, [DefaultArgument("null")] List <Property> additionalGratingParameters) { additionalGratingParameters = PreSetDefaults(additionalGratingParameters, gratingClass, gratingName); return(new VariableGrating(Utils.ToAstPoint(coordinateSystem.Origin, true), Utils.ToAstVector3d(coordinateSystem.ZAxis, true), Utils.ToInternalDistanceUnits(width, true), Utils.ToInternalDistanceUnits(length, true), additionalGratingParameters)); }
/// <summary> /// Create Advance Steel Standard Grating using Dynamo Origin Point and Normal to Grating Plate - Assumes World X Vector to get cross product /// </summary> /// <param name="origin"> Input Dynamo Point</param> /// <param name="normal"> Input Dynamo Vector for Normal to Grating Plane</param> /// <param name="gratingClass"> Input Grating Class</param> /// <param name="gratingName"> Input Grating Size</param> /// <param name="additionalGratingParameters"> Optional Input Grating Build Properties </param> /// <returns name="standardGrating"> grating</returns> public static StandardGrating ByPointAndNormal(Autodesk.DesignScript.Geometry.Point origin, Autodesk.DesignScript.Geometry.Vector normal, string gratingClass, string gratingName, [DefaultArgument("null")] List <Property> additionalGratingParameters) { Vector3d as_normal = Utils.ToAstVector3d(normal, true); Vector3d xWorldVec = Vector3d.kXAxis; Vector3d xYVector = as_normal.CrossProduct(xWorldVec); Autodesk.DesignScript.Geometry.CoordinateSystem coordinateSystem = Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(origin, Utils.ToDynVector(xWorldVec, true), Utils.ToDynVector(xYVector, true)); additionalGratingParameters = PreSetDefaults(additionalGratingParameters, gratingClass, gratingName); return(new StandardGrating(Utils.ToAstPoint(coordinateSystem.Origin, true), Utils.ToAstVector3d(coordinateSystem.ZAxis, true), additionalGratingParameters)); }
public static Autodesk.Revit.DB.BoundingBoxXYZ ToRevitBoundingBox( Autodesk.DesignScript.Geometry.CoordinateSystem cs, Autodesk.DesignScript.Geometry.Point minPoint, Autodesk.DesignScript.Geometry.Point maxPoint, bool convertUnits = true) { var rbb = new BoundingBoxXYZ(); rbb.Enabled = true; rbb.Transform = cs.ToTransform(convertUnits); rbb.Max = maxPoint.ToXyz(convertUnits); rbb.Min = minPoint.ToXyz(convertUnits); return(rbb); }
/// <summary> /// Create an Advance Steel unbounded Rectangular Pattern at a Point /// </summary> /// <param name="connectionPoint"> Input Insertion point of Anchor Bolt Pattern </param> /// <param name="boltCS"> Input Anchor Bolt Coordinate System </param> /// <param name="noOfBoltsX"> Input No of Anchor Bolts in the X direction</param> /// <param name="noOfBoltsY"> Input No of Anchor Bolts in the Y direction</param> /// <param name="objectsToConnect"> Input Objects to be bolted </param> /// <param name="boltConnectionType"> Input Bolt Connection type - Shop Bolt Default</param> /// <param name="additionalAnchorBoltParameters"> Optional Input Anchor Bolt Build Properties </param> /// <returns name="rectangularAnchorPattern"> rectangularAnchorPattern</returns> public static RectangularAnchorPattern AtCentrePoint(Autodesk.DesignScript.Geometry.Point connectionPoint, Autodesk.DesignScript.Geometry.CoordinateSystem boltCS, [DefaultArgument("2;")] int noOfBoltsX, [DefaultArgument("2;")] int noOfBoltsY, IEnumerable <SteelDbObject> objectsToConnect, [DefaultArgument("2;")] int boltConnectionType, [DefaultArgument("null")] List <Property> additionalAnchorBoltParameters) { List <string> handlesList = Utils.GetSteelDbObjectsToConnect(objectsToConnect); var vx = Utils.ToAstVector3d(boltCS.XAxis, true); var vy = Utils.ToAstVector3d(boltCS.YAxis, true); additionalAnchorBoltParameters = PreSetValuesInListProps(additionalAnchorBoltParameters, noOfBoltsX, noOfBoltsY); return(new RectangularAnchorPattern(Utils.ToAstPoint(connectionPoint, true), handlesList, vx, vy, additionalAnchorBoltParameters, boltConnectionType)); }
/// <summary> /// Create an Advance Steel Circular Anchor Pattern By Center Point and Dynamo Coordinate System /// </summary> /// <param name="point"> Input radius center point</param> /// <param name="anchorCS"> Input Dynamo Coordinate System</param> /// <param name="objectsToConnect"> Input Objects to be bolted </param> /// <param name="anchorBoltConnectionType"> Input Bolt Connection type - Shop Bolt Default</param> /// <param name="additionalAnchorBoltParameters"> Optional Input Bolt Build Properties </param> /// <returns name="circularAnchorPattern"> anchor</returns> public static CircularAnchorPattern AtCentrePoint(DynGeometry.Point point, DynGeometry.CoordinateSystem anchorCS, IEnumerable <SteelDbObject> objectsToConnect, [DefaultArgument("2;")] int anchorBoltConnectionType, [DefaultArgument("null")] List <Property> additionalAnchorBoltParameters) { SteelGeometry.Point3d astPointRef = Utils.ToAstPoint(point, true); var vx = Utils.ToAstVector3d(anchorCS.XAxis, true); var vy = Utils.ToAstVector3d(anchorCS.YAxis, true); vx = vx.Normalize(); vy = vy.Normalize(); IEnumerable <string> handles = Utils.GetSteelDbObjectsToConnect(objectsToConnect); return(new CircularAnchorPattern(astPointRef, handles, vx, vy, additionalAnchorBoltParameters, anchorBoltConnectionType)); }
/// <summary> /// Get the edges and faces from the solid and convert them /// </summary> /// <param name="solid"></param> /// <param name="reference"></param> /// <param name="transform"></param> /// <returns></returns> public static IEnumerable <object> ConvertToMany(this Autodesk.Revit.DB.Solid solid, Autodesk.Revit.DB.Reference reference = null, Autodesk.DesignScript.Geometry.CoordinateSystem transform = null) { if (solid == null) { return(null); } try { var convertedGeoms = InternalConvertToMany(solid); return(convertedGeoms.Select(x => { return Tag(Transform(x, transform), reference); })); } catch (Exception) { return(null); } }
/// <summary> /// Convert a GeometryObject to an applicable ProtoGeometry type. /// </summary> /// <param name="geom"></param> /// <param name="reference"></param> /// <param name="transform"></param> /// <returns>A Geometry type. Null if there's no suitable conversion.</returns> public static object Convert(this Autodesk.Revit.DB.GeometryObject geom, Autodesk.Revit.DB.Reference reference = null, Autodesk.DesignScript.Geometry.CoordinateSystem transform = null) { if (geom == null) { return(null); } dynamic dynGeom = geom; try { return(Tag(Transform(InternalConvert(dynGeom), transform), reference)); } catch (RuntimeBinderException) { return(null); } }
/// <summary> /// Convert a GeometryObject to an applicable ProtoGeometry type. /// </summary> /// <param name="geom"></param> /// <param name="reference"></param> /// <param name="transform"></param> /// <returns>A Geometry type. Null if there's no suitable conversion.</returns> public static object Convert(this Autodesk.Revit.DB.GeometryObject geom, Autodesk.Revit.DB.Reference reference = null, Autodesk.DesignScript.Geometry.CoordinateSystem transform = null) { if (geom == null) { return(null); } dynamic dynGeom = geom; dynamic protoGeom = null; try { protoGeom = InternalConvert(dynGeom); return(Tag(Transform(protoGeom, transform), reference)); } catch (Exception) { return(null); } finally { // Dispose the temporary geometry that has been transformed. if (protoGeom != null && transform != null) { if (protoGeom is Autodesk.DesignScript.Geometry.Geometry) { protoGeom.Dispose(); } else if (protoGeom is IEnumerable <Autodesk.DesignScript.Geometry.Geometry> ) { var geoms = protoGeom as IEnumerable <Autodesk.DesignScript.Geometry.Geometry>; foreach (var g in geoms) { if (g != null) { g.Dispose(); } } } } } }
public static Dictionary <string, object> Display(Autodesk.DesignScript.Geometry.CoordinateSystem coordinateSystem, double length = 1000) { //Avoid zero length if (length == 0) { length = 1; } //Origin and Axes var pt = coordinateSystem.Origin; var lineX = Line.ByStartPointDirectionLength(pt, coordinateSystem.XAxis, length); var colorX = DSCore.Color.ByARGB(255, 255, 0, 0); var lineY = Line.ByStartPointDirectionLength(pt, coordinateSystem.YAxis, length); var colorY = DSCore.Color.ByARGB(255, 0, 255, 0); var lineZ = Line.ByStartPointDirectionLength(pt, coordinateSystem.ZAxis, length); var colorZ = DSCore.Color.ByARGB(255, 0, 0, 255); //Build List of Axes List <Modifiers.GeometryColor> display = new List <Modifiers.GeometryColor>(); display.Add(Modifiers.GeometryColor.ByGeometryColor(lineX, colorX)); display.Add(Modifiers.GeometryColor.ByGeometryColor(lineY, colorY)); display.Add(Modifiers.GeometryColor.ByGeometryColor(lineZ, colorZ)); //Dispose of non-returned geometry //pt.Dispose(); //Return values var d = new Dictionary <string, object>(); d.Add("Display", display); d.Add("Origin", pt); d.Add("XAxis", coordinateSystem.XAxis); d.Add("YAxis", coordinateSystem.YAxis); d.Add("ZAxis", coordinateSystem.ZAxis); d.Add("XYPlane", coordinateSystem.XYPlane); d.Add("YZPlane", coordinateSystem.YZPlane); d.Add("ZXPlane", coordinateSystem.ZXPlane); return(d); }
/// <summary> /// /// </summary> /// <param name="other"></param> /// <returns></returns> public CoordinateSystem Multiply(CoordinateSystem other) { if (other == null) throw new System.ArgumentNullException("other"); ICoordinateSystemEntity resultantMat = CSEntity.PostMultiplyBy(other.CSEntity); if (resultantMat == null) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.Multiply")); return new CoordinateSystem(resultantMat, true); }
protected Cone(CoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height, bool persist) : base(ByRadiusHeightCore(contextCoordinateSystem, startRadius, endRadius, height), persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; }
/// <summary> /// Inverts the transformation matrix of the current CoordinateSystem and returns a CoordinateSystem /// </summary> /// <returns>Returns inverted CoordinateSystem</returns> public CoordinateSystem Inverse() { ICoordinateSystemEntity invertedMat = CSEntity.Inverse(); if (null == invertedMat) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.Inverse")); var cs = new CoordinateSystem(invertedMat, true); return cs; }
/// <summary> /// Constructs a CoordinateSystem by transforming a parent CoordinateSystem, by a resultant transformation matrix of scaling [S], rotation [R] and transformation [T] matrices. 'translationSequence' = false implies [S][R][T] otherwise means [S][T][R]. /// </summary> /// <param name="contextCoordinateSystem">the parent coordinate system to be used to construct the coordinate system</param> /// <param name="scaleFactors">the factor by which the parent coordinate system is to be scaled</param> /// <param name="rotationAngles">the rotation angle to be applied to the parent coordinate system</param> /// <param name="rotationSequence">the rotation sequence to be applied to the parent coordinate system</param> /// <param name="translationVector">the translation vector to be applied to the parent coordinate system</param> /// <param name="translationSequence">the translation sequence to be applied to the parent coordinate system</param> /// <returns></returns> public static CoordinateSystem ByUniversalTransform(CoordinateSystem contextCoordinateSystem, double[] scaleFactors, double[] rotationAngles, int[] rotationSequence, Vector translationVector, bool translationSequence) { if (contextCoordinateSystem == null) throw new System.ArgumentNullException("contextCoordinateSystem"); else if (scaleFactors == null) throw new System.ArgumentNullException("scaleFactors"); else if (rotationAngles == null) throw new System.ArgumentNullException("rotationAngles"); else if (rotationSequence == null) throw new System.ArgumentNullException("rotationSequence"); else if (translationVector == null) throw new System.ArgumentNullException("translationVector"); else if (scaleFactors.Length < 3) throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of scale factors", "three"), "scaleFactors"); else if (rotationAngles.Length < 3) throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of rotation angles", "three"), "rotationAngles"); else if (rotationSequence.Length < 3) throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of rotation sequences", "three"), "rotationSequence"); using (var localCSEntity = HostFactory.Factory.CoordinateSystemByUniversalTransform(contextCoordinateSystem.CSEntity, scaleFactors, rotationAngles, rotationSequence, translationVector.IVector, translationSequence)) { if (null == localCSEntity) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.ByUniversalTransform")); var cs = CreateCoordinateSystem(contextCoordinateSystem, localCSEntity, true); cs.ScaleFactors = scaleFactors; cs.RotationAngles = rotationAngles; cs.RotationSequence = rotationSequence; cs.TranslationVector = translationVector; cs.TranslationSequence = translationSequence; return cs; } }
/// <summary> /// Constructs a CoordinateSystem where the x-axis of the CoordinateSystem is tangential to the sphere along the /// latitudinal direction, the z-axis is normal to the spherical surface and the y-axis is along the longitudinal /// direction at the point defined on the sphere by the r, theta, phi values. /// </summary> /// <param name="contextCoordinateSystem"> /// the parent coordinate system to be used to construct the coordinate system /// </param> /// <param name="radius"> /// the radius of the spherical surface /// </param> /// <param name="theta"> /// the theta value of the spherical surface /// </param> /// <param name="phi"> /// the phi value of the spherical surface /// </param> /// <returns> /// CoordinateSystem created in Spherical world /// </returns> public static CoordinateSystem BySphericalCoordinates(CoordinateSystem contextCoordinateSystem, double radius, double theta, double phi) { // what can be the constraints on theta if (contextCoordinateSystem == null) throw new System.ArgumentNullException("contextCoordinateSystem "); else if (radius.EqualsTo(0.0)) throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "radius"), "radius"); using (var localCSEntity = HostFactory.Factory.CoordinateSystemBySphericalCoordinates(WCS.CSEntity, radius, theta, phi)) { if (null == localCSEntity) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.BySphericalCoordinates")); var cylCS = CreateCoordinateSystem(contextCoordinateSystem, localCSEntity, true); cylCS.Radius = radius; cylCS.Theta = theta; cylCS.Phi = phi; return cylCS; } }
internal static CoordinateSystem ByOriginVectors(Point origin, Vector xAxis, Vector yAxis, Vector zAxis, bool isSheared, bool isNormalized, bool visible) { if (origin == null) throw new System.ArgumentNullException("origin"); else if (xAxis == null) throw new System.ArgumentNullException("xAxis"); else if (yAxis == null) throw new System.ArgumentNullException("yAxis"); else if (zAxis == null) throw new System.ArgumentNullException("zAxis"); else if (xAxis.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "x axis"), "xAxis"); else if (yAxis.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "y axis"), "yAxis"); else if (zAxis.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "z axis"), "zAxis"); else if (xAxis.IsParallel(yAxis)) throw new System.ArgumentException(string.Format(Properties.Resources.IsParallel, "x axis", "y axis", "CoordinateSystem.ByOriginVectors"), "xAxis, yAxis"); else if (!isSheared && (!xAxis.IsPerpendicular(yAxis) || !yAxis.IsPerpendicular(zAxis) || !zAxis.IsPerpendicular(xAxis))) { // this is not the case for sheared but axes are not orthogonal // zAxis = xAxis.Cross(yAxis); yAxis = zAxis.Cross(xAxis); } if (isNormalized) { xAxis = xAxis.Normalize(); yAxis = yAxis.Normalize(); zAxis = zAxis.Normalize(); } var cs = HostFactory.Factory.CoordinateSystemByData(null); //create identity matrix if (null == cs) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.ByOriginVectors")); cs.Set(origin.PointEntity, xAxis.IVector, yAxis.IVector, zAxis.IVector); var coordSys = new CoordinateSystem(cs, visible); return coordSys; }
/// <summary> /// Scales the given CoordinateSystem by a non-uniform scaling factor along each axis /// </summary> /// <param name="scaleX"></param> /// <param name="scaleY"></param> /// <param name="scaleZ"></param> /// <returns></returns> public CoordinateSystem Scale(double scaleX, double scaleY, double scaleZ) { if (GeometryExtension.Equals(scaleX, 0.0)) { throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "scale x"), "scaleX"); } else if (GeometryExtension.Equals(scaleY, 0.0)) { throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "scale y"), "scaleY"); } else if (GeometryExtension.Equals(scaleZ, 0.0)) { throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "scale z"), "scaleZ"); } var scaledCsEntity = CSEntity.Scale(scaleX, scaleY, scaleZ); var cs = new CoordinateSystem(scaledCsEntity, true); return cs; }
internal static IBlockEntity InsertCore(CoordinateSystem contextCoordinateSystem, string blockName) { string kMethodName = "Block.ByCoordinateSystem "; if (null == contextCoordinateSystem) throw new ArgumentNullException("contextCoordinateSystem"); if (contextCoordinateSystem.IsSheared) throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem"); if (string.IsNullOrEmpty(blockName)) throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName"); IBlockHelper helper = HostFactory.Factory.GetBlockHelper(); if (null == helper) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); if (!helper.BlockExistsInCurrentDocument(blockName)) throw new System.ArgumentException(string.Format(Properties.Resources.DoesNotExist, "Block : " + blockName)); IBlockEntity entity = helper.InsertBlockFromCurrentDocument(contextCoordinateSystem.CSEntity, blockName); if (null == entity) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName)); return entity; }
internal static IBlockEntity InsertCore(CoordinateSystem contextCoordinateSystem, ref string fileName, string blockName) { string kMethodName = "Block.ByCoordinateSystem "; if (null == contextCoordinateSystem) throw new ArgumentNullException("contextCoordinateSystem"); if (contextCoordinateSystem.IsSheared) throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem"); if (string.IsNullOrEmpty(blockName)) throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName"); fileName = GeometryExtension.LocateFile(fileName); if (!File.Exists(fileName)) throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, fileName), "fileName"); IBlockHelper helper = HostFactory.Factory.GetBlockHelper(); if (null == helper) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); IBlockEntity entity = helper.InsertBlockFromFile(contextCoordinateSystem.CSEntity, fileName, blockName); if (null == entity) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName)); return entity; }
/// <summary> /// Instantiates the specified block by name with the orientation /// specified by the coordinate system /// </summary> /// <param name="contextCoordinateSystem"> /// Specifies the orientation of the block. Origin is the placement point. /// This coordinate system must be orthogonal, can be non-uniformly scaled /// </param> /// <returns>BlockInstance</returns> public BlockInstance ByCoordinateSystem(CoordinateSystem contextCoordinateSystem) { return new BlockInstance(contextCoordinateSystem, Name, true); }
/// <summary> /// Creates a block with the given name, reference coordinate system and from the /// specified geometries /// </summary> /// <param name="blockName">the block name</param> /// <param name="referenceCoordinateSystem">the reference coordinate system</param> /// <param name="contents">the geometries contained in the block</param> /// <returns></returns> public static Block FromGeometry(string blockName, CoordinateSystem referenceCoordinateSystem, Geometry[] contents) { string kMethodName = "Block.FromGeometry"; if (null == referenceCoordinateSystem) throw new ArgumentNullException("contextCoordinateSystem"); if (string.IsNullOrEmpty(blockName)) throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName"); IGeometryEntity[] hosts = contents.ConvertAll(GeometryExtension.ToEntity<Geometry, IGeometryEntity>); if (null == hosts || hosts.Length == 0) throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, "geometries", kMethodName), "geometries"); IBlockHelper helper = HostFactory.Factory.GetBlockHelper(); if (null == helper) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); if (helper.DefineBlock(referenceCoordinateSystem.CSEntity, blockName, hosts)) { return new Block(blockName); } return null; }
private static Plane FromCoordinateSystem(CoordinateSystem cs) { if (null == cs) return null; Plane plane = Plane.ByOriginNormal(cs.Origin, cs.ZAxis); if (null == plane) return null; plane.ContextCoordinateSystem = cs; return plane; }
/// <summary> /// /// </summary> /// <param name="leftSide"></param> /// <returns></returns> public CoordinateSystem PreMultiplyBy(CoordinateSystem leftSide) { if (leftSide == null) throw new System.ArgumentNullException("leftSide"); ICoordinateSystemEntity resultantMat = CSEntity.PreMultiplyBy(leftSide.CSEntity); if (null == resultantMat) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.PreMultiplyBy")); return new CoordinateSystem(resultantMat, true); }
/// <summary> /// Rotates the input CoordinateSystem about its own axes and about the global origin (0,0,0) by the given rotation angles /// in the given rotation sequence. The rotation angles are always specified in the order of rotation about (xAxis, yAxis, zAxis). /// </summary> /// <param name="rotationAngle">The angle to be rotated through</param> /// <param name="axis">The axis to be rotated about</param> /// <param name="origin">The global origin</param> /// <returns>Returns a rotated CoordinateSystem</returns> public CoordinateSystem Rotate(double rotationAngle, Vector axis, Point origin) { if (axis == null) throw new System.ArgumentNullException("axis"); else if (origin == null) throw new System.ArgumentNullException("origin"); else if (axis.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "axis"), "axis"); var rotatedCSEntity = CSEntity.Rotation(rotationAngle, axis.IVector, origin.PointEntity); var cs = new CoordinateSystem(rotatedCSEntity, true); return cs; }
internal BlockInstance(CoordinateSystem contextCoordinateSystem, string blockName, bool persist) : base(Block.InsertCore(contextCoordinateSystem, blockName),persist) { Definition = new Block(blockName); ContextCoordinateSystem = contextCoordinateSystem; }
/// <summary> /// Translates the coordinate system in the direction of the vector and by the distance specified /// </summary> /// <param name="translationVector">The direction of translation</param> /// <param name="distance">The distance of translation</param> /// <returns></returns> public CoordinateSystem Translate(Vector translationVector, double distance) { if (translationVector == null) { throw new System.ArgumentNullException("translationVector"); } translationVector = translationVector.Normalize().MultiplyBy(distance); var translatedCSEntity = CSEntity.Translate(translationVector.IVector); var cs = new CoordinateSystem(translatedCSEntity, true); return cs; }
/// <summary> /// Constructs a cuboid on a coordinate system with length on X Axis, width on Y Axis and Height on Z Axis. The origin of coordinate system is the centroid of the cuboid. /// </summary> /// <param name="contextCoordinateSystem">The parent CoordinateSystem of the cuboid</param> /// <param name="length">The length of the cuboid</param> /// <param name="width">The width of the cuboid</param> /// <param name="height">The height of the cuboid</param> /// <returns></returns> public static Cuboid ByLengths(CoordinateSystem contextCoordinateSystem, double length, double width, double height) { return new Cuboid(contextCoordinateSystem, length, width, height, true); }
private static CoordinateSystem CreateCoordinateSystem(CoordinateSystem contextCoordinateSystem, ICoordinateSystemEntity localCoordSys, bool visible) { ICoordinateSystemEntity csEntity = contextCoordinateSystem.CSEntity.PostMultiplyBy(localCoordSys); var cs = new CoordinateSystem(csEntity, visible); cs.ContextCoordinateSystem = contextCoordinateSystem; cs.LocalXAxis = new Vector(localCoordSys.XAxis); cs.LocalYAxis = new Vector(localCoordSys.YAxis); cs.LocalZAxis = new Vector(localCoordSys.ZAxis); cs.XTranslation = localCoordSys.Origin.X; cs.YTranslation = localCoordSys.Origin.Y; cs.ZTranslation = localCoordSys.Origin.Z; return cs; }
protected Cuboid(CoordinateSystem contextCoordinateSystem, double length, double width, double height,bool persist) : base(CuboidByLengthsCore(contextCoordinateSystem.CSEntity, length, width, height),persist) { InitializeGuaranteedProperties(); }
/// <summary> /// Constructs a CoordinateSystem by transforming a parent CoordinateSystem, by a resultant transformation matrix of scaling [S], rotation [R] and transformation [T] matrices in the order [S][R][T]. /// </summary> /// <param name="contextCoordinateSystem">the parent coordinate system to be used to construct the coordinate system</param> /// <param name="scaleFactors">the factor by which the parent coordinate system is to be scaled</param> /// <param name="rotationAngles">the rotation angle to be applied to the parent coordinate system</param> /// <param name="rotationSequence">the rotation sequence to be applied to the parent coordinate system</param> /// <param name="translationVector">the translation vector to be applied to the parent coordinate system</param> /// <returns></returns> public static CoordinateSystem ByUniversalTransform(CoordinateSystem contextCoordinateSystem, double[] scaleFactors, double[] rotationAngles, int[] rotationSequence, double[] translationVector) { return ByUniversalTransform(contextCoordinateSystem, scaleFactors, rotationAngles, rotationSequence, translationVector, false); }
/// <summary> /// Constructs a solid cone defined a parent CoordinateSystem, start radius, end radius and height /// </summary> /// <param name="contextCoordinateSystem">The parent CoordinateSystem of the cone</param> /// <param name="startRadius">The radius of the base of the cone</param> /// <param name="endRadius">The radius of the top of the cone</param> /// <param name="height">The height of the cone</param> /// <returns></returns> public static Cone ByRadiusHeight(CoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height) { return new Cone(contextCoordinateSystem, startRadius, endRadius, height, true); }
/// <summary> /// /// </summary> /// <returns></returns> public static CoordinateSystem Identity() { var cs = HostFactory.Factory.CoordinateSystemByData(null); //create identity matrix if (null == cs) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.Identity")); CoordinateSystem coordSys = new CoordinateSystem(cs, true); coordSys.IsNormalized = true; return coordSys; }
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档 Application revitApp = commandData.Application.Application; //取得应用程序 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 Document document = commandData.Application.ActiveUIDocument.Document; Window1 window1 = new Window1(); //载入族 FamilySymbol familySymbol; using (Transaction tran = new Transaction(uiDoc.Document)) { tran.Start("载入族"); //载入弦杆族 string file = @"C:\Users\zyx\Desktop\2RevitArcBridge\CrossBeam\CrossBeam\source\crossBeam.rfa"; familySymbol = loadFaimly(file, commandData); familySymbol.Activate(); tran.Commit(); } //把这组模型线通过获取首尾点,生成dynamo里的curve List <XYZ> ps = new List <XYZ>(); using (Transaction transaction = new Transaction(uiDoc.Document)) { transaction.Start("选取模型线生成Curve"); Selection sel = uiDoc.Selection; IList <Reference> modelLines = sel.PickObjects(ObjectType.Element, "选一组模型线"); foreach (Reference reference in modelLines) { Element elem = revitDoc.GetElement(reference); ModelLine modelLine = elem as ModelLine; Autodesk.Revit.DB.Curve c = modelLine.GeometryCurve; ps.Add(c.GetEndPoint(0)); ps.Add(c.GetEndPoint(1)); } for (int i = ps.Count - 1; i > 0; i--) { XYZ p1 = ps[i]; XYZ p2 = ps[i - 1]; //注意此处重合点有一个闭合差 if (p1.DistanceTo(p2) < 0.0001) { ps.RemoveAt(i); } } transaction.Commit(); } //做一个revit和dynamo点的转换 DG.CoordinateSystem coordinateSystem = DG.CoordinateSystem.ByOrigin(0, 0, 0);//标准坐标系 List <DG.Point> DGps = new List <DG.Point>(); foreach (XYZ p in ps) { DGps.Add(p.ToPoint(false)); } DG.PolyCurve polyCurve = DG.PolyCurve.ByPoints(DGps); DG.Curve curve = polyCurve as DG.Curve; List <DG.Point> DGCBps = new List <DG.Point>();//横梁的放置点位列表 double StartLength = 0; if (window1.ShowDialog() == true) { //窗口打开并停留,只有点击按键之后,窗口关闭并返回true } //按键会改变window的属性,通过对属性的循环判断来实现对按键的监测 while (!window1.Done) { //选择起点 if (window1.StartPointSelected) { using (Transaction transaction = new Transaction(uiDoc.Document)) { transaction.Start("选择起点"); double r1 = SelectPoint(commandData); DG.Point dgp1 = curve.PointAtParameter(r1); DGCBps.Add(dgp1); StartLength = curve.SegmentLengthAtParameter(r1); transaction.Commit(); } //2、重置window1.StartPointSelected window1.StartPointSelected = false; } if (window1.ShowDialog() == true) { //窗口打开并停留,只有点击按键之后,窗口关闭并返回true } } //在这里根据间距获取到各个点 for (int i = 1; i < window1.cbNumber; i++) { double L = StartLength + window1.cbDistance * i; DG.Point point = curve.PointAtSegmentLength(L); DGCBps.Add(point); MessageBox.Show(i.ToString()); } List <FamilyInstance> instances = new List <FamilyInstance>(); using (Transaction transaction = new Transaction(uiDoc.Document)) { transaction.Start("创建横梁实例"); foreach (DG.Point p in DGCBps) { FamilyInstance familyInstance; familyInstance = CreateFamlyInstance(p, curve, familySymbol, commandData); instances.Add(familyInstance); } transaction.Commit(); } //给每个族实例设置参数 using (Transaction transaction = new Transaction(uiDoc.Document)) { transaction.Start("族实例参数设置"); foreach (FamilyInstance instance in instances) { double h1 = instance.LookupParameter("l1/2").AsDouble(); instance.LookupParameter("l1/2").Set(window1.l1 / 2); instance.LookupParameter("l2").Set(window1.l2); //instance.LookupParameter("h1").Set(window1.l1); //instance.LookupParameter("h2").Set(window1.l1); } transaction.Commit(); } return(Result.Succeeded); }
/// <summary> /// Instantiates the specified block by name with the orientation /// specified by the coordinate system into the target file. /// If the block does not exist in the target file, the block will be exported to the /// target file first. /// If the block already exists in the target file, the old block will be replaced with /// the new one. /// </summary> /// <param name="contextCoordinateSystem"> /// Specifies the orientation of the block. Origin is the placement point. /// This coordinate system must be orthogonal, can be non-uniformly scaled /// </param> /// <param name="targetFileName">the outside file name</param> /// <returns>If the insertion succeeds, returns true</returns> public bool ByCoordinateSystem(CoordinateSystem contextCoordinateSystem, string targetFileName) { string kMethodName = "Block.ByCoordinateSystem "; if (null == contextCoordinateSystem) throw new ArgumentNullException("contextCoordinateSystem"); if (contextCoordinateSystem.IsSheared) throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem"); if (string.IsNullOrEmpty(targetFileName)) throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, Name, kMethodName), "blockName"); targetFileName = Geometry.GetFullPath(targetFileName); IBlockHelper helper = HostFactory.Factory.GetBlockHelper(); if (null == helper) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); return helper.InsertBlockInTargetFile(contextCoordinateSystem.CSEntity, Name, targetFileName); }
private static IConeEntity ByRadiusHeightCore(CoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height) { string kMethod = "Cone.ByRadiusHeight"; if (startRadius.LessThanOrEqualTo(0.0)) throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "start radius"), "startRadius"); if (endRadius < 0.0) throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "end radius"), "endRadius"); if (height.LessThanOrEqualTo(0.0)) throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "height"), "height"); if (null == contextCoordinateSystem) throw new System.ArgumentNullException("contextCoordinateSystem"); if (!contextCoordinateSystem.IsUniscaledOrtho()) { if (contextCoordinateSystem.IsScaledOrtho()) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "Non Uniform Scaled CoordinateSystem", kMethod)); else throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "Shear CoordinateSystem", kMethod)); } IConeEntity entity = HostFactory.Factory.ConeByRadiusLength(contextCoordinateSystem.CSEntity, startRadius, endRadius, height); if (null == entity) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethod)); return entity; }