Ejemplo n.º 1
0
 protected ShapeStyle(Autodesk.AutoCAD.DatabaseServices.DBObject obj, bool isDynamoOwned) : base(obj, isDynamoOwned)
 {
     base._objectStyleType = "Shape";
 }
Ejemplo n.º 2
0
 protected SurfaceSlopeArrowContourTable(Autodesk.AutoCAD.DatabaseServices.DBObject obj, bool isDynamoOwned) : base(obj, isDynamoOwned)
 {
     base._objectStyleType = "Surface Slope Arrow Contour Table";
 }
        /// <summary>
        /// insert signatures
        /// </summary>
        /// <param name="dwgPath">Signature drawings' path</param>
        /// <param name="dwgNameList">Signature drawing list</param>
        public void InsertSign(string dwgPath, List <string> dwgNameList)
        {
            AdeskAppSvr.Document        doc             = AdeskAppSvr.Application.DocumentManager.MdiActiveDocument;
            AdeskDBSvr.Database         CurrDB          = doc.Database;
            AdeskEdIn.Editor            ed              = doc.Editor;
            AdeskEdIn.PromptPointResult prPointRes_Base = ed.GetPoint(new AdeskEdIn.PromptPointOptions("选择插入的基点"));
            AdeskEdIn.PromptPointResult prPointRes_opp  = ed.GetPoint(new AdeskEdIn.PromptPointOptions("选择基点的对角点"));
            //In order to make the signs look nicely , calculate the base point and its opposite point
            AdeskGeo.Point3d P_base = CalPoint(prPointRes_Base.Value, prPointRes_opp.Value, 0.1);
            AdeskGeo.Point3d P_opp  = CalPoint(prPointRes_Base.Value, prPointRes_opp.Value, 0.9);
            //sign's width and height
            double SignWidth  = P_opp.X - P_base.X;
            double SignHeight = P_opp.Y - P_base.Y;
            //distance between each other
            double distanceW = prPointRes_opp.Value.X - prPointRes_Base.Value.X;
            double distanceH = prPointRes_opp.Value.Y - prPointRes_Base.Value.Y;

            //current date
            string date = System.DateTime.Today.ToLocalTime().ToString().Split(' ')[0];

            try
            {
                for (int i = 0; i < dwgNameList.Count; i++)
                {
                    using (AdeskDBSvr.Database tmpdb = new AdeskDBSvr.Database(false, false))
                    {
                        //read drawing
                        tmpdb.ReadDwgFile(dwgPath + dwgNameList[i], FileShare.Read, true, null);
                        //insert Signature drawing as a new block into current drawing
                        AdeskDBSvr.ObjectId idBTR = CurrDB.Insert(this.ICCardList[i], tmpdb, false);
                        //scale of signature. 36 is the width of sign, and 17 is the height. you should adjust them in your condition.
                        double WidthOfSign;
                        double HeightOfSign;
                        double scaleWidth  = SignWidth / 36;
                        double scaleHeight = SignHeight / 17;
                        using (AdeskDBSvr.Transaction trans = CurrDB.TransactionManager.StartTransaction())
                        {
                            AdeskDBSvr.BlockTable       bt  = (AdeskDBSvr.BlockTable)trans.GetObject(CurrDB.BlockTableId, AdeskDBSvr.OpenMode.ForRead);
                            AdeskDBSvr.BlockTableRecord btr = (AdeskDBSvr.BlockTableRecord)trans.GetObject(bt[AdeskDBSvr.BlockTableRecord.ModelSpace], AdeskDBSvr.OpenMode.ForWrite);

                            AdeskDBSvr.BlockTableRecord InBtr = (AdeskDBSvr.BlockTableRecord)trans.GetObject(idBTR, AdeskDBSvr.OpenMode.ForRead);
                            foreach (AdeskDBSvr.ObjectId tmpid in InBtr)
                            {
                                AdeskDBSvr.DBObject dbo = trans.GetObject(tmpid, AdeskDBSvr.OpenMode.ForRead);
                                if (dbo is AdeskDBSvr.Ole2Frame)
                                {
                                    AdeskDBSvr.Ole2Frame mOle = (AdeskDBSvr.Ole2Frame)dbo;
                                    WidthOfSign  = mOle.WcsWidth;
                                    HeightOfSign = mOle.WcsHeight;
                                    scaleWidth   = SignWidth / WidthOfSign;
                                    scaleHeight  = SignHeight / HeightOfSign;
                                    break;
                                }
                            }

                            //insert point of each signature and date from top to bottom
                            AdeskGeo.Point3d inPt = new AdeskGeo.Point3d(P_base.X, P_base.Y - i * distanceH, P_base.Z);

                            #region signature date
                            //signature date
                            AdeskDBSvr.MText                SignDate       = new AdeskDBSvr.MText();
                            AdeskDBSvr.TextStyleTable       TextStyleTB    = (AdeskDBSvr.TextStyleTable)trans.GetObject(CurrDB.TextStyleTableId, AdeskDBSvr.OpenMode.ForWrite);
                            AdeskDBSvr.TextStyleTableRecord TextStyleTBRec = new AdeskDBSvr.TextStyleTableRecord();

                            TextStyleTBRec.Font = new AdeskGra.FontDescriptor("宋体", true, false, 0, 0);
                            TextStyleTB.Add(TextStyleTBRec);
                            trans.AddNewlyCreatedDBObject(TextStyleTBRec, true);
                            SignDate.TextStyle  = TextStyleTBRec.Id;
                            SignDate.Contents   = date;
                            SignDate.TextHeight = SignHeight / 2;
                            SignDate.Width      = SignWidth / 3;
                            //date's location should fit the frame
                            SignDate.Location = new AdeskGeo.Point3d((inPt.X + distanceW), (inPt.Y + 1.5 * SignDate.TextHeight), inPt.Z);
                            btr.AppendEntity(SignDate);
                            trans.AddNewlyCreatedDBObject(SignDate, true);
                            #endregion

                            try
                            {
                                //create a ref to the block
                                using (AdeskDBSvr.BlockReference bref = new AdeskDBSvr.BlockReference(inPt, idBTR))
                                {
                                    bref.ScaleFactors = new AdeskGeo.Scale3d(scaleWidth, scaleHeight, 1.0);
                                    btr.AppendEntity(bref);
                                    trans.AddNewlyCreatedDBObject(bref, true);
                                }
                                trans.Commit();
                            }
                            catch (System.Exception err)
                            {
                                MessageBox.Show("one: " + err.Message);
                            }
                        }
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception err)
            {
                MessageBox.Show("insert: " + err.Message);
            }
        }
Ejemplo n.º 4
0
 protected AlignmentSpiralTable(Autodesk.AutoCAD.DatabaseServices.DBObject obj, bool isDynamoOwned) : base(obj, isDynamoOwned)
 {
     base._objectStyleType = "Alignment Spiral Table";
 }
Ejemplo n.º 5
0
        public override async Task <StreamState> SendStream(StreamState state)
        {
            var kit       = KitManager.GetDefaultKit();
            var converter = kit.LoadConverter(Utils.AutocadAppName);

            converter.SetContextDocument(Doc);

            var streamId = state.Stream.id;
            var client   = state.Client;

            if (state.Filter != null)
            {
                state.SelectedObjectIds = GetObjectsFromFilter(state.Filter, converter);
            }

            // remove deleted object ids
            var deletedElements = new List <string>();

            foreach (var handle in state.SelectedObjectIds)
            {
                if (Doc.Database.TryGetObjectId(Utils.GetHandle(handle), out AcadDb.ObjectId id))
                {
                    if (id.IsErased || id.IsNull)
                    {
                        deletedElements.Add(handle);
                    }
                }
            }
            state.SelectedObjectIds = state.SelectedObjectIds.Where(o => !deletedElements.Contains(o)).ToList();

            if (state.SelectedObjectIds.Count == 0)
            {
                RaiseNotification("Zero objects selected; send stopped. Please select some objects, or check that your filter can actually select something.");
                return(state);
            }

            var commitObj = new Base();

            var units = Units.GetUnitsFromString(Doc.Database.Insunits.ToString());

            commitObj["units"] = units;

            var conversionProgressDict = new ConcurrentDictionary <string, int>();

            conversionProgressDict["Conversion"] = 0;
            Execute.PostToUIThread(() => state.Progress.Maximum = state.SelectedObjectIds.Count());
            int  convertedCount = 0;
            bool renamedlayers  = false;

            foreach (var autocadObjectHandle in state.SelectedObjectIds)
            {
                if (state.CancellationTokenSource.Token.IsCancellationRequested)
                {
                    return(null);
                }

                // get the db object from id
                AcadDb.Handle   hn  = Utils.GetHandle(autocadObjectHandle);
                AcadDb.DBObject obj = hn.GetObject(out string type, out string layer);

                if (obj == null)
                {
                    state.Errors.Add(new Exception($"Failed to find local object ${autocadObjectHandle}."));
                    continue;
                }

                if (!converter.CanConvertToSpeckle(obj))
                {
                    state.Errors.Add(new Exception($"Objects of type ${type} are not supported"));
                    continue;
                }

                // convert obj
                // try catch to prevent memory access violation crash in case a conversion goes wrong
                Base   converted     = null;
                string containerName = string.Empty;
                try
                {
                    converted = converter.ConvertToSpeckle(obj);
                    if (converted == null)
                    {
                        state.Errors.Add(new Exception($"Failed to convert object ${autocadObjectHandle} of type ${type}."));
                        continue;
                    }
                }
                catch
                {
                    state.Errors.Add(new Exception($"Failed to convert object {autocadObjectHandle} of type {type}."));
                    continue;
                }

                /* TODO: adding the extension dictionary / xdata per object
                 * foreach (var key in obj.ExtensionDictionary)
                 * {
                 * converted[key] = obj.ExtensionDictionary.GetUserString(key);
                 * }
                 */

                if (obj is BlockReference)
                {
                    containerName = "Blocks";
                }
                else
                {
                    // remove invalid chars from layer name
                    string cleanLayerName = Utils.RemoveInvalidDynamicPropChars(layer);
                    containerName = cleanLayerName;
                    if (!cleanLayerName.Equals(layer))
                    {
                        renamedlayers = true;
                    }
                }

                if (commitObj[$"@{containerName}"] == null)
                {
                    commitObj[$"@{containerName}"] = new List <Base>();
                }
                ((List <Base>)commitObj[$"@{containerName}"]).Add(converted);

                conversionProgressDict["Conversion"]++;
                UpdateProgress(conversionProgressDict, state.Progress);

                converted.applicationId = autocadObjectHandle;

                convertedCount++;
            }

            if (renamedlayers)
            {
                RaiseNotification("Replaced illegal chars ./ with - in one or more layer names.");
            }

            if (state.CancellationTokenSource.Token.IsCancellationRequested)
            {
                return(null);
            }

            Execute.PostToUIThread(() => state.Progress.Maximum = convertedCount);

            var transports = new List <ITransport>()
            {
                new ServerTransport(client.Account, streamId)
            };

            var commitObjId = await Operations.Send(
                commitObj,
                state.CancellationTokenSource.Token,
                transports,
                onProgressAction : dict => UpdateProgress(dict, state.Progress),
                onErrorAction : (err, exception) => { Exceptions.Add(exception); }
                );

            if (Exceptions.Count != 0)
            {
                RaiseNotification($"Failed to send: \n {Exceptions.Last().Message}");
                return(null);
            }

            if (convertedCount > 0)
            {
                var actualCommit = new CommitCreateInput
                {
                    streamId          = streamId,
                    objectId          = commitObjId,
                    branchName        = state.Branch.name,
                    message           = state.CommitMessage != null ? state.CommitMessage : $"Pushed {convertedCount} elements from AutoCAD.",
                    sourceApplication = Utils.AutocadAppName
                };

                if (state.PreviousCommitId != null)
                {
                    actualCommit.parents = new List <string>()
                    {
                        state.PreviousCommitId
                    };
                }

                try
                {
                    var commitId = await client.CommitCreate(actualCommit);

                    await state.RefreshStream();

                    state.PreviousCommitId = commitId;

                    PersistAndUpdateStreamInFile(state);
                    RaiseNotification($"{convertedCount} objects sent to {state.Stream.name}.");
                }
                catch (Exception e)
                {
                    Globals.Notify($"Failed to create commit.\n{e.Message}");
                    state.Errors.Add(e);
                }
            }
            else
            {
                Globals.Notify($"Did not create commit: no objects could be converted.");
            }

            return(state);
        }
 protected SectionViewMaterialTable(Autodesk.AutoCAD.DatabaseServices.DBObject obj, bool isDynamoOwned) : base(obj, isDynamoOwned)
 {
     base._objectStyleType = "Section View Material Table";
 }
Ejemplo n.º 7
0
 protected ProfileViewStyle(Autodesk.AutoCAD.DatabaseServices.DBObject obj, bool isDynamoOwned) : base(obj, isDynamoOwned)
 {
     base._objectStyleType = "Profile View";
 }