private void outputWeight(_Area_v2 a, int weight) { _Db.DBObject currentEntity = _c.trans.GetObject(a.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; foreach (_Db.ObjectId arId in blockRef.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { if (ar.Tag == "SUMMA_OVRIG_ARMERING") { if (weight == 0) { write("[WARINING] Weight set to 'YYY'"); ar.TextString = "YYY"; } else { ar.TextString = weight.ToString(); } } } } } _c.trans.Commit(); }
public void renameBlockFields(string find, string replace) { foreach (_Db.ObjectId btrId in _c.blockTable) { _Db.BlockTableRecord btr = _c.trans.GetObject(btrId, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord; _Db.ObjectIdCollection blockRefIds = btr.GetBlockReferenceIds(true, true); foreach (_Db.ObjectId btRfId in blockRefIds) { _Db.BlockReference br = _c.trans.GetObject(btRfId, _Db.OpenMode.ForWrite) as _Db.BlockReference; if (br != null) { foreach (_Db.ObjectId arId in br.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { ar.TextString = ar.TextString.Replace(find, replace); } } } } } }
static public void GetXData() { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; AcEd.Editor ed = doc.Editor; AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: "); AcEd.PromptEntityResult res = ed.GetEntity(opt); if (res.Status == AcEd.PromptStatus.OK) { using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForRead); AcDb.ResultBuffer rb = obj.XData; if (rb == null) { ed.WriteMessage("\nEntity does not have XData attached."); } else { int n = 0; foreach (AcDb.TypedValue tv in rb) { ed.WriteMessage("\nTypedValue {0} - type: {1}, value: {2}", n++, tv.TypeCode, tv.Value); } rb.Dispose(); } } } }
private List <T.BendingShape> getBendingData(List <_Db.BlockReference> blocks) { List <T.BendingShape> parse = new List <T.BendingShape>(); foreach (_Db.BlockReference block in blocks) { G.Point insp = new G.Point(block.Position.X, block.Position.Y); T.BendingShape current = new T.BendingShape(insp, block.Name); foreach (_Db.ObjectId arId in block.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; setBendingParameters(ar, current); } current.validator(); if (current.Valid) { parse.Add(current); } else { write(current.Reason); } } return(parse); }
private void outputTable(_Area_v2 a, List <_Mark> rows) { _Db.DBObject currentEntity = _c.trans.GetObject(a.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; double scale = blockRef.ScaleFactors.X; string name = blockRef.Name; _Ge.Point3d currentPoint = a.Start; if (name == newBoxNames[0]) { currentPoint = new _Ge.Point3d(a.Start.X + (366 * scale), a.Start.Y + (141.8 * scale), a.Start.Z); } else if (name == newBoxNames[1]) { currentPoint = new _Ge.Point3d(a.Start.X + (366 * scale), a.Start.Y + (263.5 * scale), a.Start.Z); } int counter = 0; foreach (_Mark r in rows) { if (r.Position != "emptyrow") { double txtHeight = 1.5 * scale; _Ge.Point3d position_IP = new _Ge.Point3d(currentPoint.X + (1 * scale), currentPoint.Y + (1.125 * scale), currentPoint.Z); _Ge.Point3d diameter_IP = new _Ge.Point3d(currentPoint.X + (0.75 * scale) + (6.1 * scale), currentPoint.Y + (1.125 * scale), currentPoint.Z); _Ge.Point3d number_IP = new _Ge.Point3d(currentPoint.X + (1.5 * scale) + (9.75 * scale), currentPoint.Y + (1.125 * scale), currentPoint.Z); insertText(r.Position, position_IP, _Mark.markLayerName, txtHeight); insertText(r.Diameter.ToString(), diameter_IP, _Mark.markLayerName, txtHeight); insertText(r.Number.ToString(), number_IP, _Mark.markLayerName, txtHeight); } if (counter == 19) { if (name == newBoxNames[0]) { currentPoint = new _Ge.Point3d(a.Start.X + (336 * scale), a.Start.Y + (141.8 * scale), a.Start.Z); } else if (name == newBoxNames[1]) { currentPoint = new _Ge.Point3d(a.Start.X + (336 * scale), a.Start.Y + (263.5 * scale), a.Start.Z); } } else { currentPoint = new _Ge.Point3d(currentPoint.X, currentPoint.Y - (4 * scale), currentPoint.Z); } counter++; } } }
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); } } }
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); } }
private string getAreaName(_Area_v2 area) { string ritn_nr = "x"; _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; foreach (_Db.ObjectId arId in blockRef.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { if (ar.Tag == "RITN_NR") { ritn_nr = ar.TextString; } if (blockRef.Name == "KN-V23") { if (ar.Tag == "RITN_23_NR") { ritn_nr = ar.TextString; } } else if (blockRef.Name == "KN-V27") { if (ar.Tag == "RITN_27_NR") { ritn_nr = ar.TextString; } } } } if (blockRef.Name == "KN-V23") { if (!ritn_nr.Contains("23")) { ritn_nr = "V23-" + ritn_nr; } } else if (blockRef.Name == "KN-V27") { if (!ritn_nr.Contains("73")) { ritn_nr = "V27-" + ritn_nr; } } } return(ritn_nr); }
static public void Plan2CenterBlockSelBlock() { try { if (!OpenPalette()) { return; } var opts = Globs.TheOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager; if (doc == null) { return; } _AcEd.Editor ed = doc.Editor; #if NEWSETFOCUS doc.Window.Focus(); #else Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions #endif _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nBlock wählen: "); if (per.Status == _AcEd.PromptStatus.OK) { using (var tr = doc.TransactionManager.StartTransaction()) { _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); _AcDb.BlockReference br = obj as _AcDb.BlockReference; if (br == null) { br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per); if (br == null) { return; } } opts.SetBlockname(br.Name); tr.Commit(); } } } } catch (System.Exception ex) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2CenterBlockSelBlock aufgetreten! {0}", ex.Message)); } }
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 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(); } }
private double getAreaScale(_Area_v2 area) { double scale = 1; _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; scale = blockRef.ScaleFactors.X; } return(scale); }
private void get27Data(List <element> elements) { foreach (element el in elements) { _Area_v2 area = el._27; string date = "xyz"; string rev = "xyz"; string net_weight = "xyz"; string reinf_weight = "xyz"; _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; foreach (_Db.ObjectId arId in blockRef.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { if (ar.Tag == "DATUM") { date = ar.TextString; } if (ar.Tag == "REVISION") { rev = ar.TextString; } if (ar.Tag == "SUMMA_NATARMERING") { net_weight = ar.TextString; } if (ar.Tag == "SUMMA_OVRIG_ARMERING") { reinf_weight = ar.TextString; } } } } el._date27 = date; el._rev27 = rev; el._sum_net = net_weight; el._sum_reinf = reinf_weight; } }
private List <_Db.BlockReference> getSelectedBlockReference(string[] blockNames) { List <_Db.BlockReference> refs = new List <_Db.BlockReference>(); _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions(); opts.MessageForAdding = "\nSelect BLOCK " + blockNames[0] + " / " + blockNames[1]; _Ed.PromptSelectionResult selection = _c.ed.GetSelection(opts); if (selection.Status == _Ed.PromptStatus.OK) { _Db.ObjectId[] selectionIds = selection.Value.GetObjectIds(); foreach (_Db.ObjectId id in selectionIds) { _Db.DBObject currentEntity = _c.trans.GetObject(id, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity == null) { continue; } 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) { if (blockNames.Contains(block.Name)) { refs.Add(blockRef); } } } } } return(refs); }
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 _Ge.Point3d getAreaCenter(_Area_v2 area) { _Ge.Point3d center = new _Ge.Point3d(0, 0, 0); _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; _Ge.Point3d max = blockRef.GeometricExtents.MaxPoint; _Ge.Point3d min = blockRef.GeometricExtents.MinPoint; center = new _Ge.Point3d(min.X + ((max.X - min.X) / 2), min.Y + ((max.Y - min.Y) / 2), 0); } return(center); }
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 static AcDb.ResultBuffer GetXData(AcDb.ObjectId objectId) { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(objectId, AcDb.OpenMode.ForRead); AcDb.ResultBuffer resultBuffer = obj.XData; if (resultBuffer == null) { return(null); } else { return(resultBuffer); } } }
private string getAttributeValue(_Db.BlockReference block, string[] attribute) { foreach (_Db.ObjectId arId in block.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { if (attribute.Contains(ar.Tag)) { return(ar.TextString); } } } return(null); }
private List <_Db.BlockReference> getAllBlockReference(string blockName) { List <_Db.BlockReference> refs = new List <_Db.BlockReference>(); if (_c.blockTable.Has(blockName)) { _Db.BlockTableRecord btr = _c.trans.GetObject(_c.modelSpace.Id, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord; foreach (_Db.ObjectId id in btr) { _Db.DBObject currentEntity = _c.trans.GetObject(id, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity == null) { continue; } 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) { if (block.Name == blockName) { refs.Add(blockRef); } } } } } return(refs); }
private static bool GetAttributeInfos(_AcEd.Editor ed, _AcAp.Document doc) { bool ok = false; _BlockName = string.Empty; _AttributeName = string.Empty; _AttributeValue = string.Empty; _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nZu änderndes Attribut wählen: "); if (per.Status == _AcEd.PromptStatus.OK) { using (var tr = doc.TransactionManager.StartTransaction()) { _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); _AcDb.AttributeReference ar = obj as _AcDb.AttributeReference; if (ar != null && !ar.IsConstant) { _AcDb.BlockReference br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per); if (br != null) { ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nBlockname: {0}, Attributname: {1}.", Plan2Ext.Globs.GetBlockname(br, tr), ar.Tag)); var prompt = new _AcEd.PromptStringOptions("\nText in Attribut: "); prompt.AllowSpaces = true; var prefixUserRes = ed.GetString(prompt); if (prefixUserRes.Status == _AcEd.PromptStatus.OK) { _AttributeValue = prefixUserRes.StringResult; _AttributeName = ar.Tag; _BlockName = Plan2Ext.Globs.GetBlockname(br, tr); log.InfoFormat(CultureInfo.CurrentCulture, "Block: {0}, Attribut: {1}, Wert: '{2}'", _BlockName, _AttributeName, _AttributeValue); ok = true; } } } tr.Commit(); } } return(ok); }
private void insertBending(R.Raud _ALFA_, G.Point insertion) { string layerName = "K023TL"; string blockName = getBendingBlockName(_ALFA_); _Ge.Point3d insertPointBlock = new _Ge.Point3d(insertion.X, insertion.Y, 0); using (_Db.BlockReference newBlockReference = new _Db.BlockReference(insertPointBlock, _c.blockTable[blockName])) { newBlockReference.Layer = layerName; _c.modelSpace.AppendEntity(newBlockReference); _c.trans.AddNewlyCreatedDBObject(newBlockReference, true); newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(L._V_.Z_DRAWING_SCALE, insertPointBlock)); _Db.BlockTableRecord blockBlockTable = _c.trans.GetObject(_c.blockTable[blockName], _Db.OpenMode.ForRead) as _Db.BlockTableRecord; if (blockBlockTable.HasAttributeDefinitions) { foreach (_Db.ObjectId objID in blockBlockTable) { _Db.DBObject obj = _c.trans.GetObject(objID, _Db.OpenMode.ForRead) as _Db.DBObject; if (obj is _Db.AttributeDefinition) { _Db.AttributeDefinition attDef = obj as _Db.AttributeDefinition; if (!attDef.Constant) { using (_Db.AttributeReference attRef = new _Db.AttributeReference()) { attRef.SetAttributeFromBlock(attDef, newBlockReference.BlockTransform); attRef.Position = attDef.Position.TransformBy(newBlockReference.BlockTransform); setBendingBlockParameters(attRef, _ALFA_); newBlockReference.AttributeCollection.AppendAttribute(attRef); _c.trans.AddNewlyCreatedDBObject(attRef, true); } } } } } } }
private List <T.TableBendingRow> getRowData(List <_Db.BlockReference> blocks) { List <T.TableBendingRow> parse = new List <T.TableBendingRow>(); foreach (_Db.BlockReference block in blocks) { G.Point insp = new G.Point(block.Position.X, block.Position.Y); T.TableBendingRow current = new T.TableBendingRow(insp); foreach (_Db.ObjectId arId in block.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; setRowAttribute(ar, current); } parse.Add(current); } return(parse); }
private void get23Data(List <element> elements) { foreach (element el in elements) { _Area_v2 area = el._23; string date = "xyz"; string rev = "xyz"; _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; foreach (_Db.ObjectId arId in blockRef.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { if (ar.Tag == "DATUM") { date = ar.TextString; } if (ar.Tag == "REVISION") { rev = ar.TextString; } } } } el._date23 = date; el._rev23 = rev; } }
private void insertRow(G.Point insertion, T.TableBendingRow rowData, double scale, string tableBendingRow) { _Ge.Point3d insertPointBlock = new _Ge.Point3d(insertion.X, insertion.Y, 0); using (_Db.BlockReference newBlockReference = new _Db.BlockReference(insertPointBlock, _c.blockTable[tableBendingRow])) { newBlockReference.Layer = bendingLayer; _c.modelSpace.AppendEntity(newBlockReference); _c.trans.AddNewlyCreatedDBObject(newBlockReference, true); newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(scale, insertPointBlock)); _Db.BlockTableRecord blockBlockTable = _c.trans.GetObject(_c.blockTable[tableBendingRow], _Db.OpenMode.ForRead) as _Db.BlockTableRecord; if (blockBlockTable.HasAttributeDefinitions) { foreach (_Db.ObjectId objID in blockBlockTable) { _Db.DBObject obj = _c.trans.GetObject(objID, _Db.OpenMode.ForRead) as _Db.DBObject; if (obj is _Db.AttributeDefinition) { _Db.AttributeDefinition attDef = obj as _Db.AttributeDefinition; if (!attDef.Constant) { using (_Db.AttributeReference attRef = new _Db.AttributeReference()) { attRef.SetAttributeFromBlock(attDef, newBlockReference.BlockTransform); attRef.Position = attDef.Position.TransformBy(newBlockReference.BlockTransform); setRowParameters(attRef, rowData); newBlockReference.AttributeCollection.AppendAttribute(attRef); _c.trans.AddNewlyCreatedDBObject(attRef, true); } } } } } } }
private void getSettings() { _Db.TypedValue[] filterlist = new _Db.TypedValue[2]; filterlist[0] = new _Db.TypedValue(0, "INSERT"); filterlist[1] = new _Db.TypedValue(2, "Reinf_program_settings"); _Ed.SelectionFilter filter = new _Ed.SelectionFilter(filterlist); _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions(); opts.MessageForAdding = "\nSelect Reinf_program_settings block: "; _Ed.PromptSelectionResult selection = _c.ed.GetSelection(opts, filter); if (selection.Status != _Ed.PromptStatus.OK) { throw new DMTException("[ERROR] Reinf_program_settings - cancelled"); } if (selection.Value.Count != 1) { throw new DMTException("[ERROR] Reinf_program_settings - too many in selection"); } _Db.ObjectId selectionId = selection.Value.GetObjectIds()[0]; _Db.BlockReference selectionBR = _c.trans.GetObject(selectionId, _Db.OpenMode.ForWrite) as _Db.BlockReference; L._V_.Z_DRAWING_SCALE = selectionBR.ScaleFactors.X; foreach (_Db.ObjectId arId in selectionBR.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { setProgramVariables(ar); } } }
static public void SetXData() { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; AcEd.Editor ed = doc.Editor; AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: "); AcEd.PromptEntityResult res = ed.GetEntity(opt); if (res.Status == AcEd.PromptStatus.OK) { using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForWrite); AddRegAppTableRecord("KEAN"); AcDb.ResultBuffer rb = new AcDb.ResultBuffer( new AcDb.TypedValue(1001, "KEAN"), new AcDb.TypedValue(1000, "This is a test string") ); obj.XData = rb; rb.Dispose(); tr.Commit(); } } }
private List <element> matchAreaToArea(List <_Area_v2> areas_dimentions, List <_Area_v2> areas_reinf) { List <element> elements = new List <element>(); foreach (_Area_v2 area_dim in areas_dimentions) { string ritn_nr_dim_a = "x"; string ritn_nr_dim_b = "x"; _Db.DBObject currentEntity = _c.trans.GetObject(area_dim.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity as _Db.BlockReference; foreach (_Db.ObjectId arId in blockRef.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { if (ar.Tag == "RITN_23_NR") { ritn_nr_dim_a = ar.TextString; } if (ar.Tag == "RITN_27_NR") { ritn_nr_dim_b = ar.TextString; } if (ar.Tag == "RITN_NR") { ritn_nr_dim_a = ar.TextString; } if (ar.Tag == "RITN_NR") { ritn_nr_dim_b = ar.TextString; } } } } foreach (_Area_v2 area_reinf in areas_reinf) { string ritn_nr_reinf_a = "x"; string ritn_nr_reinf_b = "x"; _Db.DBObject currentEntity_2 = _c.trans.GetObject(area_reinf.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject; if (currentEntity_2 is _Db.BlockReference) { _Db.BlockReference blockRef = currentEntity_2 as _Db.BlockReference; foreach (_Db.ObjectId arId in blockRef.AttributeCollection) { _Db.DBObject obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite); _Db.AttributeReference ar = obj as _Db.AttributeReference; if (ar != null) { if (ar.Tag == "RITN_23_NR") { ritn_nr_reinf_a = ar.TextString; } if (ar.Tag == "RITN_27_NR") { ritn_nr_reinf_b = ar.TextString; } if (ar.Tag == "RITN_NR") { ritn_nr_reinf_a = ar.TextString; } if (ar.Tag == "RITN_NR") { ritn_nr_reinf_b = ar.TextString; } } } } if (ritn_nr_dim_a == ritn_nr_reinf_a) { if (ritn_nr_reinf_a != "x") { element el = new element(area_dim, area_reinf, ritn_nr_dim_a, ritn_nr_dim_b); elements.Add(el); break; } } } } return(elements); }
private static bool PolyInPoly(_AcDb.TransactionManager tm, _AcDb.ObjectId oid, _AcDb.ObjectId elFG) { using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false)) { using (_AcDb.DBObject pElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false)) { if (pEntity is _AcDb.Polyline2d) { _AcDb.Polyline2d oldPolyline = (_AcDb.Polyline2d)pEntity; foreach (_AcDb.ObjectId Vertex2d in oldPolyline) { using (_AcDb.DBObject dbobj = tm.GetObject(Vertex2d, _AcDb.OpenMode.ForRead, false)) { _AcDb.Vertex2d vertex = dbobj as _AcDb.Vertex2d; if (vertex == null) { string msg = string.Format(CultureInfo.CurrentCulture, "Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", oldPolyline.Handle.ToString(), dbobj.GetType().ToString()); throw new InvalidOperationException(string.Format(msg)); } _AcGe.Point3d vertexPoint = oldPolyline.VertexPosition(vertex); if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG)) { return(false); } } } return(true); } else if (pEntity is _AcDb.Polyline3d) { _AcDb.Polyline3d poly3d = (_AcDb.Polyline3d)pEntity; foreach (_AcDb.ObjectId Vertex3d in poly3d) { using (_AcDb.DBObject dbobj = tm.GetObject(Vertex3d, _AcDb.OpenMode.ForRead, false)) { _AcDb.PolylineVertex3d vertex = dbobj as _AcDb.PolylineVertex3d; if (vertex == null) { string msg = string.Format(CultureInfo.CurrentCulture, "3D-Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", poly3d.Handle.ToString(), dbobj.GetType().ToString()); throw new InvalidOperationException(string.Format(msg)); } _AcGe.Point3d vertexPoint = vertex.Position; if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG)) { return(false); } } } return(true); } else if (pEntity is _AcDb.Polyline) { _AcDb.Polyline poly = pEntity as _AcDb.Polyline; for (int i = 0; i < poly.NumberOfVertices; i++) { _AcGe.Point3d vertexPoint = poly.GetPoint3dAt(i); if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG)) { return(false); } } return(true); } } } return(false); }
internal void DoIt(_AcAp.Document doc, string rbName, string fgLayer) { log.Debug("--------------------------"); _FlaechenGrenzen.Clear(); _Raumbloecke.Clear(); var _AreaEngine = new AreaEngine(); _AcGe.Matrix3d ucs = _AcGe.Matrix3d.Identity; try { ucs = doc.Editor.CurrentUserCoordinateSystem; doc.Editor.CurrentUserCoordinateSystem = _AcGe.Matrix3d.Identity; if (!string.IsNullOrEmpty(rbName)) { _RaumblockName = rbName; } if (!string.IsNullOrEmpty(fgLayer)) { _FgLayer = fgLayer; } _AreaEngine.SelectFgAndRb(_FlaechenGrenzen, _Raumbloecke, _FgLayer, _RaumblockName); if (_FlaechenGrenzen.Count == 0) { return; } // todo: läuft nicht synchron - wird dzt in lisp ausgeführt //Globs.SetWorldUCS(); ZoomToFlaechenGrenzen(); // init div int fehlerKeinRb = 0; int fehlerMehrRb = 0; int fehlerWertFalsch = 0; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcDb.TransactionManager tm = db.TransactionManager; _AcDb.Transaction myT = tm.StartTransaction(); try { _AcGe.Point2d lu = new _AcGe.Point2d(); _AcGe.Point2d ro = new _AcGe.Point2d(); for (int i = 0; i < _FlaechenGrenzen.Count; i++) { log.Debug("--------------------------"); double sumAF = 0; int rbInd = -1; _AcDb.ObjectId elFG = _FlaechenGrenzen[i]; log.DebugFormat("Flächengrenze {0}", elFG.Handle.ToString()); _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); List <_AcDb.ObjectId> rbsToIgnoreCol = GetFgAnz(minExt, maxExt, elFG); if (rbsToIgnoreCol.Count > 0) { string handles = string.Join(",", rbsToIgnoreCol.Select(x => x.Handle.ToString()).ToArray()); log.DebugFormat("Zu ignorierende Raumblöcke: {0}", handles); } // 'raumbloecke holen List <_AcDb.ObjectId> ssRB = selRB(minExt, maxExt); if (ssRB.Count > 0) { string handles = string.Join(",", ssRB.Select(x => x.Handle.ToString()).ToArray()); log.DebugFormat("Raumblöcke: {0}", handles); } int rbAnz = 0; // 'raumbloecke pruefen for (int rbCnt = 0; rbCnt < ssRB.Count; rbCnt++) { _AcDb.ObjectId rbBlock2 = ssRB[rbCnt]; // ' ignore rbs _AcDb.ObjectId found = rbsToIgnoreCol.FirstOrDefault(x => x.Equals(rbBlock2)); if (found != default(_AcDb.ObjectId)) { continue; } using (_AcDb.DBObject dbObj = tm.GetObject(rbBlock2, _AcDb.OpenMode.ForRead, false)) { _AcGe.Point3d rbEp = ((_AcDb.BlockReference)dbObj).Position; using (_AcDb.Entity elFGEnt = (_AcDb.Entity)tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false)) { if (AreaEngine.InPoly(rbEp, elFGEnt)) { log.DebugFormat("Raumblock {0} ist innerhalb der Flächengrenze.", rbBlock2.Handle.ToString()); if (_Raumbloecke.Contains(rbBlock2)) { _Raumbloecke.Remove(rbBlock2); } rbAnz++; rbInd = rbCnt; } else { log.DebugFormat("Außen liegender Raumblock {0} wird ignoriert.", rbBlock2.Handle.ToString()); } } } } if (rbAnz < 1) { log.WarnFormat("Kein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString()); //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG)); fehlerKeinRb++; } else if (rbAnz > 1) { log.WarnFormat("Mehr als ein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString()); //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG)); fehlerMehrRb++; } else { using (var tr = doc.TransactionManager.StartTransaction()) { var pt = Globs.GetLabelPoint(elFG); if (pt.HasValue) { var rblock = tr.GetObject(ssRB[rbInd], _AcDb.OpenMode.ForWrite) as _AcDb.BlockReference; var pos = rblock.GetCenter(); if (!pos.HasValue) { pos = rblock.Position; } _AcGe.Vector3d acVec3d = pos.Value.GetVectorTo(pt.Value); rblock.TransformBy(_AcGe.Matrix3d.Displacement(acVec3d)); ed.WriteMessage("\nCentroid is {0}", pt); } else { var poly = tr.GetObject(elFG, _AcDb.OpenMode.ForRead) as _AcDb.Polyline; string msg = string.Format(CultureInfo.CurrentCulture, "\nFläche {0}. Centroid liegt außerhalb.", poly.Handle.ToString()); ed.WriteMessage(msg); log.Warn(msg); } tr.Commit(); } } } //if (_Raumbloecke.Count > 0) //{ // List<object> insPoints = new List<object>(); // for (int i = 0; i < _Raumbloecke.Count; i++) // { // _AcIntCom.AcadBlockReference rbBlock = (_AcIntCom.AcadBlockReference)Globs.ObjectIdToAcadEntity(_Raumbloecke[i], tm); // insPoints.Add(rbBlock.InsertionPoint); // } // _AcCm.Color col = _AcCm.Color.FromRgb((byte)0, (byte)255, (byte)0); // Plan2Ext.Globs.InsertFehlerLines(insPoints, _LooseBlockLayer, 50, Math.PI * 1.25, col); //} if (fehlerKeinRb > 0 || fehlerMehrRb > 0 || fehlerWertFalsch > 0 || _Raumbloecke.Count > 0) { string msg = string.Format(CultureInfo.CurrentCulture, "Räume ohne Raumblock: {0}\nRäume mit mehr als einem Raumblock: {1}\nRäume mit falschem Wert in Raumblock: {2}\nRaumblöcke ohne entsprechende Flächengrenzen: {3}", fehlerKeinRb, fehlerMehrRb, fehlerWertFalsch, _Raumbloecke.Count); log.Debug(msg); _AcAp.Application.ShowAlertDialog(msg); } //If wucs = 0 Then // ThisDrawing.SendCommand "(command ""_.UCS"" ""_P"") " //End If myT.Commit(); } finally { myT.Dispose(); } } finally { doc.Editor.CurrentUserCoordinateSystem = ucs; } }