Beispiel #1
0
        public static MapValue ReadComponentOffsetX(BlockReference br, System.Data.DataTable fjvTable)
        {
            Matrix3d transform        = br.BlockTransform;
            Matrix3d inverseTransform = transform.Inverse();

            br.TransformBy(inverseTransform);
            Extents3d bbox = br.Bounds.GetValueOrDefault();

            br.TransformBy(transform);
            double value = (bbox.MinPoint.X + bbox.MaxPoint.X) / 2;

            //Debug
            if (ReadComponentFlipState(br) != "_PP")
            {
                prdDbg(br.Handle.ToString() + ": " + ReadComponentFlipState(br));
            }
            //Debug
            switch (ReadComponentFlipState(br))
            {
            case "_NP":
                value = value * -1;
                break;

            default:
                break;
            }
            return(new MapValue(value));
        }
        private static void SetDrawOrderInBlock(App.Document dwg, Db.ObjectId blkId)
        {
            using (Db.Transaction tran =
                       dwg.TransactionManager.StartTransaction())
            {
                Db.BlockReference bref = (Db.BlockReference)tran.GetObject(
                    blkId, Db.OpenMode.ForRead);

                Db.BlockTableRecord bdef = (Db.BlockTableRecord)tran.GetObject(
                    bref.BlockTableRecord, Db.OpenMode.ForWrite);

                Db.DrawOrderTable doTbl = (Db.DrawOrderTable)tran.GetObject(
                    bdef.DrawOrderTableId, Db.OpenMode.ForWrite);

                Db.ObjectIdCollection col = new Db.ObjectIdCollection();
                foreach (Db.ObjectId id in bdef)
                {
                    if (id.ObjectClass == Rtm.RXObject.GetClass(typeof(Db.Wipeout)))
                    {
                        col.Add(id);
                    }
                }

                if (col.Count > 0)
                {
                    doTbl.MoveToBottom(col);
                }


                tran.Commit();
            }
        }
Beispiel #3
0
        public static MapValue ReadBlockName(BlockReference br, System.Data.DataTable fjvTable)
        {
            Transaction tx       = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.TopTransaction;
            string      realName = ((BlockTableRecord)tx.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead)).Name;

            return(new MapValue(realName));
        }
Beispiel #4
0
        public static MapValue ReadComponentDN1(BlockReference br, System.Data.DataTable fjvTable)
        {
            string propertyToExtractName = "DN1";

            string valueToReturn = ReadStringParameterFromDataTable(br.RealName(), fjvTable, propertyToExtractName, 0);

            if (valueToReturn.StartsWith("$"))
            {
                valueToReturn = valueToReturn.Substring(1);
                if (br.RealName() == "BØJN KDLR v2")
                {
                    prdDbg(br.GetDynamicPropertyByName(valueToReturn).Value.ToString());
                }

                //If the value is a pattern to extract from string
                if (valueToReturn.Contains("{"))
                {
                    valueToReturn = GetValueByRegex(br, propertyToExtractName, valueToReturn);
                }
                //Else the value is parameter literal to read
                else
                {
                    return(new MapValue(br.GetDynamicPropertyByName(valueToReturn).Value.ToString() ?? ""));
                }
            }
            return(new MapValue(valueToReturn ?? ""));
        }
Beispiel #5
0
        private static string ReadDynamicPropertyValue(this BlockReference br, string propertyName)
        {
            DynamicBlockReferencePropertyCollection props = br.DynamicBlockReferencePropertyCollection;

            foreach (DynamicBlockReferenceProperty property in props)
            {
                //prdDbg($"Name: {property.PropertyName}, Units: {property.UnitsType}, Value: {property.Value}");
                if (property.PropertyName == propertyName)
                {
                    switch (property.UnitsType)
                    {
                    case DynamicBlockReferencePropertyUnitsType.NoUnits:
                        return(property.Value.ToString());

                    case DynamicBlockReferencePropertyUnitsType.Angular:
                        double angular = Convert.ToDouble(property.Value);
                        return(angular.ToDegrees().ToString("0.##"));

                    case DynamicBlockReferencePropertyUnitsType.Distance:
                        double distance = Convert.ToDouble(property.Value);
                        return(distance.ToString("0.##"));

                    case DynamicBlockReferencePropertyUnitsType.Area:
                        double area = Convert.ToDouble(property.Value);
                        return(area.ToString("0.00"));

                    default:
                        return("");
                    }
                }
            }
            return("");
        }
        public static double ReadComponentDN2KodDouble(BlockReference br, System.Data.DataTable fjvTable)
        {
            string system = ReadComponentSystem(br, fjvTable);

            if (system.IsNoE())
            {
                throw new System.Exception($"{br.RealName()} failed to read system!");
            }
            int dn = ReadComponentDN2Int(br, fjvTable);

            if (dn == 0 || dn == 999)
            {
                throw new System.Exception($"{br.RealName()} failed to read DN1!");
            }
            if (system == "Twin")
            {
                return(PipeSchedule.GetTwinPipeKOd(dn));
            }
            else if (system == "Enkelt")
            {
                return(PipeSchedule.GetBondedPipeKOd(dn));
            }
            else
            {
                throw new System.Exception($"{br.RealName()} returned non-standard \"System\": {system}!");
            }
        }
