Exemplo n.º 1
0
        /// <summary>
        /// Initialize a DirectShape element
        /// </summary>
        private void InitDirectShape(DesignScriptEntity shapeReference,
                                     string shapeName,
                                     Category category,
                                     Material material)
        {
            //Phase 1 - Check to see if a DirectShape exists in trace and should be rebound
            var oldShape =
                ElementBinder.GetElementAndTraceData <Autodesk.Revit.DB.DirectShape, DirectShapeState>(Document);

            //There was a oldDirectShape, rebind to that
            if (oldShape != null)
            {
                //set the directshape element
                this.InternalSetDirectShape(oldShape.Item1);

                //if the cateogryID has changed, we cannot continue to rebind and instead
                //will make a new directShape
                if (category.Id == this.InternalElement.Category.Id.IntegerValue)
                {
                    //set the shape geometry of the directshape, this method passes in the actual input geo
                    //and checks the directShapeState object at the elementId key in the input geo tags dictionary.
                    //this check is used to determine if the geometry should be updated, this is done by checking
                    //the sync guid in the DirectShapeState (a guid that is generated when geometry changes on
                    //the revit element.
                    //we also check the material, if it's different than the currently assigned material
                    //then we need to rebuild the geo so that a new material is applied
                    //
                    this.InternalSetShape(shapeReference, new ElementId(material.Id), oldShape.Item2.syncId);
                    this.InternalSetName(shapeReference, shapeName, material, category);
                    return;
                }
            }

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

            Autodesk.Revit.DB.DirectShape ds;

            //generate the geometry correctly depending on the type of geo
            var tessellatedShape = GenerateTessellatedGeo(shapeReference, new ElementId(material.Id));

            //actually construct the directshape revit element
            ds = NewDirectShape(tessellatedShape,
                                Document, new ElementId(category.Id),
                                DirectShape.DYNAMO_DIRECTSHAPE_APP_GUID.ToString(), shapeName);

            InternalSetDirectShape(ds);
            InternalSetName(shapeReference, shapeName, material, category);
            //generate a new syncId for trace
            var traceData = new DirectShapeState(this, Guid.NewGuid().ToString(), new ElementId(material.Id));

            //add the elementID:tracedata to the tags dictionary on the real protogeometry input
            shapeReference.Tags.AddTag(this.InternalElementId.ToString(), traceData);
            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetRawDataForTrace(traceData);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize a Level element
        /// </summary>
        /// <param name="elevation"></param>
        /// <param name="name"></param>
        private void InitLevel(double elevation, string name)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle = ElementBinder.GetElementAndTraceData <Autodesk.Revit.DB.Level, LevelTraceData>(Document);

            //There was an element, bind & mutate
            if (oldEle != null)
            {
                InternalSetLevel(oldEle.Item1);
                InternalSetElevation(elevation);
                InternalSetName(oldEle.Item2.InputName, name);
                return;
            }

            //There was no element, create a new one
            TransactionManager.Instance.EnsureInTransaction(Document);

            Autodesk.Revit.DB.Level level;

            if (Document.IsFamilyDocument)
            {
                level = Autodesk.Revit.DB.Level.Create(Document, elevation);
            }
            else
            {
                level = Autodesk.Revit.DB.Level.Create(Document, elevation);
            }

            InternalSetLevel(level);
            InternalSetName(string.Empty, name);
            var traceData = new LevelTraceData(this, name);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetRawDataForTrace(traceData);
        }