本文整理汇总了C#中Transaction.AddNewlyCreatedDBObject方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.AddNewlyCreatedDBObject方法的具体用法?C# Transaction.AddNewlyCreatedDBObject怎么用?C# Transaction.AddNewlyCreatedDBObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.AddNewlyCreatedDBObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDescription
/// <summary>
/// Создание описания панели на листе шаблона
/// Должна быть запущена транзакция
/// </summary>
public void CreateDescription(Transaction t)
{
// Лист
var layoutId = LayoutManager.Current.GetLayoutId(Settings.Default.SheetTemplateLayoutNameForMarkAR);
if (layoutId.IsNull)
{
error("PanelDescription.CreateDescription() - layoutId.IsNull.");
return;
}
var layout = layoutId.GetObject(OpenMode.ForRead) as Layout;
using (var btrLayout = layout?.BlockTableRecordId.GetObject(OpenMode.ForWrite) as BlockTableRecord)
{
if (btrLayout == null)
{
error("PanelDescription.CreateDescription() - btrLayout == null");
return;
}
// Добавление мтекста
MText mtext = getMtext();
if (mtext != null)
{
btrLayout.AppendEntity(mtext);
t.AddNewlyCreatedDBObject(mtext, true);
}
// Таблица профилей для панелей с торцевыми плитками
Table tableProfile = getTableProfile(mtext);
if (tableProfile != null)
{
btrLayout.AppendEntity(tableProfile);
t.AddNewlyCreatedDBObject(tableProfile, true);
}
}
}
示例2: InsertBlock
public Handle InsertBlock(Transaction trans, string blockName, Point3d origin, double scale, double rotationDegrees, string layerName)
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
LayerTable lt = trans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
if (!bt.Has(blockName))
{
BlockDefinitionCreator bdc = new BlockDefinitionCreator();
bdc.CreateBlock(blockName);
}
if (!lt.Has(layerName))
{
throw new ArgumentException("Layer doesn't exists.");
}
ObjectId btObjectId = bt[blockName];
if (btObjectId != ObjectId.Null)
{
BlockReference blockRef = new BlockReference(origin, btObjectId);
blockRef.Rotation = rotationDegrees * Math.PI / 180;
blockRef.TransformBy(Matrix3d.Scaling(scale, origin));
blockRef.Layer = layerName;
BlockTableRecord currentSpaceId = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
currentSpaceId.AppendEntity(blockRef);
trans.AddNewlyCreatedDBObject(blockRef, true);
BlockTableRecord btr = trans.GetObject(btObjectId, OpenMode.ForRead) as BlockTableRecord;
if (btr.HasAttributeDefinitions)
{
foreach (ObjectId atId in btr)
{
Entity ent = trans.GetObject(atId, OpenMode.ForRead) as Entity;
if (ent is AttributeDefinition)
{
AttributeDefinition atd = ent as AttributeDefinition;
AttributeReference atr = new AttributeReference();
atr.SetAttributeFromBlock(atd, blockRef.BlockTransform);
blockRef.AttributeCollection.AppendAttribute(atr);
trans.AddNewlyCreatedDBObject(atr, true);
}
}
}
return blockRef.ObjectId.Handle;
}
else
{
return new Handle();
}
}
示例3: Create
public static DBObject Create(this Grevit.Types.DrawingPoint a, Transaction tr)
{
try
{
LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);
Point3d pp = a.point.ToPoint3d();
DBPoint ppp = new DBPoint(pp);
ppp.SetDatabaseDefaults(Command.Database);
if (a.TypeOrLayer != "") { if (lt.Has(a.TypeOrLayer)) ppp.LayerId = lt[a.TypeOrLayer]; }
BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
ms.AppendEntity(ppp);
tr.AddNewlyCreatedDBObject(ppp, true);
return ppp;
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
}
return null;
}
示例4: Create
public void Create(BlockTableRecord btrPanel, Transaction t)
{
Polyline plContour = new Polyline();
plContour.LayerId = panelBase.Service.Env.IdLayerContourPanel;
// Определение подрезок и пустот
defineUndercuts();
// Outsides - части сторон панели без плитки - заходит под торец другой угловой панели
addOutsides(btrPanel, t);
definePtsLeftSide();
definePtsTopSide();
definePtsRightSide();
definePtsBotSide();
int i = 0;
ptsLeftSide.ForEach(p => plContour.AddVertexAt(i++, p, 0, 0, 0));
ptsTopSide.ForEach(p => plContour.AddVertexAt(i++, p, 0, 0, 0));
ptsRightSide.ForEach(p => plContour.AddVertexAt(i++, p, 0, 0, 0));
ptsBotSide.ForEach(p => plContour.AddVertexAt(i++, p, 0, 0, 0));
plContour.Closed = true;
btrPanel.AppendEntity(plContour);
t.AddNewlyCreatedDBObject(plContour, true);
}
示例5: Create
public void Create(Point2d ptCell, BlockTableRecord cs, Transaction t)
{
var cellWidth = ColorBookHelper.CellWidth;
var cellHeight = ColorBookHelper.CellHeight;
var margin = ColorBookHelper.Margin;
var marginHalf = margin * 0.5;
Point3d ptText = new Point3d(ptCell.X + cellWidth * 0.5, ptCell.Y - ColorBookHelper.TextHeight-margin, 0);
Polyline pl = new Polyline(4);
pl.AddVertexAt(0, new Point2d(ptCell.X+margin, ptText.Y- marginHalf), 0, 0, 0);
pl.AddVertexAt(1, new Point2d(ptCell.X+cellWidth- margin, ptText.Y- marginHalf), 0, 0, 0);
pl.AddVertexAt(2, new Point2d(ptCell.X + cellWidth-margin, ptCell.Y-cellHeight+margin), 0, 0, 0);
pl.AddVertexAt(3, new Point2d(ptCell.X+margin, ptCell.Y - cellHeight+margin), 0, 0, 0);
pl.Closed = true;
pl.SetDatabaseDefaults();
pl.Color = Color;
cs.AppendEntity(pl);
t.AddNewlyCreatedDBObject(pl, true);
Hatch h = new Hatch();
h.SetDatabaseDefaults();
h.SetHatchPattern(HatchPatternType.PreDefined, "Solid");
h.Annotative = AnnotativeStates.False;
cs.AppendEntity(h);
t.AddNewlyCreatedDBObject(h, true);
h.Associative = true;
h.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection(new[] { pl.Id }));
h.Color = Color;
h.EvaluateHatch(true);
DBText text = new DBText();
text.SetDatabaseDefaults();
text.HorizontalMode = TextHorizontalMode.TextCenter;
text.Annotative = AnnotativeStates.False;
text.Height = ColorBookHelper.TextHeight;
text.AlignmentPoint = ptText;
text.AdjustAlignment(cs.Database);
text.TextStyleId = ColorBookHelper.IdTextStylePik;
text.TextString = Name;
cs.AppendEntity(text);
t.AddNewlyCreatedDBObject(text, true);
}
示例6: Create
public void Create(BlockTableRecord btr, Transaction t)
{
var table = GetTable();
table.Position = ptPlan;
table.TransformBy(Matrix3d.Scaling(100, table.Position));
btr.AppendEntity(table);
t.AddNewlyCreatedDBObject(table, true);
}
示例7: CreateIfDoesntExists
private void CreateIfDoesntExists(Transaction trans, string layerName, LayerType fx, bool isPlottable)
{
LayerTable lt = trans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
if (!lt.Has(layerName))
{
LayerTableRecord ltr = GetLayer(layerName, fx, isPlottable, trans);
lt.UpgradeOpen();
lt.Add(ltr);
trans.AddNewlyCreatedDBObject(ltr, true);
}
}
示例8: curvaAlineas
/**
* @brief Metodo que descompone una curva en un conjunto de segmentos de línea que aproximan o recubren la curva original.
*
* @param cur Entidad curva que debe ser linealizada.
* @param numSeg Número de líneas en las que tiene que ser partida la curva.
* @param acBlkTbl Tabla de bloques de AutoCAD para buscar nuevos objetos y añadir nuevos objetos generados.
* @param acBlkTblRec Tabla de registros de los bloques de AutoCAD para buscar nuevos objetos y añadir nuevos objetos generados.
* @param t Transaccion abierta para manipular la tabla de bloques de AutoCAD.
* @param LayerId Parámetro del tipo ObjectId que identifica la capa a la que tendrán que asociarse las nuevas líneas generadas por el proceso
* de descomposición de la curva.
* @param dwfg Parámetro del tipo dwgFile donde se almacenaran las nuevas líneas creadas a partir del proceso de descomposición de la curva.
*
* @return Devuelve una colección de entidades tipo linea bajo la clase DBObjectCollection.
**/
public static DBObjectCollection curvaAlineas(Curve cur, int numSeg, BlockTable acBlkTbl, BlockTableRecord acBlkTblRec,Transaction t, ObjectId LayerId, dwgFile dwfg)
{
DBObjectCollection ret = new DBObjectCollection();
// Collect points along our curve
Point3dCollection pts = new Point3dCollection();
// Split the curve's parameter space into
// equal parts
double startParam = cur.StartParam;
double segLen = (cur.EndParam - startParam) / numSeg;
// Loop along it, getting points each time
for (int i = 0; i < numSeg + 1; i++)
{
Point3d pt = cur.GetPointAtParameter(startParam + segLen * i);
pts.Add(pt);
}
if (pts != null && pts.Count > 0)
{
if (pts.Count == 1)
{
// Retornamos un punto.
}
else if (pts.Count >= 2)
{
// Retornamos una secuencia de lineas
for (int i = 0; i < pts.Count - 1; i++)
{
Line ln = new Line();
ln.StartPoint = pts[i];
ln.EndPoint = pts[i + 1];
ln.LayerId = LayerId;
acBlkTblRec.AppendEntity(ln);
t.AddNewlyCreatedDBObject(ln, true);
dwfg.objetosArtificiales.Add(ln.ObjectId);
ret.Add(ln);
}
}
}
return ret;
}
示例9: AddAttributes
/// <summary>
/// Добавление атрибутов к вставке блока
/// </summary>
public static void AddAttributes(BlockReference blRef, BlockTableRecord btrBl, Transaction t)
{
foreach (ObjectId idEnt in btrBl)
{
if (idEnt.ObjectClass.Name == "AcDbAttributeDefinition")
{
var atrDef = t.GetObject(idEnt, OpenMode.ForRead) as AttributeDefinition;
if (!atrDef.Constant)
{
using (var atrRef = new AttributeReference())
{
atrRef.SetAttributeFromBlock(atrDef, blRef.BlockTransform);
//atrRef.TextString = atrDef.TextString;
blRef.AttributeCollection.AppendAttribute(atrRef);
t.AddNewlyCreatedDBObject(atrRef, true);
}
}
}
}
}
示例10: CreateAssociativeHatch
/// <summary>
/// Создание ассоциативной штриховки по полилинии
/// Полилиния должна быть в базе чертежа
/// </summary>
public static Hatch CreateAssociativeHatch(Curve loop, BlockTableRecord cs, Transaction t,
string pattern = "SOLID", string layer = null, LineWeight lw = LineWeight.LineWeight015)
{
var h = new Hatch();
h.SetDatabaseDefaults();
if (layer != null)
{
Layers.LayerExt.CheckLayerState(layer);
h.Layer = layer;
}
h.LineWeight = lw;
h.Linetype = SymbolUtilityServices.LinetypeContinuousName;
h.SetHatchPattern(HatchPatternType.PreDefined, pattern);
cs.AppendEntity(h);
t.AddNewlyCreatedDBObject(h, true);
h.Associative = true;
h.HatchStyle = HatchStyle.Normal;
// добавление контура полилинии в гштриховку
var ids = new ObjectIdCollection();
ids.Add(loop.Id);
try
{
h.AppendLoop(HatchLoopTypes.Default, ids);
}
catch (Exception ex)
{
Logger.Log.Error(ex, $"CreateAssociativeHatch");
h.Erase();
return null;
}
h.EvaluateHatch(true);
var orders = cs.DrawOrderTableId.GetObject(OpenMode.ForWrite) as DrawOrderTable;
orders.MoveToBottom(new ObjectIdCollection(new[] { h.Id }));
return h;
}
示例11: CreateHatchesForConcentricCircles
/// <summary>
/// Generates and adds a series of <see cref="Hatch"/> objects to the supplied <see cref="BlockTableRecord"/>
/// </summary>
/// <returns>The selected color as a<see cref="Autodesk.AutoCAD.Colors.Color"/></returns>
private static void CreateHatchesForConcentricCircles(BlockTableRecord blockTableRecord, ObjectIdCollection objectIdCollection, Transaction transaction)
{
var rand = new Random();
var previousPattern = string.Empty;
for (var i = 0; i < objectIdCollection.Count - 1; i++)
{
var r = Convert.ToByte((i + 1)*rand.Next(0, 25));
var g = Convert.ToByte((i + 1)*rand.Next(0, 25));
var b = Convert.ToByte((i + 1)*rand.Next(0, 25));
using (var hatch = new Hatch())
{
blockTableRecord.AppendEntity(hatch);
transaction.AddNewlyCreatedDBObject(hatch, true);
var pattern = GetRandomHatchPatternName();
//ensure pattern isn't repeated by from previous hatch
// in production quality code I would move this behavior to avoid violating SRP/SoC
while (pattern.Equals(previousPattern, StringComparison.InvariantCultureIgnoreCase))
{
pattern = GetRandomHatchPatternName();
}
previousPattern = pattern;
hatch.SetHatchPattern(HatchPatternType.PreDefined, pattern);
hatch.Color = Color.FromRgb(r, g, b);
// Associative must be set after the hatch object is appended to the block table record and before AppendLoop
hatch.Associative = true;
// Take the current circle and the next to create a HatchLoop
hatch.AppendLoop(HatchLoopTypes.Outermost, new ObjectIdCollection {objectIdCollection[i]});
hatch.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection {objectIdCollection[i + 1]});
hatch.EvaluateHatch(true);
}
}
}
示例12: addCheek
private void addCheek(BlockTableRecord btrPanel, Transaction t)
{
if (IsCheekLeft || IsCheekRight)
{
int yStep = Settings.Default.TileHeight + Settings.Default.TileSeam;
double xTile = 0;
List<Point2d> ptsPlContourCheek = new List<Point2d>();
// Торец слева
if (IsCheekLeft)
{
xTile = -(600 + Settings.Default.TileLenght);
// Добавление точек контура в список
Point2d pt = new Point2d(xTile, 0);
ptsPlContourCheek.Add(pt);
PtsForBotDimCheek.Add(pt.X);
pt = new Point2d(pt.X + 277, 0);
PtsForBotDimCheek.Add(pt.X);
ptsPlContourCheek.Add(pt);
pt = new Point2d(pt.X + 12, 0);
PtsForBotDimCheek.Add(pt.X);
ptsPlContourCheek.Add(pt);
pt = new Point2d(pt.X, Height);
ptsPlContourCheek.Add(pt);
pt = new Point2d(pt.X-30, pt.Y);
ptsPlContourCheek.Add(pt);
pt = new Point2d(pt.X-20, pt.Y+20);
ptsPlContourCheek.Add(pt);
pt = new Point2d(xTile, pt.Y);
ptsPlContourCheek.Add(pt);
}
// Торец справа
else if (IsCheekRight)
{
xTile = Length + 600;
// Добавление точек контура в список
Point2d pt = new Point2d(xTile, 0);
ptsPlContourCheek.Add(pt);
PtsForBotDimCheek.Add(pt.X);
pt = new Point2d(pt.X + 12, 0);
PtsForBotDimCheek.Add(pt.X);
ptsPlContourCheek.Add(pt);
pt = new Point2d(pt.X + 277, 0);
PtsForBotDimCheek.Add(pt.X);
ptsPlContourCheek.Add(pt);
pt = new Point2d(pt.X, Height+20);
ptsPlContourCheek.Add(pt);
pt = new Point2d(pt.X - 240, pt.Y);
ptsPlContourCheek.Add(pt);
pt = new Point2d(pt.X - 20, pt.Y - 20);
ptsPlContourCheek.Add(pt);
pt = new Point2d(xTile, pt.Y);
ptsPlContourCheek.Add(pt);
}
// Заполнение торца плиткой
for (int y = 0; y < Height; y += yStep)
{
Point3d pt = new Point3d(xTile, y, 0);
addTile(btrPanel, t, pt);
}
// Полилиния контура торца
Polyline plCheekContour = new Polyline();
plCheekContour.LayerId = Service.Env.IdLayerContourPanel;
int i = 0;
ptsPlContourCheek.ForEach(p => plCheekContour.AddVertexAt(i++, p, 0, 0, 0));
plCheekContour.Closed = true;
btrPanel.AppendEntity(plCheekContour);
t.AddNewlyCreatedDBObject(plCheekContour, true);
}
}
示例13: addText
private static DBText addText(BlockTableRecord btr, Transaction t, Point3d pt, string value, double height,
TextHorizontalMode horMode = TextHorizontalMode.TextCenter)
{
// Подпись развертки - номер вида
DBText text = new DBText();
text.SetDatabaseDefaults();
text.Height = height;
text.TextStyleId = IdTextStylePik;
text.TextString = value;
if (horMode == TextHorizontalMode.TextLeft)
{
text.Position = pt;
}
else
{
text.HorizontalMode = horMode;
text.AlignmentPoint = pt;
text.AdjustAlignment(btr.Database);
}
btr.AppendEntity(text);
t.AddNewlyCreatedDBObject(text, true);
return text;
}
示例14: addTile
private void addTile(BlockTableRecord btrPanel, Transaction t, Point3d pt)
{
if (Service.Env.IdBtrTile.IsNull)
{
return;
}
BlockReference blRefTile = new BlockReference(pt, Service.Env.IdBtrTile);
blRefTile.Layer = "0";
blRefTile.ColorIndex = 256; // ByLayer
btrPanel.AppendEntity(blRefTile);
t.AddNewlyCreatedDBObject(blRefTile, true);
}
示例15: addWindows
private void addWindows(BlockTableRecord btrPanel, Transaction t)
{
// все окна и балеоны в панели
var windows = Panel.windows?.window?.Select(w => new { posi = w.posi, width = w.width, height = w.height });
var balconys = Panel.balconys?.balcony?.Select(b => new { posi = b.posi, width = b.width, height = b.height });
var apertures = balconys==null? windows: windows?.Union(balconys)?? balconys;
if (apertures != null)
{
foreach (var item in apertures)
{
// контур окон
Polyline plWindow = new Polyline();
plWindow.LayerId = Service.Env.IdLayerContourPanel;
Point2d ptMinWindow = new Point2d(item.posi.X, item.posi.Y);
plWindow.AddVertexAt(0, ptMinWindow, 0, 0, 0);
plWindow.AddVertexAt(0, new Point2d(ptMinWindow.X, ptMinWindow.Y + item.height), 0, 0, 0);
Point2d ptMaxWindow = new Point2d(ptMinWindow.X + item.width, ptMinWindow.Y + item.height);
plWindow.AddVertexAt(0, ptMaxWindow, 0, 0, 0);
plWindow.AddVertexAt(0, new Point2d(ptMinWindow.X + item.width, ptMinWindow.Y), 0, 0, 0);
plWindow.Closed = true;
btrPanel.AppendEntity(plWindow);
t.AddNewlyCreatedDBObject(plWindow, true);
// добавление точек для верхнего образмеривания.
PtsForTopDim.Add(ptMinWindow.X);
PtsForTopDim.Add(ptMaxWindow.X);
Openings.Add(new Extents3d(ptMinWindow.Convert3d(), ptMaxWindow.Convert3d()));
// Вставка окон
if (WindowsBaseCenters.Count > 0)
{
var xCenter = item.posi.X + item.width * 0.5;
var winMarkMin = WindowsBaseCenters.Where(w => Math.Abs(w.Key.X - xCenter) < 600);
if (winMarkMin.Count() > 0)
{
var winMark = winMarkMin.MinBy(g => (g.Key.X - xCenter));
if (string.IsNullOrWhiteSpace(winMark.Value))
{
continue;
}
// Точка вставки блока окна
Point3d ptWin = new Point3d(item.posi.X, item.posi.Y, 0);
// Вставка блока окна
if (!Service.Env.IdBtrWindow.IsNull)
{
BlockReference blRefWin = new BlockReference(ptWin, Service.Env.IdBtrWindow);
blRefWin.LayerId = Service.Env.IdLayerWindow;
btrPanel.AppendEntity(blRefWin);
t.AddNewlyCreatedDBObject(blRefWin, true);
var resSetDyn = BlockWindow.SetDynBlWinMark(blRefWin, winMark.Value);
if (!resSetDyn)
{
// Добавление текста марки окна
DBText dbTextWin = new DBText();
dbTextWin.Position = ptWin;
dbTextWin.LayerId = Service.Env.IdLayerWindow;
dbTextWin.TextString = winMark.Value;
dbTextWin.Height = 180;
btrPanel.AppendEntity(dbTextWin);
t.AddNewlyCreatedDBObject(dbTextWin, true);
}
}
#if Test
// Test
else
{
// Добавление текста марки окна
DBText dbTextWin = new DBText();
dbTextWin.Position = ptWin;
dbTextWin.LayerId = Service.Env.IdLayerWindow;
dbTextWin.TextString = winMark.Value;
dbTextWin.Height = 180;
btrPanel.AppendEntity(dbTextWin);
t.AddNewlyCreatedDBObject(dbTextWin, true);
}
#endif
}
}
// Сортировка окон слева-направо
Openings.Sort((w1, w2) => w1.MinPoint.X.CompareTo(w2.MinPoint.X));
}
}
}