コード例 #1
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
        private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ location,
                                        Autodesk.Revit.DB.XYZ referenceDirection)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document);

            //There was an existing family instance, rebind to that, and adjust its position
            if (oldFam != null && oldFam.HostFace.ElementId == reference.ElementId)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetFamilySymbol(fs);
                InternalSetPosition(location);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(Document);

            //If the symbol is not active, then activate it
            if (!fs.IsActive)
            {
                fs.Activate();
            }

            var fi = Document.IsFamilyDocument
                ? Document.FamilyCreate.NewFamilyInstance(reference, location, referenceDirection, fs)
                : Document.Create.NewFamilyInstance(reference, location, referenceDirection, fs);

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
コード例 #2
0
        private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Line line, Autodesk.Revit.DB.Level level)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(DocumentManager.Instance.CurrentDBDocument);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetLevel(level);
                InternalSetFamilySymbol(fs);
                InternalSetPosition(line);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            //If the symbol is not active, then activate it
            if (!fs.IsActive)
            {
                fs.Activate();
            }

            var fi = DocumentManager.Instance.CurrentDBDocument.Create.NewFamilyInstance(line, fs, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            ((Autodesk.Revit.DB.LocationCurve)fi.Location).Curve = line;

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
コード例 #3
0
ファイル: FamilyInstances.cs プロジェクト: jpahlow/archilab
        private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.View view)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(DocumentManager.Instance.CurrentDBDocument);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetFamilySymbol(fs);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            //If the symbol is not active, then activate it
            if (!fs.IsActive)
            {
                fs.Activate();
            }

            var fi = DocumentManager.Instance.CurrentDBDocument.Create.NewFamilyInstance(point, fs, view);

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
コード例 #4
0
        protected void InternalSetFamilySymbol(Autodesk.Revit.DB.FamilySymbol fs)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            // Don't attempt to set the symbol if it is the same.
            // Doing so will raise a document modification event which
            // will, in turn, be responded to by this node causing an infinite loop.
            if (InternalFamilyInstance.Symbol.UniqueId != fs.UniqueId)
            {
                InternalFamilyInstance.Symbol = fs;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
コード例 #5
0
 internal FamilyInstances(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Line line, Autodesk.Revit.DB.Level level)
 {
     SafeInit(() => InitFamilyInstance(fs, line, level));
 }
コード例 #6
0
ファイル: FamilyInstances.cs プロジェクト: jpahlow/archilab
 internal FamilyInstances(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.View view)
 {
     SafeInit(() => InitFamilyInstance(fs, point, view));
 }
コード例 #7
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
 internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ location, Autodesk.Revit.DB.XYZ referenceDirection)
 {
     SafeInit(() => InitFamilyInstance(fs, reference, location, referenceDirection));
 }
コード例 #8
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
 internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.Line pos)
 {
     SafeInit(() => InitFamilyInstance(fs, reference, pos));
 }
コード例 #9
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
 /// <summary>
 /// Internal constructor for a FamilyInstance
 /// </summary>
 internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ pos)
 {
     SafeInit(() => InitFamilyInstance(fs, pos));
 }
コード例 #10
0
 internal FamilyInstances(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ referenceDir)
 {
     SafeInit(() => InitFamilyInstance(fs, point, reference, referenceDir));
 }
コード例 #11
0
 internal FamilyInstances(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.Element host, Autodesk.Revit.DB.Level level)
 {
     SafeInit(() => InitFamilyInstance(fs, point, host, level));
 }
コード例 #12
0
        /// <summary>
        /// Initialize a StructuralFraming element
        /// </summary>
        private void InitStructuralFraming(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetFamilySymbol(symbol);
                InternalSetCurve(curve);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(Document);

            var creationData = GetCreationData(curve, upVector, level, structuralType, symbol);

            Autodesk.Revit.DB.FamilyInstance fi;
            if (Document.IsFamilyDocument)
            {
                var elementIds = Document.FamilyCreate.NewFamilyInstances2(new List <FamilyInstanceCreationData>()
                {
                    creationData
                });

                if (elementIds.Count == 0)
                {
                    throw new Exception(Properties.Resources.FamilyInstanceCreationFailure);
                }

                fi = (Autodesk.Revit.DB.FamilyInstance)Document.GetElement(elementIds.First());
            }
            else
            {
                var elementIds = Document.Create.NewFamilyInstances2(new List <FamilyInstanceCreationData>()
                {
                    creationData
                });

                if (elementIds.Count == 0)
                {
                    throw new Exception(Properties.Resources.FamilyInstanceCreationFailure);
                }

                fi = (Autodesk.Revit.DB.FamilyInstance)Document.GetElement(elementIds.First());
            }

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
コード例 #13
0
 /// <summary>
 /// Internal constructor - creates a single StructuralFraming instance
 /// </summary>
 internal StructuralFraming(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.Level level,
                            Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
 {
     SafeInit(() => InitStructuralFraming(curve, level, structuralType, symbol));
 }
コード例 #14
0
 private static FamilyInstanceCreationData GetCreationData(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
 {
     return(new FamilyInstanceCreationData(curve, symbol, level, structuralType));
 }
コード例 #15
0
        private static FamilyInstanceCreationData GetCreationData(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
        {
            //calculate the desired rotation
            //we do this by finding the angle between the z axis
            //and vector between the start of the beam and the target point
            //both projected onto the start plane of the beam.
            var zAxis = new Autodesk.Revit.DB.XYZ(0, 0, 1);
            var yAxis = new Autodesk.Revit.DB.XYZ(0, 1, 0);

            //flatten the beam line onto the XZ plane
            //using the start's z coordinate
            var start  = curve.GetEndPoint(0);
            var end    = curve.GetEndPoint(1);
            var newEnd = new Autodesk.Revit.DB.XYZ(end.X, end.Y, start.Z); //drop end point to plane

            //catch the case where the end is directly above
            //the start, creating a normal with zero length
            //in that case, use the Z axis
            var planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize();

            var gamma = upVector.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal);

            return(new FamilyInstanceCreationData(curve, symbol, level, structuralType)
            {
                RotateAngle = gamma
            });
        }