static public GeometryBase ToRhino(this _OdDb.ObjectId id) { if (DatabaseUtils.IsCurve(id)) { using (var dbCurve = id.GetObject(_OdDb.OpenMode.ForRead) as _OdDb.Curve) { var geometry = dbCurve?.ToRhino(); if (geometry != null) { return(geometry); } } } string tmpPath = Path.Combine(Path.GetTempPath(), "BricsCAD", "torhino.3dm"); using (var aId = new _OdDb.ObjectIdCollection() { id }) { if (_OdRx.ErrorStatus.OK != Bricscad.Rhino.RhinoUtilityFunctions.ExportRhinoFile(aId, tmpPath)) { return(null); } } return(ExtractGeometryFromFile(tmpPath)); }
/// <summary> /// Створює елементи вектору з данними виносу. /// </summary> private void CreateDrawingStakeOut() { if (this.PointStation == null) { return; } AcGe.Point3d pntStart = new AcGe.Point3d(this.PointStation.E, this.PointStation.N, this.PointStation.H); AcGe.Point3d pntEnd = new AcGe.Point3d(this.Coordinates.X, this.Coordinates.Y, 0); AcDb.Line line = new AcDb.Line(pntStart, pntEnd); line.Visible = this.Visible; AcGe.Point3d pntMiddle = new AcGe.LineSegment3d(pntStart, pntEnd).MidPoint; double angleTXT = line.Angle; if (angleTXT > Math.PI / 2 && angleTXT < Math.PI * 3 / 2) { angleTXT += Math.PI; } AcDb.MText text = new AcDb.MText(); text.Contents = this.DistanceToString(AcRx.DistanceUnitFormat.Decimal) + "\r\n" + "л.к. " + ServiceTable.FormatAngleValue(this.LeftlAngleToString(AcRx.AngularUnitFormat.DegreesMinutesSeconds)); text.Rotation = angleTXT; text.Location = pntMiddle; text.Attachment = AcDb.AttachmentPoint.MiddleCenter; text.Width = 25; text.TextHeight = 1.8 * this.ScaleDrawing; this.lineID = ServiceCAD.InsertObject(line); this.txtID = ServiceCAD.InsertObject(text); }
private void createBlock(_Ge.Point3d center) { if (!_c.blockTable.Has(blockName)) { write("Create missing block"); _Db.BlockTableRecord btr = new _Db.BlockTableRecord(); btr.Name = blockName; _Db.ObjectId btrId = _c.blockTable.Add(btr); _c.trans.AddNewlyCreatedDBObject(btr, true); createX(btr, 1.5, new _Ge.Point3d(0, 0, 0)); createCircle(btr, 1, new _Ge.Point3d(0, 0, 0)); _Db.BlockReference newBlockReference = new _Db.BlockReference(center, btrId); newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(40, center)); _c.modelSpace.AppendEntity(newBlockReference); _c.trans.AddNewlyCreatedDBObject(newBlockReference, true); } else { using (_Db.BlockReference newBlockReference = new _Db.BlockReference(center, _c.blockTable[blockName])) { newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(40, center)); _c.modelSpace.AppendEntity(newBlockReference); _c.trans.AddNewlyCreatedDBObject(newBlockReference, true); } } }
private AcDb.ObjectId AddBorders() { AcDb.Polyline2d borderParcel = ServiceSimpleElements.CreatePolyline2d(this.Parcel.Points, true); borderParcel.LayerId = ServiceCAD.CreateLayer(settingsDrawing.Plan.FillParcel.Layer); AcDb.ObjectId idBorderParcel = ServiceCAD.InsertObject(borderParcel); AcDb.ResultBuffer xData = new AcDb.ResultBuffer(); int dxfCode; AcDb.TypedValue typedValue; dxfCode = (int)AcDb.DxfCode.ExtendedDataRegAppName; typedValue = new AcDb.TypedValue(dxfCode, "Земельна ділянка"); xData.Add(typedValue); foreach (LandInfo infoValue in this.Parcel.Info) { dxfCode = (int)AcDb.DxfCode.ExtendedDataAsciiString; typedValue = new AcDb.TypedValue(dxfCode, "<" + infoValue.Key + "> " + infoValue.Value); xData.Add(typedValue); } ServiceCAD.SetXData(idBorderParcel, xData); return(idBorderParcel); }
public static void DetachRasterImage(LandRasterImage landRastr) { AcDb.Database curDb = AcApp.DocumentManager.MdiActiveDocument.Database; using (AcDb.Transaction tr = curDb.TransactionManager.StartTransaction()) { AcDb.RasterImageDef rasterDef; //bool bRasterDefCreated = false; AcDb.ObjectId imgDefId; AcDb.ObjectId imgDctID = AcDb.RasterImageDef.GetImageDictionary(curDb); if (imgDctID.IsNull) { imgDctID = AcDb.RasterImageDef.CreateImageDictionary(curDb); } AcDb.DBDictionary imgDict = tr.GetObject(imgDctID, AcDb.OpenMode.ForWrite) as AcDb.DBDictionary; if (imgDict.Contains(landRastr.ImageName)) { imgDefId = imgDict.GetAt(landRastr.ImageName); rasterDef = tr.GetObject(imgDefId, AcDb.OpenMode.ForWrite) as AcDb.RasterImageDef; if (rasterDef.IsLoaded) { rasterDef.Unload(true); imgDict.Remove(landRastr.ImageName); } } tr.Commit(); } }
public static AcDb.ObjectId CreateFontStyle(String textStyleName, AcGi.FontDescriptor font) { AcDb.ObjectId txtStyleId = AcDb.ObjectId.Null; using (AcDb.Transaction tr = doc.Database.TransactionManager.StartTransaction()) { AcDb.TextStyleTable newTextStyleTable = tr.GetObject(doc.Database.TextStyleTableId, AcDb.OpenMode.ForRead) as AcDb.TextStyleTable; if (!newTextStyleTable.Has(textStyleName)) { newTextStyleTable.UpgradeOpen(); AcDb.TextStyleTableRecord newTextStyleTableRecord = new AcDb.TextStyleTableRecord(); //newTextStyleTableRecord.FileName = "romans.shx"; newTextStyleTableRecord.Name = textStyleName; newTextStyleTableRecord.Font = font; newTextStyleTable.Add(newTextStyleTableRecord); tr.AddNewlyCreatedDBObject(newTextStyleTableRecord, true); txtStyleId = newTextStyleTable[textStyleName]; } tr.Commit(); } return(txtStyleId); }
public LayerInfo(_AcDb.LayerTableRecord ltr, _AcDb.Transaction trans) { OldLayer = ltr.Name; NewLayer = ""; _ColorO = ltr.Color; Color = ColorToString(); _LineTypeO = ltr.LinetypeObjectId; _LineType = Engine.GetNameFromLinetypeOid(ltr.LinetypeObjectId, trans); _LineWeightO = ltr.LineWeight; LineWeight = LineWeightToString(); _TransparencyO = ltr.Transparency; if (_TransparencyO != default(_AcCm.Transparency)) { Transparency = Engine.AlphaToTransparenz(_TransparencyO.Alpha).ToString(CultureInfo.InvariantCulture); } else { Transparency = string.Empty; } if (ltr.IsPlottable) { Plot = "Ja"; } else { Plot = "Nein"; } Description = ltr.Description; }
public static void CreateLayout(string name) { _AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database acCurDb = acDoc.Database; using (_AcDb.Transaction trans = acCurDb.TransactionManager.StartTransaction()) { // Reference the Layout Manager _AcDb.LayoutManager acLayoutMgr = _AcDb.LayoutManager.Current; // Create the new layout with default settings _AcDb.ObjectId objID = acLayoutMgr.CreateLayout(name); // Open the layout _AcDb.Layout layout = trans.GetObject(objID, _AcDb.OpenMode.ForRead) as _AcDb.Layout; // Set the layout current if it is not already if (layout.TabSelected == false) { acLayoutMgr.CurrentLayout = layout.LayoutName; } // Output some information related to the layout object acDoc.Editor.WriteMessage("\nTab Order: " + layout.TabOrder + "\nTab Selected: " + layout.TabSelected + "\nBlock Table Record ID: " + layout.BlockTableRecordId.ToString()); // Save the changes made trans.Commit(); } }
} // for sorting public _Area_v2(_Db.ObjectId id, _Ge.Point3d s, _Ge.Point3d e) { _id = id; _start = s; _end = e; }
private void alfa(_Db.ObjectId id, ref List <_Db.Dimension> dims, ref List <_Db.BlockReference> blocks, ref List <_Db.MText> txts) { _Db.DBObject currentEntity = _c.trans.GetObject(id, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity == null) { return; } else if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; _Db.BlockTableRecord block = null; if (blockRef.IsDynamicBlock) { block = _c.trans.GetObject(blockRef.DynamicBlockTableRecord, _Db.OpenMode.ForRead) as _Db.BlockTableRecord; } else { block = _c.trans.GetObject(blockRef.BlockTableRecord, _Db.OpenMode.ForRead) as _Db.BlockTableRecord; } if (block != null) { blocks.Add(blockRef); } } else if (currentEntity is _Db.Dimension) { _Db.Dimension dim = currentEntity as _Db.Dimension; dims.Add(dim); } else if (currentEntity is _Db.MText) { _Db.MText br = currentEntity as _Db.MText; txts.Add(br); } else if (currentEntity is _Db.DBText) { _Db.DBText br = currentEntity as _Db.DBText; _Db.MText myMtext = new _Db.MText(); myMtext.Contents = br.TextString; myMtext.Location = br.Position; myMtext.TextHeight = br.Height; txts.Add(myMtext); } else if (currentEntity is _Db.MLeader) { _Db.MLeader br = currentEntity as _Db.MLeader; if (br.ContentType == _Db.ContentType.MTextContent) { _Db.MText leaderText = br.MText; txts.Add(leaderText); } } }
public static void ReplaceAttributeBlock(AcDb.ObjectId idBlock, string tag, string newValue, Boolean visible) { try { //using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) //{ // DBObject dbObj = tr.GetObject(idBlock, AcDb.OpenMode.ForRead) as DBObject; // AcDb.BlockReference blockReference = dbObj as BlockReference; // ReplaceAttributeBlock(blockReference, tag, newValue, visible); //} using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTable acBlockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead); if (acBlockTable == null) { return; } AcDb.BlockTableRecord acBlockTableRecord = (AcDb.BlockTableRecord) tr.GetObject(acBlockTable[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForRead); if (acBlockTableRecord == null) { return; } //foreach (var blkId in acBlockTableRecord) //{ AcDb.BlockReference acBlock = (AcDb.BlockReference)tr.GetObject(idBlock, AcDb.OpenMode.ForRead); //if (acBlock == null) continue; //if (!acBlock.Name.Equals(blockName, StringComparison.CurrentCultureIgnoreCase)) continue; foreach (AcDb.ObjectId attId in acBlock.AttributeCollection) { AcDb.AttributeReference acAtt = (AcDb.AttributeReference)tr.GetObject(attId, AcDb.OpenMode.ForRead); if (acAtt == null) { continue; } if (!acAtt.Tag.Equals(tag, StringComparison.CurrentCultureIgnoreCase)) { continue; } acAtt.UpgradeOpen(); acAtt.TextString = newValue; } //} tr.Commit(); } } catch //(System.Exception exc) { } }
public static void ManualInsertbAttribute(string nameBlock) { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead); if (!blockTable.Has(nameBlock)) { ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock); return; } AcDb.BlockTableRecord curSpace = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); AcDb.BlockReference blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock]); blockReference.TransformBy(ed.CurrentUserCoordinateSystem); curSpace.AppendEntity(blockReference); tr.AddNewlyCreatedDBObject(blockReference, true); AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead); AcDb.DBText text; foreach (AcDb.ObjectId id in btr) { if (id.ObjectClass.Name == "AcDbAttributeDefinition") { AcDb.AttributeDefinition attDef = (AcDb.AttributeDefinition)tr.GetObject(id, AcDb.OpenMode.ForRead); text = new AcDb.DBText { TextString = "jig_test" }; TextPlacementJig jig = new TextPlacementJig(text); //PromptResult pr = ed.Drag(jig); AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword; while (stat == AcEd.PromptStatus.Keyword) { AcEd.PromptResult pr = ed.Drag(jig); stat = pr.Status; if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword) { return; } } AcDb.AttributeReference attRef = new AcDb.AttributeReference(); attRef.SetAttributeFromBlock(attDef, blockReference.BlockTransform); AcDb.ObjectId attId = blockReference.AttributeCollection.AppendAttribute(attRef); tr.AddNewlyCreatedDBObject(attRef, true); tr.Commit(); //if (pr.Status != PromptStatus.OK) blockReference.Erase(); } } //tr.Commit(); } }
/// <summary> /// Видаляє елементи вектору з данними виносу. /// </summary> private void DeleteDrawingStakeOut() { ServiceCAD.DeleteObject(this.lineID); ServiceCAD.DeleteObject(this.txtID); this.txtID = AcDb.ObjectId.Null; this.lineID = AcDb.ObjectId.Null; }
public CompoundDrawable Drawable(_OdDb.ObjectId id) { if (_grasshopperData.TryGetValue(id, out var drawable)) { return(drawable); } return(null); }
//[_AcTrx.LispFunction("C:Plan2AufteilungNet")] //public static void Plan2AufteilungNet(_AcDb.ResultBuffer rb) //{ // var acadApp = (Autodesk.AutoCAD.Interop.AcadApplication)_AcAp.Application.AcadApplication; // _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; // _AcDb.Database db = doc.Database; // _AcEd.Editor ed = doc.Editor; // try // { // ed.Command("_.LAYER", "_TH", "*", "_ON", "*", "_UN", "*", ""); // var selOp = new _AcEd.PromptSelectionOptions(); // selOp.MessageForAdding = "Zu verschiebende Elemente wählen: "; // _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { // new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator ,"<NOT"), // new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator ,"<AND"), // new _AcDb.TypedValue((int)_AcDb.DxfCode.Start ,"*POLYLINE"), // new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName , "A_AL_MANSFEN"), // new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator ,"AND>"), // new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator ,"NOT>") // }); // while (true) // { // var res = ed.GetSelection(selOp, filter); // if (res.Status != _AcEd.PromptStatus.OK) // { // break; // } // else // { // var ss = res.Value; // var selOpE = new _AcEd.PromptSelectionOptions(); // _AcDb.ObjectId mf1 = default(_AcDb.ObjectId); // if (!GetMansfen("Quell-Mansfen wählen: ", ref mf1)) break; // _AcDb.ObjectId mf2 = default(_AcDb.ObjectId); // if (!GetMansfen("Ziel-Mansfen wählen: ", ref mf2)) break; // if (!SameMansfens(mf1, mf2)) // { // ed.WriteMessage("\nDie gewählten Mansfens sind nicht identisch!"); // System.Windows.Forms.MessageBox.Show("\nDie gewählten Mansfens sind nicht identisch!", "Plan2AufteilungNet"); // } // else // { // _AcGe.Point3d fromPoint = GetLuPoint(mf1); // _AcGe.Point3d toPoint = GetLuPoint(mf2); // string dwgName = doc.Name; // var dwgProposal = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(dwgName), System.IO.Path.GetFileNameWithoutExtension(dwgName) + "_X.dwg"); // _AcWnd.SaveFileDialog sfd = new _AcWnd.SaveFileDialog("Ziel-Zeichnung", dwgProposal, "dwg", "TargetDrawing", _AcWnd.SaveFileDialog.SaveFileDialogFlags.NoFtpSites); // System.Windows.Forms.DialogResult dr = sfd.ShowDialog(); // if (dr == System.Windows.Forms.DialogResult.OK) // { // var ucs = ed.CurrentUserCoordinateSystem; // var fromPointU = Globs.TransWcsUcs(fromPoint); // fromPoint.TransformBy(ucs); // var toPointU = Globs.TransWcsUcs(toPoint); // toPoint.TransformBy(ucs); // // only acad2015 - // //ed.Command("_.UNDO", "_M"); // //ed.Command("_.DIMDISASSOCIATE", ss, ""); // //ed.Command("_.MOVE", ss, "", fromPointU, toPointU); // ////ed.Command("_.MOVE", ss, "", "0,0", "100,100"); // //ed.Command("_.ERASE", "_ALL", "_R", ss, mf2, ""); // //doc.Database.SaveAs(sfd.Filename, false, _AcDb.DwgVersion.Current, doc.Database.SecurityParameters); // //ed.Command("_.UNDO", "_B"); // //doc.SendStringToExecute("._UNDO B", true, false, true); // // also supports acad2013 // //doc.SendStringToExecute(".'_UNDO M ", true, false, true); // acadApp.ActiveDocument.SendCommand("_.UNDO _M "); // acadApp.ActiveDocument.SendCommand("_.DIMDISASSOCIATE _P "); // } // } // Globs.HightLight(mf1, onOff: false); // Globs.HightLight(mf2, onOff: false); // } // } // } // catch (System.Exception ex) // { // string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2AufteilungNet): {0}", ex.Message); // ed.WriteMessage("\n" + msg); // System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2AufteilungNet"); // } //} #endif private static _AcGe.Point3d GetLuPoint(_AcDb.ObjectId mf1) { List <_AcGe.Point2d> pts1 = GetLwPoints(mf1); var xMin = pts1.Select(x => x.X).Min(); var yMin = pts1.Select(x => x.Y).Min(); return(new _AcGe.Point3d(xMin, yMin, 0.0)); }
private static _AcDb.Extents3d GetExtents(_AcDb.TransactionManager tm, _AcDb.ObjectId oid) { using (_AcDb.DBObject dbobj = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false)) { _AcDb.Entity ent = dbobj as _AcDb.Entity; return(ent.GeometricExtents); } }
public static AcDb.ObjectId InsertBlock( String nameBlock, AcGe.Point3d insertionPoint, double scale, AcDb.ObjectId layerId, double rotation) { return(InsertBlock(nameBlock, insertionPoint, scale, rotation, layerId, null)); }
private _AcDb.ObjectId CreateNewLayer(_AcAp.Document doc, _AcDb.Database db) { using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction()) { try { string layerName = "MyTest"; _AcDb.LayerTable layTb = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForRead) as _AcDb.LayerTable; using (_AcDb.LayerTableRecord acLyrTblRec = new _AcDb.LayerTableRecord()) { // Assign the layer a name acLyrTblRec.Name = layerName; // Upgrade the Layer table for write layTb.UpgradeOpen(); // Append the new layer to the Layer table and the transaction layTb.Add(acLyrTblRec); trans.AddNewlyCreatedDBObject(acLyrTblRec, true); int transparenz = 10; Byte alpha = TransparenzToAlpha(transparenz); _AcCm.Transparency tr = new _AcCm.Transparency(alpha); acLyrTblRec.Transparency = tr; _AcCm.Color col = _AcCm.Color.FromColorIndex(_AcCm.ColorMethod.ByColor, 2); //_AcCm.Color col = _AcCm.Color.FromRgb(10, 20, 30); acLyrTblRec.Color = col; _AcDb.ObjectId ltOid = GetLinetypeFromName("Continuous", trans, db); if (!ltOid.IsNull) { acLyrTblRec.LinetypeObjectId = ltOid; } _AcDb.LineWeight lw = _AcDb.LineWeight.LineWeight030; acLyrTblRec.LineWeight = lw; // ??? //acLyrTblRec.PlotStyleName = "hugo"; acLyrTblRec.Description = "My new Layer"; return(acLyrTblRec.ObjectId); } } finally { trans.Commit(); } } }
public static AcDb.DBObject GetObject(AcDb.ObjectId objectId) { AcDb.DBObject obj = null; using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { obj = tr.GetObject(objectId, AcDb.OpenMode.ForWrite); obj.Erase(); tr.Commit(); } return(obj); }
public static void DrawOrder_MoveBelow(AcDb.ObjectIdCollection collection, AcDb.ObjectId target) { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTable bt = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead); AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(bt[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForWrite); AcDb.DrawOrderTable dot = (AcDb.DrawOrderTable)tr.GetObject(btr.DrawOrderTableId, AcDb.OpenMode.ForWrite); dot.MoveBelow(collection, target); } }
public BlockPlacementJig(AcDb.BlockReference br, Dictionary <string, string> tags) : base(br) { blockReference = br; position = blockReference.Position; AcEd.Editor ed = CurrentCAD.Editor; AcGe.CoordinateSystem3d ucs = ed.CurrentUserCoordinateSystem.CoordinateSystem3d; AcGe.Matrix3d ocsMat = AcGe.Matrix3d.WorldToPlane(new AcGe.Plane(AcGe.Point3d.Origin, ucs.Zaxis)); ucsRotation = AcGe.Vector3d.XAxis.GetAngleTo(ucs.Xaxis.TransformBy(ocsMat), ucs.Zaxis); rotation = blockReference.Rotation - ucsRotation; this.tags = tags; layerId = blockReference.LayerId; }
public static void SetXData(AcDb.ObjectId objectId, AcDb.ResultBuffer valueXData) { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(objectId, AcDb.OpenMode.ForWrite); AddRegAppTableRecord((string)valueXData.AsArray()[0].Value); obj.XData = valueXData; valueXData.Dispose(); tr.Commit(); } }
public void SetLineType(string lt, _AcDb.Transaction trans, _AcDb.Database db) { _LineType = lt; var lto = GetLinetypeFromName(_LineType, trans, db); if (lto == default(_AcDb.ObjectId)) { _Errors = _Errors + string.Format(CultureInfo.CurrentCulture, "\nUngültiger Linientyp '{0}' für Layer '{1}'", _LineType, OldLayer); return; } _LineTypeO = lto; }
private List <_AcDb.ObjectId> GetFgAnz(_AcGe.Point3d minExt, _AcGe.Point3d maxExt, _AcDb.ObjectId elFG) { List <_AcDb.ObjectId> Ret = new List <_AcDb.ObjectId>(); _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "*POLYLINE"), new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName, _FgLayer) }); _AcEd.PromptSelectionResult res = null; res = ed.SelectCrossingWindow(minExt, maxExt, filter); //res = ed.SelectAll(filter); if (res.Status != _AcEd.PromptStatus.OK) { // todo: logging: lot4net? return(Ret); } #if BRX_APP _AcEd.SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { _AcDb.ObjectId[] idArray = ss.GetObjectIds(); _AcDb.Database db = _AcAp.Application.DocumentManager.MdiActiveDocument.Database; _AcDb.TransactionManager tm = db.TransactionManager; _AcDb.Transaction myT = tm.StartTransaction(); try { for (int i = 0; i < idArray.Length; i++) { _AcDb.ObjectId oid = idArray[i]; if (!oid.Equals(elFG)) { if (PolyInPoly(tm, oid, elFG)) { AddRbToRetCol(Ret, tm, oid); } } } myT.Commit(); } finally { myT.Dispose(); } } return(Ret); }
private static void FehlerLineOrHatchPoly(_AcDb.ObjectId oid, string layer, int red, int green, int blue, _AcDb.TransactionManager tm, _AcGe.Point3d?label) { if (label.HasValue) { _AcCm.Color col = _AcCm.Color.FromRgb((byte)red, (byte)green, (byte)blue); Plan2Ext.Globs.InsertFehlerLines(new List <_AcGe.Point3d> { label.Value }, layer, 50, Math.PI * 1.25, col); } else { HatchPoly(oid, layer, red, green, blue, tm); } }
public void initLayer(string layerName) { _Db.LayerTable layerTable = _c.trans.GetObject(_c.db.LayerTableId, _Db.OpenMode.ForWrite) as _Db.LayerTable; if (!layerTable.Has(layerName)) { _Db.LayerTableRecord newLayer = new _Db.LayerTableRecord(); newLayer.Name = layerName; newLayer.Color = _Cm.Color.FromColorIndex(_Cm.ColorMethod.None, 1); _Db.ObjectId layerId = layerTable.Add(newLayer); _c.trans.AddNewlyCreatedDBObject(newLayer, true); } }
private void ExplodeBlocks(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs, List <_AcDb.ObjectId> newlyCreatedObjects, bool deleteRef, bool deleteBtr) { log.Debug("ExplodeXRefs"); using (_AcDb.Transaction tr = _TransMan.StartTransaction()) { _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead); _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(_AcDb.SymbolUtilityServices.GetBlockModelSpaceId(db), _AcDb.OpenMode.ForWrite); foreach (var oid in allXrefsInMs) { _AcDb.DBObjectCollection objs = new _AcDb.DBObjectCollection(); _AcDb.BlockReference block = (_AcDb.BlockReference)tr.GetObject(oid, _AcDb.OpenMode.ForRead); log.DebugFormat(CultureInfo.CurrentCulture, "Explode von Block '{0}'.", block.Name); block.Explode(objs); log.DebugFormat(CultureInfo.CurrentCulture, "Block enthält {0} Entities.", objs.Count); _AcDb.ObjectId blockRefTableId = block.BlockTableRecord; foreach (_AcDb.DBObject obj in objs) { _AcDb.Entity ent = (_AcDb.Entity)obj; btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); newlyCreatedObjects.Add(ent.ObjectId); } if (deleteRef) { log.DebugFormat(CultureInfo.CurrentCulture, "Lösche Block '{0}'.", block.Name); block.UpgradeOpen(); block.Erase(); } if (deleteBtr) { log.DebugFormat("DeleteBtr"); // funkt nicht -> xref würde gelöscht var bd = (_AcDb.BlockTableRecord)tr.GetObject(blockRefTableId, _AcDb.OpenMode.ForWrite); bd.Erase(); log.DebugFormat("Endof DeleteBtr"); } } tr.Commit(); } }
public static void DeleteObject(AcDb.ObjectId objectId) { try { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.DBObject dbObj = tr.GetObject(objectId, AcDb.OpenMode.ForRead) as AcDb.DBObject; dbObj.UpgradeOpen(); dbObj.Erase(); tr.Commit(); } } catch //(System.Exception exc) { } }
private void AddRbToRetCol(List <_AcDb.ObjectId> Ret, _AcDb.TransactionManager tm, _AcDb.ObjectId elFG) { _AcDb.Extents3d ext = GetExtents(tm, elFG); _AcGe.Point3d minExt = new _AcGe.Point3d(ext.MinPoint.X - ABSTANDTEXT, ext.MinPoint.Y - ABSTANDTEXT, ext.MinPoint.Z); _AcGe.Point3d maxExt = new _AcGe.Point3d(ext.MaxPoint.X + ABSTANDTEXT, ext.MaxPoint.Y + ABSTANDTEXT, ext.MaxPoint.Z); _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"), new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName, _RaumblockName) }); _AcEd.PromptSelectionResult res = null; res = ed.SelectCrossingWindow(minExt, maxExt, filter); if (res.Status != _AcEd.PromptStatus.OK) { // todo: logging: lot4net? return; } #if BRX_APP _AcEd.SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { _AcDb.ObjectId[] idArray = ss.GetObjectIds(); for (int i = 0; i < idArray.Length; i++) { _AcDb.ObjectId oid = idArray[i]; using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false)) { using (_AcDb.Entity entElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false) as _AcDb.Entity) { if (pEntity is _AcDb.BlockReference) { _AcDb.BlockReference br = pEntity as _AcDb.BlockReference; if (AreaEngine.InPoly(br.Position, entElFG)) { Ret.Add(oid); } } } } } } }
public void DisplayArrays(int numberСolumns, int numberRows, double stepСolumns, double stepRows) { for (int i = 0; i < numberСolumns; i++) { for (int j = 0; j < numberRows; j++) { AcGe.Vector3d offset = new AcGe.Vector3d(j * stepRows, i * stepСolumns, 0); AcGe.Point3d insertPoint = this.BasePointArrays.Add(offset); AcDb.ObjectId objId = ServiceBlockElements.InsertBlock(this.NameBlock, insertPoint, this.ScaleBlock, this.RotationBlock); if (objId.IsNull) { return; } } } }