Beispiel #7
0
        private static string ConstructStringByRegex(BlockReference br, string stringToProcess)
        {
            //Construct pattern which matches the parameter definition
            Regex variablePattern = new Regex(@"{\$(?<Parameter>[a-zæøåA-ZÆØÅ0-9_:-]*)}");

            //Test if a pattern matches in the input string
            if (variablePattern.IsMatch(stringToProcess))
            {
                //Get the first match
                Match match = variablePattern.Match(stringToProcess);
                //Get the first capture
                string capture = match.Captures[0].Value;
                //Get the parameter name from the regex match
                string parameterName = match.Groups["Parameter"].Value;
                //Read the parameter value from BR
                string parameterValue = br.ReadDynamicPropertyValue(parameterName);
                //Replace the captured group in original string with the parameter value
                stringToProcess = stringToProcess.Replace(capture, parameterValue);
                //Recursively call current function
                //It runs on the string until no more captures remain
                //Then it returns
                stringToProcess = ConstructStringByRegex(br, stringToProcess);
            }

            return(stringToProcess);
        }
Beispiel #8
0
        static public void SpaceOnAttributeName()
        {
            // Получение текущего документа и базы данных
            App.Document acDoc   = App.Application.DocumentManager.MdiActiveDocument;
            Db.Database  acCurDb = acDoc.Database;
            Ed.Editor    acEd    = acDoc.Editor;

            // старт транзакции
            using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                Db.TypedValue[] acTypValAr = new Db.TypedValue[1];
                acTypValAr.SetValue(new Db.TypedValue((int)Db.DxfCode.Start, "INSERT"), 0);
                Ed.SelectionFilter acSelFtr = new Ed.SelectionFilter(acTypValAr);

                Ed.PromptSelectionResult acSSPrompt = acDoc.Editor.GetSelection(acSelFtr);
                if (acSSPrompt.Status == Ed.PromptStatus.OK)
                {
                    Ed.SelectionSet acSSet = acSSPrompt.Value;
                    foreach (Ed.SelectedObject acSSObj in acSSet)
                    {
                        if (acSSObj != null)
                        {
                            if (acSSObj.ObjectId.ObjectClass.IsDerivedFrom(Rtm.RXClass.GetClass(typeof(Db.BlockReference))))
                            {
                                Db.BlockReference acEnt = acTrans.GetObject(acSSObj.ObjectId,
                                                                            Db.OpenMode.ForRead) as Db.BlockReference;

                                Db.BlockTableRecord blr = acTrans.GetObject(acEnt.BlockTableRecord,
                                                                            Db.OpenMode.ForRead) as Db.BlockTableRecord;
                                if (acEnt.IsDynamicBlock)
                                {
                                    blr = acTrans.GetObject(acEnt.DynamicBlockTableRecord,
                                                            Db.OpenMode.ForRead) as Db.BlockTableRecord;
                                }

                                if (blr.HasAttributeDefinitions)
                                {
                                    foreach (Db.ObjectId id in blr)
                                    {
                                        if (id.ObjectClass.IsDerivedFrom(Rtm.RXClass.GetClass(typeof(Db.AttributeDefinition))))
                                        {
                                            Db.AttributeDefinition acAttrRef = acTrans.GetObject(id,
                                                                                                 Db.OpenMode.ForWrite) as Db.AttributeDefinition;

                                            if (acAttrRef != null)
                                            {
                                                acAttrRef.Tag = acAttrRef.Tag.Replace('_', ' ');
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                acTrans.Commit();
            }
        }
        public static void StatisticsModel123_Steel4(BeamData beam, AcadDB.BlockReference blk_ref)
        {
            AcadDB.Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
            using (AcadDB.Transaction trans = db.TransactionManager.StartTransaction())
            {
                AcadDB.AttributeCollection atts = blk_ref.AttributeCollection;
                foreach (AcadDB.ObjectId att in atts)
                {
                    AcadDB.AttributeReference att_ref = trans.GetObject(att, AcadDB.OpenMode.ForWrite) as AcadDB.AttributeReference;
                    if (null == att_ref)
                    {
                        continue;
                    }

                    if (ATT_SH == att_ref.Tag)
                    {
                        att_ref.TextString = "4";
                    }
                    if (ATT_DK == att_ref.Tag)
                    {
                        att_ref.TextString = beam.dau_goi_data.first_layer_diameter.ToString();
                    }
                    if (ATT_DAI == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.Length - 2 * Beam.cover).ToString();
                    }
                    if (ATT_L2 == att_ref.Tag)
                    {
                        att_ref.TextString = "2000";
                    }
                    if (ATT_L1 == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.Height - 2 * Beam.cover).ToString();
                    }
                    if (ATT_SL1 == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.dau_goi_data.number_steel_first_layer).ToString();
                    }
                    if (ATT_SLA == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.dau_goi_data.number_steel_first_layer).ToString();
                    }
                    if (ATT_DT == att_ref.Tag)
                    {
                        double total_len = beam.dau_goi_data.number_steel_first_layer * (beam.Length - 2 * Beam.cover);
                        total_len         /= 1000.0;
                        att_ref.TextString = (total_len).ToString();
                    }
                    if (ATT_TL == att_ref.Tag)
                    {
                        att_ref.TextString = "...";
                    }
                }

                trans.Commit();
            }
        }
    public void DisplayBlockAttributesSample()
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDisplay Block Attributes:\n");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================\n");

        Editor      ed = Application.DocumentManager.MdiActiveDocument.Editor;
        Database    db = HostApplicationServices.WorkingDatabase;
        Transaction tr = db.TransactionManager.StartTransaction();

        // Start the transaction
        try
        {
            // Build a filter list so that only
            // block references are selected

            TypedValue[] filList = new TypedValue[1] {
                new TypedValue((int)DxfCode.Start, "INSERT")
            };

            SelectionFilter        filter = new SelectionFilter(filList);
            PromptSelectionOptions opts   = new PromptSelectionOptions();
            opts.MessageForAdding = "Select block references: ";

            PromptSelectionResult res = ed.GetSelection(opts, filter);
            if (res.Status != PromptStatus.OK)
            {
                return;
            }

            SelectionSet selSet  = res.Value;
            ObjectId[]   idArray = selSet.GetObjectIds();

            foreach (ObjectId blkId in idArray)
            {
                BlockReference   blkRef = (BlockReference)tr.GetObject(blkId, OpenMode.ForRead);
                BlockTableRecord btr    = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead);
                btr.Dispose();

                AttributeCollection attCol = blkRef.AttributeCollection;
                foreach (ObjectId attId in attCol)
                {
                    AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);
                }
            }
            tr.Commit();
        }
        catch (Autodesk.AutoCAD.Runtime.Exception ex)
        {
            ed.WriteMessage(("Exception: " + ex.Message));
        }
        finally
        {
            tr.Dispose();
        }
    }
