Untitled
unknown
plain_text
a year ago
3.3 kB
10
Indexable
[CommandMethod("IS_CruzAl")] public void IS_CruzAl() { // Selecione os Alinhamentos PromptSelectionOptions SelAlin = new PromptSelectionOptions(); SelAlin.MessageForAdding = "Selecione os Alinhamentos"; TypedValue[] filtro = { new TypedValue((int)DxfCode.Start, "AECC_ALIGNMENT") }; SelectionFilter selecaoFiltro = new SelectionFilter(filtro); PromptSelectionResult SelRes = Manager.DocEditor.GetSelection(SelAlin, selecaoFiltro); if (SelRes.Status != PromptStatus.OK) { Manager.DocEditor.WriteMessage("\nComando Cancelado"); return; } ObjectIdCollection AlinhamentoId = new ObjectIdCollection(SelRes.Value.GetObjectIds()); if (AlinhamentoId.Count < 2) { Manager.DocEditor.WriteMessage("\nSelecione pelo menos 2 alinhamentos."); return; } // Exibe o formulário para seleção do bloco F_IS_CruzAl janela = new F_IS_CruzAl(); janela.ShowDialog(); if (!janela.Fazer) { return; } string NomeBloco = janela.NomeBloco; // Insere o bloco nas interseções dos alinhamentos selecionados using (Transaction trCad = Manager.DocData.TransactionManager.StartTransaction()) { BlockTable Btb = (BlockTable)trCad.GetObject(Manager.DocData.BlockTableId, OpenMode.ForRead); // Verifica se o bloco selecionado existe na tabela de blocos if (!Btb.Has(NomeBloco)) { Manager.DocEditor.WriteMessage("\nBloco não encontrado."); return; } BlockTableRecord Btbr = (BlockTableRecord)trCad.GetObject(Manager.DocData.CurrentSpaceId, OpenMode.ForWrite); ObjectId BlocoId = Btb[NomeBloco]; // Usando um HashSet para armazenar pontos únicos HashSet<Point3d> pontosInseridos = new HashSet<Point3d>(); foreach (ObjectId AlinhamentoId1 in AlinhamentoId) { Alignment Alinhamento1 = (Alignment)trCad.GetObject(AlinhamentoId1, OpenMode.ForRead); foreach (ObjectId AlinhamentoId2 in AlinhamentoId) { if (AlinhamentoId1 == AlinhamentoId2) continue; Alignment Alinhamento2 = (Alignment)trCad.GetObject(AlinhamentoId2, OpenMode.ForRead); Point3dCollection intersectionPoints = new Point3dCollection(); Alinhamento1.IntersectWith(Alinhamento2, Intersect.OnBothOperands, intersectionPoints, IntPtr.Zero, IntPtr.Zero); foreach (Point3d point in intersectionPoints) { // Verifica se o ponto já foi processado if (!pontosInseridos.Any(p => p.IsEqualTo(point, new Tolerance(1e-6, 1e-6)))) { pontosInseridos.Add(point); // Adiciona o ponto ao HashSet using (BlockReference br = new BlockReference(point, BlocoId)) { Btbr.AppendEntity(br); trCad.AddNewlyCreatedDBObject(br, true); } } } } } trCad.Commit(); } }
Editor is loading...
Leave a Comment