.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to insert multiple block from file to one drawing at once?

2 REPLIES 2
Reply
Message 1 of 3
thenndral
1072 Views, 2 Replies

How to insert multiple block from file to one drawing at once?

Hello,

I'm using AutoCAD 2014 with C#.
How to insert multiple block from file to one drawing at once?

Explaination:
BlockFile Name:
1. C:\aa.dwg
2. C:\bb.dwg
3. C:\cc.dwg
4. C:\dd.dwg
5. C:\ee.dwg

Insert Drawing file:
1. Stu_0001.dwg

I need to open drawing Stu_0001.dwg in memory and insert the above 5 block drawing file at once.
I try to achieve my requirements using Jig.
http://through-the-interface.typepad.com/through_the_interface/2007/05/using_a_jig_fro.html

Please give me more information/suggestion to acheive my goal.

Thanks in advance.
thenndral

2 REPLIES 2
Message 2 of 3
Littlerubarb
in reply to: thenndral

You are on the right path, here's a sample in vb that inserts a block into a drawing in memory...

 

'path to blocks dwg

Dim insertblock As String = ""

'path to drawing to load in memory

Dim filepath As String

 

Try
For Each Me.filepath In ListBox1.Items

'Your drawing in memory

Dim fi As New FileInfo(filepath)

Dim SelectedDWG As String = DWGNMComboBox.SelectedItem.ToString

CreateBlock()

Catch Ex As System.Exception
System.Windows.Forms.MessageBox.Show(Ex.ToString)

End Try

 

Public Sub CreateBlock()
Dim db As New Database(False, True)
db.ReadDwgFile(filepath, System.IO.FileShare.ReadWrite, False, "")
Dim trans As Transaction
trans = db.TransactionManager.StartTransaction
Try
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord
btr = trans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
Dim id As ObjectId
If bt.Has(blckname) Then
Dim btrSrc As BlockTableRecord
btrsrc=trans.GetObject(bt.Item(blckname), OpenMode.ForWrite)
btrSrc.Erase()
Else
End If

Dim dbDwg As New Database(False, True)
dbDwg.ReadDwgFile(insertblock, IO.FileShare.Read, True, "")
id = db.Insert(blckname, dbDwg, False)
dbDwg.Dispose()
'Modify insertion settings
Dim ptInsert As New Point3d(IPX, IPY, IPz)
Dim blkRef As New BlockReference(ptInsert, id)
blkRef.ScaleFactors = New Scale3d(blkscale)
btr.AppendEntity(blkRef)
trans.AddNewlyCreatedDBObject(blkRef, True)
trans.Commit()
Catch
MsgBox(Err.Description + "ouch")
Finally
trans.Dispose()
End Try
db.SaveAs(filepath, DwgVersion.Current)
End Sub

Message 3 of 3
thenndral
in reply to: Littlerubarb

Hi Littlerubarb,

 

Thank you for your code.

I will check this code in c#.

 

Thanks again,

thenndral

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost