TheSwamp

Code Red => .NET => Topic started by: guohq on March 11, 2016, 05:58:49 AM

Title: How to save block as a single file?
Post by: guohq on March 11, 2016, 05:58:49 AM
 (command "-wblock" newBlockFilePath   blockName)

I can use lisp to save a block as a single file.

How can I achieve  this  use .net?
Title: Re: How to save block as a single file?
Post by: BillZndl on March 11, 2016, 07:44:44 AM
(command "-wblock" newBlockFilePath   blockName)

I can use lisp to save a block as a single file.

How can I achieve  this  use .net?

Look into  WBlockCloneObjects

Code - C#: [Select]
  1.  
  2. ////Clones all objectId's to a new drawing and saves it to your path & filename.
  3.  
  4.             Database newdata = new Database(true, true);
  5.             string SavPath = @"C:\Path\" + DwgName;
  6.            
  7.                 using (Transaction ntrans = newdata.TransactionManager.StartTransaction())
  8.                 {
  9.                     BlockTableRecord newbtr = (BlockTableRecord)ntrans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(newdata), OpenMode.ForRead);
  10.  
  11.                     IdMapping IDMap = new IdMapping();
  12.                    
  13.                     database.WblockCloneObjects(oidc, newbtr.ObjectId, IDMap, DuplicateRecordCloning.Replace, false);                                        
  14.                    
  15.                     newdata.SaveAs(SavPath, DwgVersion.Current);
  16.  
  17.                     ntrans.Commit();
  18.                 }            
  19.  

Title: Re: How to save block as a single file?
Post by: guohq on March 11, 2016, 11:24:51 AM
(command "-wblock" newBlockFilePath   blockName)

I can use lisp to save a block as a single file.

How can I achieve  this  use .net?

Look into  WBlockCloneObjects

Code - C#: [Select]
  1.  
  2. ////Clones all objectId's to a new drawing and saves it to your path & filename.
  3.  
  4.             Database newdata = new Database(true, true);
  5.             string SavPath = @"C:\Path\" + DwgName;
  6.            
  7.                 using (Transaction ntrans = newdata.TransactionManager.StartTransaction())
  8.                 {
  9.                     BlockTableRecord newbtr = (BlockTableRecord)ntrans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(newdata), OpenMode.ForRead);
  10.  
  11.                     IdMapping IDMap = new IdMapping();
  12.                    
  13.                     database.WblockCloneObjects(oidc, newbtr.ObjectId, IDMap, DuplicateRecordCloning.Replace, false);                                        
  14.                    
  15.                     newdata.SaveAs(SavPath, DwgVersion.Current);
  16.  
  17.                     ntrans.Commit();
  18.                 }            
  19.  
Thank you!
Title: Re: How to save block as a single file?
Post by: BillZndl on March 11, 2016, 12:08:15 PM
You are welcome!  :-)