Beispiel #11
0
        public static double ReadComponentOffsetY(BlockReference br, System.Data.DataTable fjvTable)
        {
            Matrix3d transform        = br.BlockTransform;
            Matrix3d inverseTransform = transform.Inverse();

            br.TransformBy(inverseTransform);
            Extents3d bbox = br.Bounds.GetValueOrDefault();

            br.TransformBy(transform);
            return(-(bbox.MinPoint.Y + bbox.MaxPoint.Y) / 2);
        }
Beispiel #12
0
        public static MapValue ReadComponentHeight(BlockReference br, System.Data.DataTable fjvTable)
        {
            Matrix3d transform        = br.BlockTransform;
            Matrix3d inverseTransform = transform.Inverse();

            br.TransformBy(inverseTransform);
            Extents3d bbox = br.Bounds.GetValueOrDefault();

            br.TransformBy(transform);
            return(new MapValue(Math.Abs(bbox.MaxPoint.Y - bbox.MinPoint.Y)));
        }
Beispiel #13
0
 private static string RealName(this BlockReference br)
 {
     if (br.IsDynamicBlock)
     {
         Transaction tx = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.TopTransaction;
         return(((BlockTableRecord)tx.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead)).Name);
     }
     else
     {
         return(br.Name);
     }
 }
