Untitled

mail@pastecode.io avatar
unknown
csharp
a month ago
4.3 kB
2
Indexable
Never
        [CommandMethod("LOTEMASTER")]
        public void LOTEMASTER()
        {
            #region REALIZA A SELEÇÃO DAS POLYLINES
            PromptSelectionOptions Opts = new PromptSelectionOptions();
            Opts.MessageForAdding = "\nSelecione as POLYLINES dos LOTES";
            Opts.MessageForRemoval = "\nApenas Polylines";
            TypedValue TipoPL = new TypedValue((int)DxfCode.Start, "LWPOLYLINE");
            TypedValue[] ListaTipos = new TypedValue[] { TipoPL };
            SelectionFilter SF = new SelectionFilter(ListaTipos);
            PromptSelectionResult Sel = Manager.DocEditor.GetSelection(Opts, SF);
            if (Sel.Status != PromptStatus.OK)
            {
                return;
            }
            #endregion
      
            ObjectId IDSiteTemp = ObjectId.Null;
            using (Transaction TransCAD = Manager.DocData.TransactionManager.StartTransaction())
            {          
                BlockTableRecord Model = (BlockTableRecord)TransCAD.GetObject(Manager.DocData.CurrentSpaceId, OpenMode.ForWrite);
                // RECEBE TODAS AS POLYLINES EM FORMATO DE CLASSE PARA VERIFICAÇÃO
                IDSiteTemp = Autodesk.Civil.DatabaseServices.Site.Create(Manager.DocCivil, Guid.NewGuid().ToString());
                Autodesk.Civil.DatabaseServices.Site Site = (Site)TransCAD.GetObject(IDSiteTemp, OpenMode.ForWrite);
                dynamic SiteACAD = Site.AcadObject;
                dynamic SiteParcelLines = SiteACAD.ParcelSegments();
                for (int i = 0; i < Sel.Value.Count; i++)
                {
                    Polyline PL = (Polyline)TransCAD.GetObject(Sel.Value[i].ObjectId, OpenMode.ForRead);
                    var Segmentos = SiteParcelLines.AddFromEntity(PL.AcadObject, true);
                    Segmentos.Name = "Lote " + i.ToString();
                }           
                TransCAD.Commit();
            }
            string NomeSite = string.Empty;
            using (Transaction TransCAD = Manager.DocData.TransactionManager.StartTransaction())
            {
                BlockTableRecord Model = (BlockTableRecord)TransCAD.GetObject(Manager.DocData.CurrentSpaceId, OpenMode.ForWrite);
                // RECEBE TODAS AS POLYLINES EM FORMATO DE CLASSE PARA VERIFICAÇÃO         
                Autodesk.Civil.DatabaseServices.Site Site = (Site)TransCAD.GetObject(IDSiteTemp, OpenMode.ForRead);
                NomeSite = Site.Name;
                foreach (ObjectId IDParcel in Site.GetParcelIds()) {
                    Autodesk.Civil.DatabaseServices.Parcel Parcela = (Autodesk.Civil.DatabaseServices.Parcel)TransCAD.GetObject(IDParcel, OpenMode.ForWrite);
                    try
                    {
                        Polyline LimiteParcel = (Polyline)Parcela.BaseCurve;
                        if (LimiteParcel != null)
                        {
                            LimiteParcel.ColorIndex = 4;
                            Model.AppendEntity(LimiteParcel);
                            TransCAD.AddNewlyCreatedDBObject(LimiteParcel, true);
                        }
                    }
                    catch { }
                }
                TransCAD.Commit();
            }

            var str = GetCivilAppString("Land");
            dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            dynamic aeccApp = acadApp.GetInterfaceObject(str);
            dynamic aeccDoc = aeccApp.ActiveDocument;
            dynamic sites = aeccDoc.Sites;
            try
            {
                sites.Remove(NomeSite);
            }
            catch { }
        }

        string GetCivilAppString(string module)
        {
            var retval = "";
            var ucm = HostApplicationServices.Current.UserRegistryProductRootKey;
            var lm = "HKEY_LOCAL_MACHINE\\" + ucm;
            var hj = Registry.LocalMachine.OpenSubKey(ucm);
            var c3d = (string)hj.GetValue("Release");
            c3d = c3d.Substring(0, c3d.IndexOf(".", (c3d.IndexOf(".") + 1)));
            hj.Close();
            retval = "AeccXUi" + module + ".Aecc" + (module == "Land" ? "" : module) + "Application." + c3d;
            return retval;
        }
Leave a Comment