Beispiel #1
0
        public string BlockInstanceToNativeDB(BlockInstance instance, out BlockReference reference, bool AppendToModelSpace = true)
        {
            string result = null;

            reference = null;

            // block definition
            ObjectId definitionId = BlockDefinitionToNativeDB(instance.blockDefinition);

            if (definitionId == ObjectId.Null)
            {
                return(result);
            }

            // insertion pt
            Point3d insertionPoint = PointToNative(instance.GetInsertionPoint());

            // transform
            double[] transform = instance.transform.value;
            for (int i = 3; i < 12; i += 4)
            {
                transform[i] = ScaleToNative(transform[i], instance.units);
            }
            Matrix3d convertedTransform = new Matrix3d(transform);

            // add block reference
            BlockTableRecord modelSpaceRecord = Doc.Database.GetModelSpace();
            BlockReference   br = new BlockReference(insertionPoint, definitionId);

            br.BlockTransform = convertedTransform;
            // add attributes if there are any
            var attributes = instance["attributes"] as Dictionary <string, string>;

            if (attributes != null)
            {
                // TODO: figure out how to add attributes
            }
            ObjectId id = ObjectId.Null;

            if (AppendToModelSpace)
            {
                id = modelSpaceRecord.Append(br);
            }

            // return
            result = "success";
            if ((id.IsValid && !id.IsNull) || !AppendToModelSpace)
            {
                reference = br;
            }

            return(result);
        }
Beispiel #2
0
        // Blocks
        public BlockInstance BlockReferenceToSpeckle(BlockReference reference)
        {
            /*
             * // skip if dynamic block
             * if (reference.IsDynamicBlock)
             * return null;
             */

            // get record
            BlockDefinition definition = null;
            var             attributes = new Dictionary <string, string>();

            BlockTableRecord btr = (BlockTableRecord)Trans.GetObject(reference.BlockTableRecord, OpenMode.ForRead);

            definition = BlockRecordToSpeckle(btr);
            foreach (ObjectId id in reference.AttributeCollection)
            {
                AttributeReference attRef = (AttributeReference)Trans.GetObject(id, OpenMode.ForRead);
                attributes.Add(attRef.Tag, attRef.TextString);
            }

            if (definition == null)
            {
                return(null);
            }

            var instance = new BlockInstance()
            {
                transform       = new Transform(reference.BlockTransform.ToArray(), ModelUnits),
                blockDefinition = definition,
                units           = ModelUnits
            };

            // add attributes
            instance["attributes"] = attributes;

            return(instance);
        }