Beispiel #14
0
        private static DynamicBlockReferenceProperty GetDynamicPropertyByName(this BlockReference br, string name)
        {
            DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection;

            foreach (DynamicBlockReferenceProperty property in pc)
            {
                if (property.PropertyName == name)
                {
                    return(property);
                }
            }
            return(null);
        }
Beispiel #15
0
        /// <summary>
        /// 获取块参照数据
        /// </summary>
        /// <param name="block2">块参照</param>
        /// <returns>提取的数据字符串</returns>
        public static List <string> AnalysisBlockReferenceFun(Autodesk.AutoCAD.DatabaseServices.BlockReference _br)
        {
            List <string> result = new List <string>();
            Document      doc    = Application.DocumentManager.MdiActiveDocument;
            Editor        ed     = doc.Editor;
            Database      db     = doc.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                result.Add("#BlockReference#");
                result.Add(ReflectionClass.GetAllPropertyInfoEx(_br, "BlockReference"));

                BlockTableRecord block = trans.GetObject(_br.BlockTableRecord, OpenMode.ForWrite) as BlockTableRecord;

                foreach (ObjectId id in block)
                {
                    DBObject ODB = id.GetObject(OpenMode.ForRead);
                    if (ODB.GetRXClass().Equals(RXClass.GetClass(typeof(BlockReference))))
                    {
                        BlockReference   br     = trans.GetObject(id, OpenMode.ForRead) as BlockReference;
                        BlockTableRecord block1 = trans.GetObject(br.BlockTableRecord, OpenMode.ForWrite) as BlockTableRecord;

                        result.Add("#Sub_BlockReference#");
                        result.Add(ReflectionClass.GetAllPropertyInfoEx(br, "Sub_BlockReference"));

                        foreach (var item in block1)
                        {
                            result.Add("#" + item.GetObject(OpenMode.ForRead).GetRXClass().Name + "#");
                            result.Add(ReflectionClass.GetAllPropertyInfoEx(trans.GetObject(item, OpenMode.ForRead), item.GetObject(OpenMode.ForRead).GetRXClass().Name));
                            result.Add("#" + item.GetObject(OpenMode.ForRead).GetRXClass().Name + "#");
                        }

                        result.Add("#Sub_BlockReference#");
                        break;
                    }
                    else
                    {
                        result.Add("#" + id.GetObject(OpenMode.ForRead).GetRXClass().Name + "#");
                        result.Add(ReflectionClass.GetAllPropertyInfoEx(trans.GetObject(id, OpenMode.ForRead), id.GetObject(OpenMode.ForRead).GetRXClass().Name));
                        result.Add("#" + id.GetObject(OpenMode.ForRead).GetRXClass().Name + "#");
                    }
                }
            }

            //扩展数据


            result.Add("#BlockReference#");
            return(result);
        }
