Insert block with parameters and attributes

Insert block with parameters and attributes

Anonymous
Not applicable
2,261 Views
1 Reply
Message 1 of 2

Insert block with parameters and attributes

Anonymous
Not applicable

Hi everyone

I am looking for a long time in a solution to inserting block using vb.net. I need to insert a block with parameters and attributes. My dynamic block has three parameters and two attributes, but I only can insert the block and send the parameters using vb.net. How can I send the attributes to the block if the block is dynamic?.

The initial code to insert the block:

 

Dim acdoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim accurdb As Database = acdoc.Database
Using acdoc.LockDocument()
Using acTrans As Transaction = accurdb.TransactionManager.StartTransaction()
' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(accurdb.BlockTableId, OpenMode.ForRead)
Dim blkRecId As ObjectId = ObjectId.Null
blkRecId = acBlkTbl(nombrebloque)

' Insert the block into the current space
If blkRecId <> ObjectId.Null Then
Using acBlkRef As New BlockReference(New Point3d(0, 0, 0), blkRecId)

Dim acCurSpaceBlkTblRec As BlockTableRecord
acCurSpaceBlkTblRec = acTrans.GetObject(accurdb.CurrentSpaceId, OpenMode.ForWrite)
acCurSpaceBlkTblRec.AppendEntity(acBlkRef)

'**********PROPIEDADES*********
Dim pc As DynamicBlockReferencePropertyCollection = acBlkRef.DynamicBlockReferencePropertyCollection
' MsgBox("añadido a tblrec")
acBlkRef.Layer = capa
acTrans.AddNewlyCreatedDBObject(acBlkRef, True)
For Each prop As DynamicBlockReferenceProperty In pc
If prop.PropertyName = "pkini_origen" Then
prop.Value = xiniorigen
End If
If prop.PropertyName = "pkini_destino" Then
prop.Value = xinidestino
End If

[...]

Thank you

Please, excuse my bad english...

 

0 Likes
2,262 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant

Hi,

 

You should have a look at this topic in the Managed .NET Developer's Guide.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes