Example #1
0
        public BlockReference Insert(InsertData blData, Action <Exception, DynProp, BlockReference>?setDynPropException = null)
        {
            if (!_templates.TryGetValue(blData, out var template))
            {
                template = InsertTemplate(blData, setDynPropException);
                _templates.Add(blData, template);
            }

            var blRef  = template.Id.CopyEnt(blData.Owner.Id).GetObject <BlockReference>(OpenMode.ForWrite);
            var matrix = Matrix3d.Identity;
            var vec    = blData.Point - blRef.Position;

            if (vec.Length > 0)
            {
                matrix = Matrix3d.Displacement(vec);
            }

            if (Math.Abs(blData.Scale - 1) > 0.0001)
            {
                matrix.PreMultiplyBy(Matrix3d.Scaling(blData.Scale, blRef.Position));
            }

            if (!matrix.IsEqualTo(Matrix3d.Identity))
            {
                blRef.TransformBy(matrix);
            }

            return(blRef);
        }
Example #2
0
        private BlockReference InsertTemplate(InsertData blData, Action <Exception, DynProp, BlockReference>?setDynPropException)
        {
            var owner  = blData.Btr.Database.MS(OpenMode.ForWrite);
            var blRef  = BlockInsert.InsertBlockRef(blData.Btr, Point3d.Origin, owner, blData.Transaction, blData.Scale);
            var blBase = new BlockBase(blRef, blData.Btr.Name);

            foreach (var dynProp in blData.DynProps)
            {
                try
                {
                    blBase.FillPropValue(dynProp.Name, dynProp.Value, dynProp.ExactMatch, dynProp.IsRequired);
                }
                catch (Exception ex)
                {
                    setDynPropException?.Invoke(ex, dynProp, blRef);
                    ex.LogError();
                }
            }

            return(blRef);
        }