Beispiel #16
0
        private static string GetValueByRegex(BlockReference br, string propertyToExtractName, string valueToProcess)
        {
            //Extract property name
            Regex  regex    = new Regex(@"(?<Name>^[\w\s]+)");
            string propName = "";

            if (!regex.IsMatch(valueToProcess))
            {
                throw new System.Exception("Property name not found!");
            }
            propName = regex.Match(valueToProcess).Groups["Name"].Value;
            //Read raw data from block
            //Debug
            if (br.RealName() == "BØJN KDLR v2")
            {
                prdDbg(br.GetDynamicPropertyByName(propName).UnitsType.ToString());
            }

            string rawContents = br.GetDynamicPropertyByName(propName).Value as string;

            //Safeguard against value not being set -> CUSTOM
            if (rawContents == "Custom" || rawContents == "ÆNDR MIG")
            {
                throw new System.Exception($"Parameter {propName} is not set for block handle {br.Handle}!");
            }
            //Extract regex def from the table
            Regex regxExtract = new Regex(@"{(?<Regx>[^}]+)}");

            if (!regxExtract.IsMatch(valueToProcess))
            {
                throw new System.Exception("Regex definition is incorrect!");
            }
            string extractedRegx = regxExtract.Match(valueToProcess).Groups["Regx"].Value;
            //extract needed value from the rawContents by using the extracted regex
            Regex finalValueRegex = new Regex(extractedRegx);

            if (!finalValueRegex.IsMatch(rawContents))
            {
                prdDbg($"Extracted Regex failed to match Raw Value for block {br.RealName()}, handle {br.Handle}!");
                prdDbg($"Returning instead: {finalValueRegex.Match(rawContents).Groups[propertyToExtractName].Value}");
                return(finalValueRegex.Match(rawContents).Groups[propertyToExtractName].Value);
            }
            return(finalValueRegex.Match(rawContents).Groups[propertyToExtractName].Value);
        }
        public static int ReadComponentDN2Int(BlockReference br, System.Data.DataTable fjvTable)
        {
            string value = ReadComponentDN2Str(br, fjvTable);

            if (value.IsNoE())
            {
                return(0);
            }
            int result;

            if (int.TryParse(value, out result))
            {
                return(result);
            }
            else
            {
                return(0);
            }
        }
        public static string ReadComponentSystem(BlockReference br, System.Data.DataTable fjvTable)
        {
            string propertyToExtractName = "System";

            string valueToReturn = ReadStringParameterFromDataTable(br.RealName(), fjvTable, propertyToExtractName, 0);

            if (valueToReturn.StartsWith("$"))
            {
                valueToReturn = valueToReturn.Substring(1);
                //If the value is a pattern to extract from string
                if (valueToReturn.Contains("{"))
                {
                    valueToReturn = GetValueByRegex(br, propertyToExtractName, valueToReturn);
                }
                //Else the value is parameter literal to read
                else
                {
                    return(br.GetDynamicPropertyByName(valueToReturn).Value as string ?? "");
                }
            }
            return(valueToReturn ?? "");
        }
Beispiel #19
0
        internal static string ReadComponentFlipState(BlockReference br)
        {
            Scale3d scale = br.ScaleFactors;

            if (scale.X < 0 && scale.Y < 0)
            {
                return("_NN");
            }
            if (scale.X > 0 && scale.Y > 0)
            {
                return("_PP");
            }
            if (scale.X > 0)
            {
                return("_PN");
            }
            if (scale.Y > 0)
            {
                return("_NP");
            }
            return("_PP");
        }
Beispiel #20
0
        internal static MapValue ReadComponentFlipState(BlockReference br, System.Data.DataTable fjvTable)
        {
            Scale3d scale = br.ScaleFactors;

            if (scale.X < 0 && scale.Y < 0)
            {
                return(new MapValue("_NN"));
            }
            if (scale.X > 0 && scale.Y > 0)
            {
                return(new MapValue("_PP"));
            }
            if (scale.X > 0)
            {
                return(new MapValue("_PN"));
            }
            if (scale.Y > 0)
            {
                return(new MapValue("_NP"));
            }
            return(new MapValue("_PP"));
        }
Beispiel #21
0
        public static string ReadComponentVinkel(BlockReference br, System.Data.DataTable fjvTable)
        {
            string propertyToExtractName = "Vinkel";

            string valueToReturn = ReadStringParameterFromDataTable(br.RealName(), fjvTable, propertyToExtractName, 0);

            if (valueToReturn.StartsWith("$"))
            {
                valueToReturn = valueToReturn.Substring(1);
                //If the value is a pattern to extract from string
                if (valueToReturn.Contains("{"))
                {
                    valueToReturn = GetValueByRegex(br, propertyToExtractName, valueToReturn);
                }
                //Else the value is parameter literal to read
                else
                {
                    double value = Convert.ToDouble(br.GetDynamicPropertyByName(valueToReturn).Value);
                    return((value * (180 / Math.PI)).ToString("0.##"));
                }
            }
            return(valueToReturn ?? "");
        }
Beispiel #22
0
 public static MapValue ReadComponentSeries(BlockReference br, System.Data.DataTable fjvTable) => new MapValue("S3");
Beispiel #23
0
 public static MapValue ReadComponentDN2(BlockReference br, System.Data.DataTable fjvTable) =>
 new MapValue(ReadStringParameterFromDataTable(br.Name, fjvTable, "DN2", 0));
