Wenn ich versuche, einen Block mit Attributen in einem von der Seite geladenen DWG mit dem folgenden Code einzufügen, erhalte ich die falsche Datenbank in der Zeile. . Kann mich jemand in die richtige Richtung dessen zeigen, was ich falsch mache? Ich habe versucht, den BlockTableRecord aus der Blockreferenz zu erhalten, aber ohne Glück. < /P>
Danke im Voraus. < /P>
using (Database targetDb = new Database(false, true))
{
using (Transaction tr = targetDb.TransactionManager.StartTransaction())
{
targetDb.ReadDwgFile(file, FileOpenMode.OpenForReadAndAllShare, true, "");
targetDb.CloseInput(true);
bool bFixErrors = true;
bool becho = true;
ImportAlstomFiles.TransformDwg.InsertTbmBlock(targetDb);
targetDb.Audit(bFixErrors, becho);
targetDb.SaveAs(file, DwgVersion.Current);
tr.Commit();
}
}
public class TransformDwg
{
public static void InsertTbm(Database db)
{
string[] files = Directory.GetFiles(@"C:\ProgramData\Autodesk\ApplicationPlugins\SpNwDo.bundle\Contents\Block\Alstom\", "*.dwg");
foreach (string file in files)
{
string blockname = Path.GetFileNameWithoutExtension(file);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Database tmpDb = new Database(false, true);
tmpDb.ReadDwgFile(file, FileShare.Read, true, "");
db.Insert(blockname, tmpDb, true);
tr.Commit();
}
}
Point3d insPoint = new Point3d();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Open BlockTable and BlockTableRecord
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// Retrieve the inserted block definition
BlockTableRecord btrBlock = tr.GetObject(bt["Alstom_TBM_DATA01_S_N"], OpenMode.ForRead) as BlockTableRecord;
// Loop through the inserted block references and retrieve attribute values
foreach (ObjectId btrId in btr)
{
if (btrId.ObjectClass.DxfName == "INSERT")
{
BlockReference br = tr.GetObject(btrId, OpenMode.ForWrite) as BlockReference;
SymbolTableRecord str = tr.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead) as SymbolTableRecord;
using (BlockReference brBlock = new BlockReference(insPoint, btrBlock.ObjectId))
{
btr.UpgradeOpen();
// Append the new BlockReference to PaperSpace
btr.AppendEntity(brBlock);
tr.AddNewlyCreatedDBObject(brBlock, true);
// Loop through BlockTableRecord to create AttributeReferences
foreach (ObjectId btrBlockId in btrBlock)
{
AttributeDefinition ad = tr.GetObject(btrBlockId, OpenMode.ForWrite) as AttributeDefinition;
if (ad != null)
{
// Create a new AttributeReference in the correct database (db)
using (AttributeReference ar = new AttributeReference())
{
// Set the attribute values and transformation
ar.SetAttributeFromBlock(ad, brBlock.BlockTransform);
// Update the text for each attribute based on collected values
if (ar.Tag == "AT_DATA_ZONE_N")
ar.TextString = zone;
if (ar.Tag == "AT_DATA_STATION_N")
ar.TextString = station;
if (ar.Tag == "AT_DATA_BLOCKNUM_N")
ar.TextString = blocknum;
if (ar.Tag == "AT_DATA_DESC3_S_N")
ar.TextString = lijn1;
if (ar.Tag == "AT_DATA_DESC4_S_N")
ar.TextString = lijn2;
if (ar.Tag == "AT_DATA_DESC5_S_N")
ar.TextString = lijn3;
// Add the AttributeReference to the BlockReference's AttributeCollection
brBlock.AttributeCollection.AppendAttribute(ar);
// Ensure the attribute is added to the transaction
tr.AddNewlyCreatedDBObject(ar, true);
}
}
}
}
}
}
}
}
}
Wenn ich versuche, einen Block mit Attributen in einem von der Seite geladenen DWG mit dem folgenden Code einzufügen, erhalte ich die falsche Datenbank in der Zeile. . Kann mich jemand in die richtige Richtung dessen zeigen, was ich falsch mache? Ich habe versucht, den BlockTableRecord aus der Blockreferenz zu erhalten, aber ohne Glück. < /P> Danke im Voraus. < /P> [code]using (Database targetDb = new Database(false, true)) { using (Transaction tr = targetDb.TransactionManager.StartTransaction()) { targetDb.ReadDwgFile(file, FileOpenMode.OpenForReadAndAllShare, true, ""); targetDb.CloseInput(true);
foreach (string file in files) { string blockname = Path.GetFileNameWithoutExtension(file);
using (Transaction tr = db.TransactionManager.StartTransaction()) { Database tmpDb = new Database(false, true); tmpDb.ReadDwgFile(file, FileShare.Read, true, "");
db.Insert(blockname, tmpDb, true);
tr.Commit(); } }
Point3d insPoint = new Point3d();
using (Transaction tr = db.TransactionManager.StartTransaction()) { // Open BlockTable and BlockTableRecord BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// Retrieve the inserted block definition BlockTableRecord btrBlock = tr.GetObject(bt["Alstom_TBM_DATA01_S_N"], OpenMode.ForRead) as BlockTableRecord;
// Loop through the inserted block references and retrieve attribute values foreach (ObjectId btrId in btr) { if (btrId.ObjectClass.DxfName == "INSERT") { BlockReference br = tr.GetObject(btrId, OpenMode.ForWrite) as BlockReference; SymbolTableRecord str = tr.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead) as SymbolTableRecord;
using (BlockReference brBlock = new BlockReference(insPoint, btrBlock.ObjectId)) {
btr.UpgradeOpen();
// Append the new BlockReference to PaperSpace btr.AppendEntity(brBlock); tr.AddNewlyCreatedDBObject(brBlock, true);
// Loop through BlockTableRecord to create AttributeReferences foreach (ObjectId btrBlockId in btrBlock) { AttributeDefinition ad = tr.GetObject(btrBlockId, OpenMode.ForWrite) as AttributeDefinition;
if (ad != null) { // Create a new AttributeReference in the correct database (db) using (AttributeReference ar = new AttributeReference()) { // Set the attribute values and transformation ar.SetAttributeFromBlock(ad, brBlock.BlockTransform);
// Update the text for each attribute based on collected values if (ar.Tag == "AT_DATA_ZONE_N") ar.TextString = zone; if (ar.Tag == "AT_DATA_STATION_N") ar.TextString = station; if (ar.Tag == "AT_DATA_BLOCKNUM_N") ar.TextString = blocknum; if (ar.Tag == "AT_DATA_DESC3_S_N") ar.TextString = lijn1; if (ar.Tag == "AT_DATA_DESC4_S_N") ar.TextString = lijn2; if (ar.Tag == "AT_DATA_DESC5_S_N") ar.TextString = lijn3;
// Add the AttributeReference to the BlockReference's AttributeCollection brBlock.AttributeCollection.AppendAttribute(ar);
// Ensure the attribute is added to the transaction tr.AddNewlyCreatedDBObject(ar, true); } } } } } } } } } [/code]
Ich versuche, eine DWG -Datei zu exportieren, in der die Linien in Röhrchen oder Rohre mit einem Standardradius oder einem Standarddurchmesser umgewandelt werden. Die exportierte Datei (die x-, y-...
Ich habe einen Speicherblock mit einer Bytegröße von 10 erstellt und wollte eine Zufallszahl erstellen und in den Speicherblock einfügen, aber es werden mir immer nur Fehlermeldungen angezeigt,...
Ich habe eine DWG (ich kann das Dateiformat in SVG oder bei Bedarf an andere Formate ändern), die ich auf meiner Webseite anzeigen möchte. Nachdem diese Datei auf der Seite angezeigt wurde, möchte...
Ich habe eine DLL, die ein benutzerdefiniertes Avalonia-Steuerelement sowie dessen Standardstil und -ressourcen enthält.
Ich kann die DLL so dynamisch laden und das Steuerelement ohne Probleme...