Author Topic: How to save block as a single file?  (Read 2287 times)

0 Members and 1 Guest are viewing this topic.

guohq

  • Newt
  • Posts: 84
How to save block as a single file?
« 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?

BillZndl

  • Guest
Re: How to save block as a single file?
« Reply #1 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.  

« Last Edit: March 11, 2016, 08:00:36 AM by BillZndl »

guohq

  • Newt
  • Posts: 84
Re: How to save block as a single file?
« Reply #2 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!

BillZndl

  • Guest
Re: How to save block as a single file?
« Reply #3 on: March 11, 2016, 12:08:15 PM »
You are welcome!  :-)