本文整理汇总了C#中Database.ReadDwgFile方法的典型用法代码示例。如果您正苦于以下问题:C# Database.ReadDwgFile方法的具体用法?C# Database.ReadDwgFile怎么用?C# Database.ReadDwgFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database.ReadDwgFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlotFiles
private void PlotFiles()
{
DsdEntryCollection dsdCol = new DsdEntryCollection();
int indexfile = 0;
title = $"Печать {filesDwg.Length} файлов dwg...";
foreach (var fileDwg in filesDwg)
{
if (HostApplicationServices.Current.UserBreak())
throw new Exception(General.CanceledByUser);
indexfile++;
using (var dbTemp = new Database(false, true))
{
dbTemp.ReadDwgFile(fileDwg, FileOpenMode.OpenForReadAndAllShare, false, "");
dbTemp.CloseInput(true);
using (var t = dbTemp.TransactionManager.StartTransaction())
{
DBDictionary layoutDict = (DBDictionary)dbTemp.LayoutDictionaryId.GetObject(OpenMode.ForRead);
List<Layout> layouts = new List<Layout>();
foreach (DBDictionaryEntry entry in layoutDict)
{
if (entry.Key != "Model")
{
if (!entry.Value.IsErased)
{
var layout = entry.Value.GetObject(OpenMode.ForRead) as Layout;
layouts.Add(layout);
}
}
}
// Фильтр листов
if (Options.FilterState)
{
layouts = FilterLayouts(layouts, Options);
}
List<Tuple<Layout, DsdEntry>> layoutsDsd = new List<Tuple<Layout, DsdEntry>>();
foreach (var layout in layouts)
{
DsdEntry dsdEntry = new DsdEntry();
dsdEntry.Layout = layout.LayoutName;
dsdEntry.DwgName = fileDwg;
//dsdEntry.Nps = "Setup1";
dsdEntry.NpsSourceDwg = fileDwg;
dsdEntry.Title = indexfile + "-" + layout.LayoutName;
layoutsDsd.Add(new Tuple<Layout, DsdEntry>(layout, dsdEntry));
//dsdCol.Add(dsdEntry);
}
if (Options.SortTabOrName)
{
layoutsDsd.Sort((l1, l2) => l1.Item1.TabOrder.CompareTo(l2.Item1.TabOrder));
}
else
{
layoutsDsd.Sort((l1, l2) => l1.Item1.LayoutName.CompareTo(l2.Item1.LayoutName));
}
layoutsDsd.ForEach(l => dsdCol.Add(l.Item2));
t.Commit();
}
}
}
PublisherDSD(dsdCol);
}
示例2: copyFlat
private static void copyFlat(string fileFlat, ObjectId idBt)
{
using (var dbFlat = new Database(false, true))
{
dbFlat.ReadDwgFile(fileFlat, FileOpenMode.OpenForReadAndAllShare, false, "");
dbFlat.CloseInput(true);
using (var bt = dbFlat.BlockTableId.Open( OpenMode.ForRead) as BlockTable)
{
foreach (var idBtr in bt)
{
using (var btr = idBtr.Open( OpenMode.ForRead) as BlockTableRecord)
{
if (Revit.Apartment.IsBlockNameApartment(btr.Name))
{
using (var map = new IdMapping())
{
ObjectIdCollection ids = new ObjectIdCollection(new[] { idBtr });
dbFlat.WblockCloneObjects(ids, idBt, map, DuplicateRecordCloning.Ignore, false);
}
return;
}
}
}
}
}
}
示例3: LoadVisuals
public static List<IVisualBlock> LoadVisuals(string file, Predicate<string> filter)
{
var visualBlocks = new List<IVisualBlock>();
using (var dbTemp = new Database(false, true))
{
dbTemp.ReadDwgFile(file, FileOpenMode.OpenForReadAndReadShare, true, "");
using (var t = dbTemp.TransactionManager.StartTransaction())
{
var bt = dbTemp.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
foreach (var idBtr in bt)
{
var btr = idBtr.GetObject(OpenMode.ForRead) as BlockTableRecord;
if (filter(btr.Name))
{
var visualBl = new VisualBlock(btr);
visualBl.File = file;
visualBlocks.Add(visualBl);
}
}
t.Commit();
}
var alpha = Comparers.AlphanumComparator.New;
visualBlocks.Sort((v1, v2) => alpha.Compare(v1.Name, v2.Name));
}
return visualBlocks;
}
示例4: CloseAndDelete
public void CloseAndDelete(List<PanelAKR> panelsToDelete)
{
string file = dbLib.Filename;
try
{
dbLib.Dispose();
}
catch { }
File.Delete(file);
// Удаление блоков
if (panelsToDelete != null && panelsToDelete.Count > 0)
{
// Сделать копию библиотеки
PanelLibrarySaveService.BackUpLibPanelsFile();
using (ProgressMeter progress = new ProgressMeter())
{
progress.SetLimit(panelsToDelete.Count);
progress.Start($"Удаление {panelsToDelete.Count} панелей из библиотеки...");
using (var db = new Database(false, true))
{
db.ReadDwgFile(PanelLibrarySaveService.LibPanelsFilePath, FileShare.None, true, "");
db.CloseInput(true);
using (var t = db.TransactionManager.StartTransaction())
{
var bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
foreach (var item in panelsToDelete)
{
if (bt.Has(item.BlName))
{
var idPanelAkr = bt[item.BlName];
var dbo = idPanelAkr.GetObject(OpenMode.ForWrite);
try
{
dbo.Erase();
progress.MeterProgress();
}
catch { };
}
}
t.Commit();
}
db.SaveAs(PanelLibrarySaveService.LibPanelsFilePath, DwgVersion.Current);
}
Logger.Log.Error ($"Удалены панели АКР из библиотеки - {panelsToDelete.Count}шт.: {string.Join(", ",panelsToDelete)}");
progress.Stop();
}
}
}
示例5: get_image_of_file
public System.Drawing.Bitmap get_image_of_file(string filename)
{
//create a new database instance and load the dwg file into it.
Database dbb = new Database(false, true);
dbb.ReadDwgFile(filename, FileOpenMode.OpenForReadAndAllShare, false, "");
//grab the thumbnail bitmap and get rid of the white background
System.Drawing.Bitmap preview = dbb.ThumbnailBitmap;
preview.MakeTransparent(System.Drawing.Color.White);
return preview;
}
示例6: Edit
public void Edit()
{
var panelsFile = GetPanelsFile();
List<PanelAKR> panelsInLib;
dbLib = new Database(false, true);
dbLib.ReadDwgFile(panelsFile, FileShare.ReadWrite, true, "");
dbLib.CloseInput(true);
// список блоков АКР-Панелей в библиотеке (полные имена блоков).
panelsInLib = PanelAKR.GetAkrPanelLib(dbLib, true);
UI.PanelsAkrView panelsView = new UI.PanelsAkrView(panelsInLib, this);
UI.PanelsWindow panelsWindow = new UI.PanelsWindow(panelsView);
Application.ShowModelessWindow(panelsWindow);
}
示例7: CreateBtrPanelFromBase
public void CreateBtrPanelFromBase(int i, string[] marks)
{
// Тест создания определения блока панели по описанию в xml базе.
PanelBase panelBase;
string testFile = @"c:\temp\test\АКР\Base\Tests\CreateBlockPanelTest\TestCreatePanels.dwg";
//File.Copy(@"c:\Autodesk\AutoCAD\Pik\Settings\Template\АР\АР.dwt", testFile, true);
using (var db = new Database(false, true))
{
db.ReadDwgFile(testFile, FileOpenMode.OpenForReadAndAllShare, false, "");
db.CloseInput(true);
using (AcadLib.WorkingDatabaseSwitcher dbSwitcher = new AcadLib.WorkingDatabaseSwitcher(db))
{
baseService.ClearPanelsAkrFromDrawing(db);
baseService.InitToCreationPanels(db);
Point3d pt = Point3d.Origin;
List<ObjectId> idsBtrPanels = new List<ObjectId>();
// Создание определениц блоков панелей
foreach (var mark in marks)
{
Panel panelXml = baseService.GetPanelXml(mark);
panelBase = new PanelBase(panelXml, baseService);
panelBase.CreateBlock();
if (!panelBase.IdBtrPanel.IsNull)
{
idsBtrPanels.Add(panelBase.IdBtrPanel);
}
}
// Вставка вхождениц блоков панелей в модель
using (var t = db.TransactionManager.StartTransaction())
{
foreach (var idBtrPanel in idsBtrPanels)
{
var blRefPanel = new BlockReference(pt, idBtrPanel);
var ms = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
ms.AppendEntity(blRefPanel);
t.AddNewlyCreatedDBObject(blRefPanel, true);
pt = new Point3d(0, pt.Y + 10000, 0);
}
t.Commit();
}
}
db.SaveAs(testFile, DwgVersion.Current);
}
}
示例8: CreatePlotSettingsInfos
/// <summary>
/// Чтение именованных настроек печати из указанного файла
/// </summary>
/// <param name="templatePath">Путь к файлу с именованными настройками печати</param>
/// <returns>Коллекция PlotSettingsInfo</returns>
public static IEnumerable<PlotSettingsInfo> CreatePlotSettingsInfos(string templatePath)
{
Database db = null;
bool isTemplateOpened = false;
DocumentCollection docMan = Application.DocumentManager;
Document doc = docMan.Cast<Document>().FirstOrDefault(d => d.Name.Equals(templatePath, StringComparison.InvariantCulture));
if (doc != null)
{
db = doc.Database;
isTemplateOpened = true;
}
else
{
db = new Database(false, true);
db.ReadDwgFile(templatePath, System.IO.FileShare.Read, true, null);
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBDictionary psDict = tr.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary;
if (psDict != null)
{
foreach (DBDictionaryEntry entry in psDict)
{
ObjectId psId = entry.Value;
PlotSettings ps = tr.GetObject(psId, OpenMode.ForRead) as PlotSettings;
// Настройки печати для модели и настройки листов самих по себе
// нам не нужны
// только именованные настройки печати для листов
if (!ps.ModelType && !ps.PlotSettingsName.Contains("*"))
{
PlotSettings newPS = new PlotSettings(false);
newPS.CopyFrom(ps);
yield return new PlotSettingsInfo(newPS);
}
}
}
tr.Commit();
}
if (!isTemplateOpened)
db.Dispose();
}
示例9: TransferDimStyles
public void TransferDimStyles()
{
LayerManager lm = new LayerManager();
Database dbStandart = new Database(false, true);
dbStandart.ReadDwgFile(lm.PathToStadartFile, FileShare.Read, true, "");
List<DimStyleTableRecord> standartDimStyless = GetDimStyles(dbStandart);
ObjectIdCollection col = GetStandartDimStyles(standartDimStyless, true);
CopyEtalonStyle(col);
List<DimStyleTableRecord> docDimStyles = GetDimStyles(targetDB);
DimStyleTableRecord pikStyleActive = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK")).ToList()[0];
DimStyleTableRecord pikStyleDiametricDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$2")).ToList()[0];
DimStyleTableRecord pikStyleRadialDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$3")).ToList()[0];
DimStyleTableRecord pikStyleLineAngularDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$4")).ToList()[0];
DimStyleTableRecord[] masDimStyles = new DimStyleTableRecord[] { pikStyleActive, pikStyleDiametricDimension, pikStyleRadialDimension, pikStyleLineAngularDimension };
targetDB.Dimstyle = pikStyleActive.ObjectId;
Dictionary<string, ObjectId[]> dicDeleteDimStyles = GetDependentPrimitives(docDimStyles.Select(x => x.Name).ToArray());
Union(dicDeleteDimStyles, masDimStyles);
}
示例10: GetAllPlanesTest
public void GetAllPlanesTest()
{
List<FloorArchitect> floorsAr;
string testFile = @"c:\temp\test\АКР\Base\Tests\Тест-ПостроениеФасада.dwg";
using (var db = new Database(false, true))
{
db.ReadDwgFile(testFile, FileOpenMode.OpenForReadAndAllShare, false, "");
db.CloseInput(true);
using (AcadLib.WorkingDatabaseSwitcher dbSwitcher = new AcadLib.WorkingDatabaseSwitcher(db))
{
BaseService baseService = new BaseService();
baseService.InitToCreationPanels(db);
floorsAr = FloorArchitect.GetAllPlanes(db, baseService);
}
db.SaveAs(@"c:\temp\test\АКР\Base\Tests\Тест-ПостроениеФасада-WindowMarks.dwg", DwgVersion.Current);
}
Assert.AreEqual(floorsAr.Count, 2);
}
示例11: PlotDir
// Открытие и печать всех файлов в папке
public void PlotDir(string dir)
{
var dirInfo = new DirectoryInfo(dir);
var filesDwg = dirInfo.GetFiles("*.dwg", SearchOption.TopDirectoryOnly);
Database dbOrig = HostApplicationServices.WorkingDatabase;
foreach (var fileDwg in filesDwg)
{
// Открыть файл, сделать его текущим
using (var db = new Database(false, true))
{
db.ReadDwgFile(fileDwg.FullName, FileShare.ReadWrite, false, "");
db.CloseInput(true);
HostApplicationServices.WorkingDatabase = db;
db.CloseInput(true);
multiSheetPlot(db);
HostApplicationServices.WorkingDatabase = dbOrig;
}
}
}
示例12: Autograder
public static void Autograder()
{
const string systemVar_DwgCheck = "DWGCHECK";
Int16 dwgCheckPrevious = (Int16)Application.GetSystemVariable(systemVar_DwgCheck);
Application.SetSystemVariable(systemVar_DwgCheck, 2);
Document acDoc = Application.DocumentManager.MdiActiveDocument;
PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter entire path to the folder containing all the submissions");
pStrOpts.AllowSpaces = true;
PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts);
/*string[] folderpaths = Directory.GetDirectories(@"C:\Users\Vaibhav\Desktop\2D\2D Cad project\");*/
string[] folderpaths = Directory.GetDirectories(pStrRes.StringResult);
int i = 0;
foreach (string strFolderStudname in folderpaths)
{
i = i + 1;
//define dictionary for storing data.
Dictionary<string, string> dict1 = new Dictionary<string, string>();
dict1["auxinfodim"] = "";
dict1["blocksinlastlayout"] = "";
dict1["filename"] = i.ToString() + ": " + strFolderStudname;
//writestuff(strwrite,i.ToString()+": "+strFolderStudname,1);
Directory.SetCurrentDirectory(strFolderStudname + "/Submission attachment(s)/");
string[] filepaths = Directory.GetFiles(Directory.GetCurrentDirectory());
bool checkfilepass = false;
bool checkfilepdf = false;
bool checkfilepdfmulti = false;
int checkblockexistance = 0;
foreach (string strFileName in filepaths)
{
string newStr = strFileName.Substring(strFileName.Length - 3, 3);
if (newStr.Equals("dwg"))
{
/*Application.DocumentManager.Open(strFileName,false); //the boolean is for read only
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;*/
Database acCurDb = new Database(false, true);
acCurDb.ReadDwgFile(strFileName, FileOpenMode.OpenForReadAndAllShare, false, null);
acCurDb.CloseInput(true);
checkfilepass = true;
Layout taborderlayout = null;
int vp2 = 0;
string[] Layerlist = { };
using (Transaction acTrans2 = acCurDb.TransactionManager.StartTransaction())
{
DBDictionary lays = acTrans2.GetObject(acCurDb.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
LayoutManager Lm = LayoutManager.Current;
string currentLayout = Lm.CurrentLayout;
int layoutnum = 0;
string slayouts = "NA";
int tabordercheck = 0;
int tabviewports = 0;
bool tabcheck = false;
Viewport taborderviewport=null;
Viewport tempviewport = null;
Layout firsttaborderlayout=null;
Viewport firsttaporderviewport=null;
int firsttabviewports = 0;
foreach (DBDictionaryEntry de in lays)
{
layoutnum += 1;
Layout layout = de.Value.GetObject(OpenMode.ForRead) as Layout;
string layoutName = layout.LayoutName;
if (layoutName != "Model")
{
if (slayouts.Equals("NA"))
{
slayouts = layoutName;
}
else
{
slayouts = layoutName + " , " + slayouts;
}
ObjectIdCollection vpIdCol = layout.GetViewports();
if (tabordercheck < layout.TabOrder)
{
tabordercheck = layout.TabOrder;
taborderlayout = layout;
tabcheck = true;
}
else
{
tabcheck = false;
}
int nviewports = -1;
foreach (ObjectId vpId in vpIdCol)
{
Viewport vp = vpId.GetObject(OpenMode.ForRead) as Viewport;
nviewports += 1;
tempviewport = vp;
if (tabcheck == true)
{
tabviewports = nviewports;
}
if (layout.TabOrder == 2)
{
firsttaborderlayout = layout;
firsttaporderviewport = vp;
firsttabviewports = nviewports;
//.........这里部分代码省略.........
示例13: TransferLayer
public bool TransferLayer(Dictionary<string, string> dicLayers)
{
Document thisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = thisDrawing.Database;
LayerTableRecord stdLayer = null;
var stdDatabase = new Database(false, true);
stdDatabase.ReadDwgFile(PathToStadartFile, FileShare.Read, true, "");
List<LayerTableRecord> listStd = GetListLayers(stdDatabase, true);
using (DocumentLock docLock = thisDrawing.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable layerTable = tr.GetObject(db.LayerTableId, OpenMode.ForWrite, true) as LayerTable;
foreach (var dicLayer in dicLayers)
{
string activeLayerName = dicLayer.Key;
string stdLayerName = dicLayer.Value;
foreach (LayerTableRecord layer in listStd)
{
if (layer.Name != stdLayerName) continue;
stdLayer = layer;
}
var op = MainForm.dicLineTypes;
SetStandartToLayer(db, stdLayer, tr, activeLayerName, stdLayerName, layerTable);
}
tr.Commit();
}
}
return true;
}
示例14: OpenSourceDbForRead
private void OpenSourceDbForRead(string sourceFileName)
{
sourceDB = new Database(false, true);
sourceDB.ReadDwgFile(sourceFileName, FileShare.Read, true, "");
}
示例15: copyObjectFromTemplate
// Копирование стиля таблиц ПИК из файла шаблона
private static ObjectId copyObjectFromTemplate(Database db, Func<Database, string, ObjectId> getObjectId, string styleName, ObjectId ownerIdTable)
{
ObjectId idStyleDest = ObjectId.Null;
// файл шаблона
var userGroup = PikSettings.UserGroupsCombined.First();
string fileTemplate = Path.Combine(PikSettings.LocalSettingsFolder, "Template", userGroup,
userGroup + ".dwt");
if (File.Exists(fileTemplate))
{
using (Database dbTemplate = new Database(false, true))
{
dbTemplate.ReadDwgFile(fileTemplate, FileOpenMode.OpenForReadAndAllShare, false, "");
dbTemplate.CloseInput(true);
ObjectId idStyleInTemplate = getObjectId(dbTemplate, styleName);
if (!idStyleInTemplate.IsNull)
{
using (IdMapping map = new IdMapping())
{
using (var ids = (new ObjectIdCollection(new ObjectId[] { idStyleInTemplate })))
{
db.WblockCloneObjects(ids, ownerIdTable, map, DuplicateRecordCloning.Replace, false);
idStyleDest = map[idStyleInTemplate].Value;
}
}
}
}
}
return idStyleDest;
}