Beispiel #24
0
 public static MapValue ReadBlockRotation(BlockReference br, System.Data.DataTable fjvTable) =>
 new MapValue(br.Rotation * (180 / Math.PI));
Beispiel #25
0
 public static MapValue ReadBlockName(BlockReference br, System.Data.DataTable fjvTable) => new MapValue(br.Name);
Beispiel #26
0
        /// <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);
            }
        }
Beispiel #27
0
 public static MapValue ReadComponentType(BlockReference br, System.Data.DataTable fjvTable) =>
 new MapValue(br.GetDynamicPropertyByName("Betegnelse").Value as string ?? "");
Beispiel #28
0
        public static void WriteIsogenAttrubutesToDwg()
        {
            DocumentCollection docCol   = Application.DocumentManager;
            Database           localDb  = docCol.MdiActiveDocument.Database;
            Editor             editor   = docCol.MdiActiveDocument.Editor;
            Document           doc      = docCol.MdiActiveDocument;
            CivilDocument      civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            //Instantiate serializer
            XmlSerializer serializer = new XmlSerializer(typeof(BackingSheetData));

            // Declare an object variable of the type to be deserialized.
            BackingSheetData bsd;

            using (Stream reader = new FileStream(@"X:\AC - Iso\IsoDir\1189\DRI_VEKS_ASBUILT\DRI_VEKS_ASBUILT.BDF", FileMode.Open))
            {
                // Call the Deserialize method to restore the object's state.
                bsd = (BackingSheetData)serializer.Deserialize(reader);
            }

            #region Dialog box for selecting the PCF file
            string         fileName;
            OpenFileDialog dialog = new OpenFileDialog()
            {
                Title       = "Choose PCF file:",
                DefaultExt  = "pcf",
                Filter      = "PCF files (*.pcf)|*.pcf|All files (*.*)|*.*",
                FilterIndex = 0
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                fileName = dialog.FileName;
            }
            else
            {
                throw new System.Exception("Cannot find BBR file!");
            }
            #endregion

            string[] pcf = File.ReadAllLines(fileName);

            using (Transaction tx = localDb.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockReference tb = localDb.GetBlockReferenceByName("Title Block").FirstOrDefault();

                    if (tb == null)
                    {
                        prdDbg("Title Block not found!"); tx.Abort(); return;
                    }

                    bsd.ParseData(pcf);

                    foreach (var item in bsd.AttributeMapping)
                    {
                        if (item.FinalData.IsNoE())
                        {
                            continue;
                        }
                        prdDbg($"{item.BlockAttribute} > {item.FinalData}");
                        tb.SetAttributeStringValue(item.BlockAttribute, item.FinalData);
                    }
                }
                catch (System.Exception ex)
                {
                    tx.Abort();
                    editor.WriteMessage("\n" + ex.Message);
                    return;
                }
                tx.Commit();
            }
        }
Beispiel #29
0
        public void AddEntityToPOIs(Entity ent)
        {
            switch (ent)
            {
            case Polyline pline:
                switch (GetPipeSystem(pline))
                {
                case PipeSystemEnum.Ukendt:
                    prdDbg($"Wrong type of pline supplied: {pline.Handle}");
                    return;

                case PipeSystemEnum.Stål:
                    POIs.Add(new POI(pline, pline.StartPoint.To2D(), EndType.Start, PSM, DriGraph));
                    POIs.Add(new POI(pline, pline.EndPoint.To2D(), EndType.End, PSM, DriGraph));
                    break;

                case PipeSystemEnum.Kobberflex:
                case PipeSystemEnum.AluPex:
                    #region STIK        //Find forbindelse til forsyningsrøret
                    Point3d pt    = pline.StartPoint;
                    var     query = allPipes.Where(x =>
                                                   pt.IsOnCurve(x, 0.025) &&
                                                   pline.Handle != x.Handle &&
                                                   GetPipeSystem(x) == PipeSystemEnum.Stål);

                    if (query.FirstOrDefault() != default)
                    {
                        Polyline parent = query.FirstOrDefault();
                        POIs.Add(new POI(parent, parent.GetClosestPointTo(pt, false).To2D(), EndType.StikAfgrening, PSM, DriGraph));
                    }

                    pt = pline.EndPoint;
                    if (query.FirstOrDefault() != default)
                    {
                        //This shouldn't happen now, because AssignPlinesAndBlocksToAlignments
                        //guarantees that the end point is never on a supply pipe
                        Polyline parent = query.FirstOrDefault();
                        POIs.Add(new POI(parent, parent.GetClosestPointTo(pt, false).To2D(), EndType.StikAfgrening, PSM, DriGraph));
                    }
                    #endregion

                    //Tilføj almindelige ender til POIs
                    POIs.Add(new POI(pline, pline.StartPoint.To2D(), EndType.StikStart, PSM, DriGraph));
                    POIs.Add(new POI(pline, pline.EndPoint.To2D(), EndType.StikEnd, PSM, DriGraph));
                    break;

                default:
                    throw new System.Exception("Supplied a new PipeSystemEnum! Add to code kthxbai.");
                }
                break;

            case BlockReference br:
                Transaction      tx  = br.Database.TransactionManager.TopTransaction;
                BlockTableRecord btr = br.BlockTableRecord.Go <BlockTableRecord>(tx);
                foreach (Oid oid in btr)
                {
                    if (!oid.IsDerivedFrom <BlockReference>())
                    {
                        continue;
                    }
                    BlockReference nestedBr = oid.Go <BlockReference>(tx);
                    if (!nestedBr.Name.Contains("MuffeIntern"))
                    {
                        continue;
                    }
                    Point3d wPt = nestedBr.Position;
                    wPt = wPt.TransformBy(br.BlockTransform);
                    EndType endType;
                    if (nestedBr.Name.Contains("BRANCH"))
                    {
                        endType = EndType.Branch;
                    }
                    else
                    {
                        endType = EndType.Main;
                        //Handle special case of AFGRSTUDS
                        //which does not coincide with an end on polyline
                        //but is situated somewhere along the polyline
                        if (br.RealName() == "AFGRSTUDS")
                        {
                            PropertySetManager psmPipeline =
                                new PropertySetManager(dB, PSetDefs.DefinedSets.DriPipelineData);
                            PSetDefs.DriPipelineData driPipelineData = new PSetDefs.DriPipelineData();

                            string branchAlName = psmPipeline.ReadPropertyString(br, driPipelineData.BranchesOffToAlignment);
                            if (branchAlName.IsNoE())
                            {
                                prdDbg(
                                    $"WARNING! Afgrstuds {br.Handle} has no BranchesOffToAlignment value.\n" +
                                    $"This happens if there are objects with no alignment assigned.\n" +
                                    $"To fix enter main alignment name in BranchesOffToAlignment field.");
                            }

                            var polylines = allPipes
                                            //.GetFjvPipes(tx, true)
                                            //.HashSetOfType<Polyline>(tx, true)
                                            .Where(x => psmPipeline.FilterPropetyString
                                                       (x, driPipelineData.BelongsToAlignment, branchAlName));
                            //.ToHashSet();

                            foreach (Polyline polyline in polylines)
                            {
                                Point3d nearest = polyline.GetClosestPointTo(wPt, false);
                                if (nearest.DistanceHorizontalTo(wPt) < 0.01)
                                {
                                    POIs.Add(new POI(polyline, nearest.To2D(), EndType.Branch, PSM, DriGraph));
                                    break;
                                }
                            }
                        }
                    }
                    POIs.Add(new POI(br, wPt.To2D(), endType, PSM, DriGraph));
                }
                break;

            default:
                throw new System.Exception("Wrong type of object supplied!");
            }
        }
Beispiel #30
0
 internal CadDynamicBlock(BlockReference block, bool isDynamoOwned) : base(block, isDynamoOwned)
 {
 }
        /// <summary>
        /// insert signatures
        /// </summary>
        /// <param name="dwgPath"></param>
        /// <param name="dwgNameList"></param>
        public void InsertSign(string dwgPath, List <string> dwgNameList)
        {
            AdeskAppSvr.Document doc = AdeskAppSvr.Application.DocumentManager.MdiActiveDocument;
            this.Hide();
            AdeskDBSvr.Database         CurrDB          = doc.Database;//current 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;
            //scale of signature. 36 is the width of sign, and 17 is the height. you should adjust them in your condition.
            double scaleWidth  = SignWidth / 36;
            double scaleHeight = SignHeight / 17;
            //today
            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 it as a new block
                        AdeskDBSvr.ObjectId idBTR = CurrDB.Insert(this.ICCardList[i], tmpdb, false);

                        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);
                            //insert point
                            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);
                            //trans.Commit();

                            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);
            }
            this.Show();
        }