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

Insert Block works but problem with update field

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
RPeter
1548 Views, 6 Replies

Insert Block works but problem with update field

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

 

6 REPLIES 6
Message 2 of 7
Jeffrey_H
in reply to: RPeter

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.

 

 

You can also find your answers @ TheSwamp
Message 3 of 7
RPeter
in reply to: Jeffrey_H

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.

Message 4 of 7
Jeffrey_H
in reply to: RPeter

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.

You can also find your answers @ TheSwamp
Message 5 of 7
RPeter
in reply to: Jeffrey_H

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

Message 6 of 7
Jeffrey_H
in reply to: RPeter

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

 

You can also find your answers @ TheSwamp
Message 7 of 7
RPeter
in reply to: Jeffrey_H

Thanks man! Problem solved!

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