.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Insert Block - Workflow?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Am I along the correct workflow path here?
I want to insert a drawing as a block into my current drawing.
Before I start writing code I want to make sure I understand the steps.
Open Transaction
Wblock Drawing to Temp Database
Now have my New BlockTableRecord Object
Copy BlockTableRecord to ActiveDwg.Database
Create New BlockReference
Add attributes
Set Scale Properties
Set Insertion Point
Set Rotation
Append BlockReference to Database
Commit Transaction
Am I missing any of the steps?
Is this how I would imidate the old VBA modelspace.insertblock(myPoint, "C:\path\path\path\block.dwg",1,1,1,0)
Solved! Go to Solution.
Re: Insert Block - Workflow?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Insert Block - Workflow?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Yes!
I think that will work.
AutoCAD help says:
This function mimics the AutoCAD INSERT command. First a new block table record is created in the database executing this function. This new block table record is given the name pointed to by blockName. Then, all the Model Space entities in the database pointed to by dataBase are copied into the new block table record.
Thank you.
Re: Insert Block - Workflow?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Here's some code for people after me.
Public Shared Sub InsertInstrumentBlock()
Dim gstrc_InstrumentBubbleBlock_FilePath As String = "C:\myblock.dwg"
Dim BlockName As String = "Field Instrument"
Dim myDwg As Document = Application.DocumentManager.MdiActiveDocument
Using myTrans As Transaction = myDwg.TransactionManager.StartTransaction
'<<Get Block From Drawing>>
'Read Block Drawing's Database
Dim BlkDwgDB As New Database(False, False)
BlkDwgDB.ReadDwgFile(gstrc_InstrumentBubbleBlock_F ilePath, System.IO.FileShare.Read, True, "")
'Insert Block, Get ObjectID
Dim id As ObjectId = mydwg.Database.Insert(BlockName, BlkDwgDB, False)
'<<Insert BlockDefinition Into Specific Place on ModelSpace/PaperSpace>>
'Open the database for Write
Dim myBT As BlockTable = myDwg.Database.BlockTableId.GetObject(OpenMode.For Read)
Dim myModelSpace As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMo de.ForWrite)
'Block Table Record (Block Definitions)
Dim myBlockDef As BlockTableRecord = id.GetObject(OpenMode.ForWrite)
Dim InsPt As New Point3d(0,0,0)
'Block References (Insertions of Blocks into Drawing Space)
Dim myBlockRef As New DatabaseServices.BlockReference(InsPt, myBT(BlockName))
myBlockRef.ScaleFactors = New Geometry.Scale3d(1, 1, 1)
myModelSpace.AppendEntity(myBlockRef)
myTrans.AddNewlyCreatedDBObject(myBlockRef, True)
'Append Attribute References to the BlockReference
Dim myAttColl As DatabaseServices.AttributeCollection
Dim myEntID As ObjectId
Dim myEnt As DatabaseServices.Entity
myAttColl = myBlockRef.AttributeCollection
For Each myEntID In myBlockDef
myEnt = myEntID.GetObject(OpenMode.ForWrite)
If TypeOf myEnt Is DatabaseServices.AttributeDefinition Then
Dim myAttDef As DatabaseServices.AttributeDefinition = _
CType(myEnt, AttributeDefinition)
Dim myAttRef As New DatabaseServices.AttributeReference
myAttRef.SetAttributeFromBlock(myAttDef, myBlockRef.BlockTransform)
myAttColl.AppendAttribute(myAttRef)
myTrans.AddNewlyCreatedDBObject(myAttRef, True)
End If
Next
'Commit the Transaction
myTrans.Commit()
End Using
End Sub
Re: Insert Block - Workflow?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Insert Block - Workflow?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Constant Attributes?
What's that? Can you tell me more please.
Re: Insert Block - Workflow?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
VB_Autocad_guy wrote:
Constant Attributes?
What's that? Can you tell me more please.
If AttributeDefinition.Constant = True then you have not add this attribute to attribute collection.
More detailes about constant attribute definition: http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%2020




