Insert Block works but problem with update field

Insert Block works but problem with update field

Anonymous
Not applicable
1,919 Views
6 Replies
Message 1 of 7

Insert Block works but problem with update field

Anonymous
Not applicable

I've got a block with multiple attributes. This is not a problem to redefine the blocks attributes.

Some of the attributes contains dynamic fields (blockplace holder x y z parameters)

 

When i insert a block with such atributes that includes the blockplaceholder dynamic fields i get

X: InsertionPoint => It is recognized as an Dynamic field but displays InsertionPoint. and does not update the value.

Regenerating the modelspace does not help

How can i update the fielddata from vb.net?

 

I hope this you understand my problem...

 

Part of the code I use (where i think the problem is)

For Each attid As ObjectId In refbtr
    attent = tr.GetObject(attid, OpenMode.ForRead)
    If TypeOf attent Is AttributeDefinition Then
        Dim attdef As AttributeDefinition = attent
        Dim attref As New AttributeReference()
        attref.SetAttributeFromBlock(attdef, myBlockRef.BlockTransform)
        Dim attrefid As ObjectId = myBlockRef.AttributeCollection.AppendAttribute(attref)
        tr.AddNewlyCreatedDBObject(attref, True)
    End If
Next

 

Regards

 

Peter

 

0 Likes
Accepted solutions (1)
1,920 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Maybe it is FIELDEVAL settings.

Take a look at FIELDEVAL system variable and see what the settings is. Set to 16 for update on regen.

 

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

I've already checked that one, (first thing i've thought) but it has no effect on the block attributes.

The UPDATEFIELD command doesn't affect it.

 

When I manual do a insert block, select the block from the drop down and place it next to the other the fields work as they are ment to be. So the defenition of the block is not wrong.

 

When I save the drawing and reopen it. The block inserted by the code still appears as InsertionPoint, the manual inserted block displays normal. They both have the exact same contents, the only difference is the way of placing the block.

 

So I think my code is not complete.

0 Likes
Message 4 of 7

Anonymous
Not applicable

It looks like you update field from the extension dictionary of the atttribute reference but I have not got anything working or this could be totally off.

 

Will see what I can do later with some more time.

0 Likes
Message 5 of 7

Anonymous
Not applicable

I've already searched on the swamp website with no luck so far. If I found the solution I will post it here.

0 Likes
Message 6 of 7

Anonymous
Not applicable
Accepted solution

See this thread has more info

http://www.theswamp.org/index.php?topic=38857.0

 

Here is some code from above link

 

    <CommandMethod("InsertBlockWithFieldAtts")> _
        Public Sub InsertBlockWithFieldAtts()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Using trx As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead)
                Dim modelBtr As BlockTableRecord = trx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                Dim blockBtr As BlockTableRecord = trx.GetObject(bt("C"), OpenMode.ForRead)
                Dim insertPoint As Point3d = ed.GetPoint("Select Insertion Point").Value
                Dim bref As New BlockReference(insertPoint, blockBtr.ObjectId)
                modelBtr.AppendEntity(bref)
                trx.AddNewlyCreatedDBObject(bref, True)

                For Each id As ObjectId In blockBtr
                    If id.ObjectClass.Name = "AcDbAttributeDefinition" Then
                        Dim attDef As AttributeDefinition = trx.GetObject(id, OpenMode.ForRead)
                        Dim attref As New AttributeReference()
                        attref.SetAttributeFromBlock(attDef, bref.BlockTransform)

                        bref.AttributeCollection.AppendAttribute(attref)
                        trx.AddNewlyCreatedDBObject(attref, True)

                        If attDef.Constant Then
                            Continue For
                        End If

                        Dim extDic As DBDictionary = trx.GetObject(attref.ExtensionDictionary, OpenMode.ForRead)
                        Dim fieldDic As DBDictionary = trx.GetObject(extDic.GetAt("ACAD_FIELD"), OpenMode.ForRead)
                        Dim fld As Field = trx.GetObject(fieldDic.GetAt("TEXT"), OpenMode.ForWrite)

                        Dim strId As String = bref.ObjectId.OldIdPtr.ToString()
                        Dim updteStr As String = "%<\_ObjId " & strId & ">%"
                        Dim fieldCode As String = fld.GetFieldCode(FieldCodeFlags.AddMarkers)
                        Dim newFieldCode As String = fieldCode.Replace("?BlockRefId", updteStr)
                        fld.SetFieldCode(newFieldCode)

                    End If
                Next
                trx.Commit()
            End Using
            ed.Regen()
        End Sub

 

Message 7 of 7

Anonymous
Not applicable

Thanks man! Problem solved!

0 Likes