.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: Repeatedly Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
>> The first one is that in the sample code there are references to "CreateLayer", "InsertBlockReference" and "RadiansToDegrees" which don't exist. Are these placeholders for code or are these documented fuctions in the API i can't seem to find? <<
Have a look at Reply #28
http://www.theswamp.org/index.php?topic=37686.msg4
OR
make the .NET forum current
and do a search for the keyword you want
Regards
class keyThumper<T> : Lazy<T>; another Swamper
I do not endorse the social media app links below![]()
Re: Repeatedly Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
When i try to put the code together from reply 28, i get the errors i posted above. When i try the compiled dll that was attached to the post and run BI_20, i get an eFilerError which halts everything. It's making me crazy that what i'm trying to do should be so simple yet is so annoyingly difficult. I've also gone through the .NET forums with no luck on this. I'll keep tacking at it and post any progress.
Cheers
Vince
Re: Repeatedly Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Maybe try one thing at a time.
1. Can you manually or through the UI insert a block into a drawing?(I guess you are inserting a drawing as block vs a block from another drawing)
2. Can you code just the part to insert another blockreference with attributes?
Re: Repeatedly Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hey Jeff,
1.) I can insert the block with no problems manually by going to "Insert"-->"Block" from the AutoCAD 2012 GUI.
2.) I'm not sure what you mean here....i need it to be able to insert the block reference with the original attributes and then do that "x' times over. I've tried pre-exploding/bursting the original block in the original dwg but to no avail.
Re: Repeatedly Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Try this:
Private Sub InsertAttibuteInBlockRef(ByVal blkRef As BlockReference, ByVal attributeTag As String, ByVal attributeText As String, ByVal tr As Transaction)
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
For Each attId As ObjectId In btr
Dim ent As Entity = DirectCast(tr.GetObject(attId, OpenMode.ForRead), Entity)
If TypeOf ent Is AttributeDefinition Then
Dim attDef As AttributeDefinition = DirectCast(ent, AttributeDefinition)
Dim attRef As New AttributeReference()
attRef.SetAttributeFromBlock(attDef, blkRef.BlockTransform)
If attRef.Tag = attributeTag Then
attRef.TextString = attributeText
Dim id As ObjectId = blkRef.AttributeCollection.AppendAttribute(attRef)
tr.AddNewlyCreatedDBObject(attRef, True)
Exit For
End If
End If
Next
End SubPublic Sub BlkInsert(ByVal basePath As String, ByVal blkName As String, ByVal px As Point3d, ByVal theta As Double, ByVal sx As Double, ByVal Layer As String, ByVal side As String, ByVal AttValList As ArrayList, ByVal AttTagList As ArrayList)
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database
acCurDb = HostApplicationServices.WorkingDatabase()
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
If acBlkTbl.Has(blkName) Then
Dim blkObjId = acBlkTbl(blkName)
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelS pace), OpenMode.ForWrite)
Dim blkRef As BlockReference = New BlockReference(px, blkObjId)
blkRef.Rotation = theta
blkRef.ScaleFactors = New Scale3d(sx, sx, 1)
blkRef.Layer = Layer
acBlkTblRec.AppendEntity(blkRef)
acTrans.AddNewlyCreatedDBObject(blkRef, True)
Dim dPropsCollection As DynamicBlockReferencePropertyCollection
dPropsCollection = blkRef.DynamicBlockReferencePropertyCollection
For Each dprop As DynamicBlockReferenceProperty In dPropsCollection
If dprop.PropertyName = "Visibility1" Then
dprop.Value = side
End If
Next
Try
Dim i As Integer = 0
For Each tag As String In AttTagList
InsertAttibuteInBlockRef(blkRef, tag, AttValList(i).ToString, acTrans)
i = i + 1
Next
acBlkTblRec.UpdateAnonymousBlocks()
blkRef.RecordGraphicsModified(True)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
Dim blkFile As String = basePath + "\\" + blkName + ".dwg"
Dim blkObjId As ObjectId
Dim dbDwg As New Database(False, True)
dbDwg.ReadDwgFile(blkFile, IO.FileShare.Read, True, "")
blkObjId = acCurDb.Insert(blkName, dbDwg, True)
dbDwg.Dispose()
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelS pace), OpenMode.ForWrite)
Dim blkRef As BlockReference = New BlockReference(px, blkObjId)
blkRef.Rotation = theta
blkRef.ScaleFactors = New Scale3d(sx, sx, 1)
blkRef.Layer = Layer
acBlkTblRec.AppendEntity(blkRef)
acTrans.AddNewlyCreatedDBObject(blkRef, True)
Dim dPropsCollection As DynamicBlockReferencePropertyCollection
dPropsCollection = blkRef.DynamicBlockReferencePropertyCollection
For Each dprop As DynamicBlockReferenceProperty In dPropsCollection
If dprop.PropertyName = "Visibility1" Then
dprop.Value = side
End If
Next
Dim i As Integer = 0
For Each tag As String In AttTagList
InsertAttibuteInBlockRef(blkRef, tag, AttValList(i).ToString, acTrans)
i = i + 1
Next
acBlkTblRec.UpdateAnonymousBlocks()
blkRef.RecordGraphicsModified(True)
End If
acTrans.Commit()
End Using
End Sub<CommandMethod("MBLKTEST")> _
Public Sub Blktest()
Dim TagList As New ArrayList
Dim ValList As New ArrayList
Dim side As String = "Top"
TagList.Add("TAG1")
TagList.Add("TAG2")
ValList.Add("VAL1")
ValList.Add("VAL2")
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Edit or
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim pr As PromptPointResult = ed.GetPoint("Pick a point:")
If pr.Status = PromptStatus.OK Then
Dim i As Integer = 0
Dim n As Integer = 10
Dim basePath As String = "C:\\MyBasePath"
Dim px As Point3d = pr.Value
For i = 0 To n
AlInsert(basePath, "MyBlockName", px, 0, 1, "0", side, ValList, TagList)
px = Polar(px, 3500, 0)
Next
End If
End SubPrivate Function Polar(ByVal bpoint As Point3d, ByVal r As Double, ByVal theta As Double) As Point3d
Dim px As New Point3d(bpoint.X + r * Math.Cos(theta), bpoint.Y + r * Math.Sin(theta), bpoint.Z)
Return px
End Function
You will need a dynamic block with 2 visibility states (the "side" parameter) and 2 attributes , or you can just get rid off that part of the code, and use a simple block with attributes.
Gaston Nunez
Re: Repeatedly Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks gasty1001,
I actually got it running with help from jeff, sorry for the delayed response. Thanks for the help though!


