예제 #1
0
        public List <ApplicationPlaceholderObject> AnalyticalStickToNative(Element1D speckleStick)
        {
            List <ApplicationPlaceholderObject> placeholderObjects = new List <ApplicationPlaceholderObject> {
            };
            XYZ offset1 = VectorToNative(speckleStick.end1Offset);
            XYZ offset2 = VectorToNative(speckleStick.end2Offset);
            List <ApplicationPlaceholderObject> placeholders = new List <ApplicationPlaceholderObject> {
            };

            switch (speckleStick.type)
            {
            case ElementType1D.Beam:
                RevitBeam revitBeam = new RevitBeam();
                //This only works for CSIC sections now for sure. Need to test on other sections
                revitBeam.type     = speckleStick.property.name.Replace('X', 'x');
                revitBeam.baseLine = speckleStick.baseLine;
                //Beam beam = new Beam(speckleStick.baseLine);
                placeholders = BeamToNative(revitBeam);
                DB.FamilyInstance    nativeRevitBeam = (DB.FamilyInstance)placeholders[0].NativeObject;
                AnalyticalModelStick analyticalModel = (AnalyticalModelStick)nativeRevitBeam.GetAnalyticalModel();
                analyticalModel.SetReleases(true, Convert.ToBoolean(speckleStick.end1Releases.stiffnessX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end1Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZZ));
                analyticalModel.SetReleases(false, Convert.ToBoolean(speckleStick.end2Releases.stiffnessX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end2Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZZ));
                analyticalModel.SetOffset(AnalyticalElementSelector.StartOrBase, offset1);
                analyticalModel.SetOffset(AnalyticalElementSelector.EndOrTop, offset2);
//analyticalModel.
                return(placeholders);

            case ElementType1D.Brace:
                RevitBrace revitBrace = new RevitBrace();
                revitBrace.type     = speckleStick.property.name.Replace('X', 'x');
                revitBrace.baseLine = speckleStick.baseLine;
                //Brace brace = new Brace(speckleStick.baseLine);
                placeholders = BraceToNative(revitBrace);
                DB.FamilyInstance nativeRevitBrace = (DB.FamilyInstance)placeholders[0].NativeObject;
                analyticalModel = (AnalyticalModelStick)nativeRevitBrace.GetAnalyticalModel();
                analyticalModel.SetReleases(true, Convert.ToBoolean(speckleStick.end1Releases.stiffnessX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end1Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZZ));
                analyticalModel.SetReleases(false, Convert.ToBoolean(speckleStick.end2Releases.stiffnessX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end2Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZZ));
                analyticalModel.SetOffset(AnalyticalElementSelector.StartOrBase, offset1);
                analyticalModel.SetOffset(AnalyticalElementSelector.EndOrTop, offset2);
                return(placeholders);

            case ElementType1D.Column:
                RevitColumn revitColumn = new RevitColumn();
                revitColumn.type     = speckleStick.property.name.Replace('X', 'x');
                revitColumn.baseLine = speckleStick.baseLine;
                placeholders         = ColumnToNative(revitColumn);
                DB.FamilyInstance     nativeRevitColumn  = (DB.FamilyInstance)placeholders[0].NativeObject;
                AnalyticalModelColumn analyticalModelCol = (AnalyticalModelColumn)nativeRevitColumn.GetAnalyticalModel();
                analyticalModelCol.SetReleases(true, Convert.ToBoolean(speckleStick.end1Releases.stiffnessX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end1Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZZ));
                analyticalModelCol.SetReleases(false, Convert.ToBoolean(speckleStick.end2Releases.stiffnessX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end2Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZZ));
                analyticalModelCol.SetOffset(AnalyticalElementSelector.StartOrBase, offset1);
                analyticalModelCol.SetOffset(AnalyticalElementSelector.EndOrTop, offset2);
                return(placeholders);

                //Column column = new Column(speckleStick.baseLine);
                return(ColumnToNative(revitColumn));
            }
            return(placeholderObjects);
        }
예제 #2
0
        public static SpeckleObject ColumnToSpeckle(Autodesk.Revit.DB.FamilyInstance myFamily)
        {
            var myColumn = new Column();

            var baseLevel = (Autodesk.Revit.DB.Level)Doc.GetElement(myFamily.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).AsElementId());
            var topLevel  = (Autodesk.Revit.DB.Level)Doc.GetElement(myFamily.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).AsElementId());

            myColumn.baseLevel = baseLevel?.ToSpeckle();
            myColumn.topLevel  = topLevel?.ToSpeckle();

            try
            {
                myColumn.baseLine = (SpeckleCoreGeometryClasses.SpeckleLine)SpeckleCore.Converter.Serialise(myFamily.GetAnalyticalModel().GetCurve());
            }
            catch
            {
                var basePt = (myFamily.Location as LocationPoint).Point;
                var topPt  = new XYZ(basePt.X, basePt.Y, topLevel.Elevation);
                myColumn.baseLine = (SpeckleCoreGeometryClasses.SpeckleLine)SpeckleCore.Converter.Serialise(Autodesk.Revit.DB.Line.CreateBound(basePt, topPt));
            }

            myColumn.columnFamily = myFamily.Symbol.FamilyName;
            myColumn.columnType   = Doc.GetElement(myFamily.GetTypeId()).Name;

            myColumn.parameters = GetElementParams(myFamily);



            // TODO: Maybe move this column properties in the class defintion
            myColumn.Properties["__facingFlipped"] = myFamily.FacingFlipped;
            myColumn.Properties["__handFlipped"]   = myFamily.HandFlipped;

            if (myFamily.Location is LocationPoint)
            {
                myColumn.Properties["__rotation"] = ((LocationPoint)myFamily.Location).Rotation;
            }
            else if (myFamily.Location is LocationCurve)
            {
                var myAngle = myFamily.get_Parameter(BuiltInParameter.STRUCTURAL_BEND_DIR_ANGLE).AsDouble(); // Stands for cross-section rotation!
                var rads    = UnitUtils.ConvertFromInternalUnits(myAngle, DisplayUnitType.DUT_RADIANS);
                myColumn.Properties["__rotation"] = rads;

                // TODO: Figure this column rotation shit out.
                // For now... Do nothing??
                //var t = myFamily.GetTotalTransform();
            }


            myColumn.GenerateHash();
            myColumn.ApplicationId = myFamily.UniqueId;
            myColumn.elementId     = myFamily.Id.ToString();

            // leaving the mesh out of the hashing process might address the randomatic hash generation we're getting
            // and hence the nuking the usability of local caching and diffing
            var allSolids = GetElementSolids(myFamily, opt: new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = true
            });

            (myColumn.Faces, myColumn.Vertices) = GetFaceVertexArrFromSolids(allSolids);

            return(myColumn);
        }