Inserted block lose attribute

1 2    next >
Lagen
2/29/2020 8:21 PM

Hi Wout

I use this to insert a block.
This block have attribute text.
But when insert it's lose the attribute text.


Visual Basic Code:
If cadControl IsNot Nothing Then

            If Not cadControl.CheckIfCanStartNewInteraction(True) Then
                Return
            End If
            Dim from = CadReader.Read(FileName, True)
            Dim entity = from.Entities(0)
            Dim boundsCalculator As BoundsCalculator = New BoundsCalculator()
            boundsCalculator.GetBounds(from, entity)
            Dim block As DxfBlock = New DxfBlock(BlockName)
            block.BasePoint = CType(boundsCalculator.Bounds.Center, Vector3D)
            Dim cloneContext = New CloneContext(from, cadControl.Model, ReferenceResolutionType.CloneMissing)
            Dim entityClone = CType(entity.Clone(cloneContext), DxfEntity)
            cloneContext.ResolveReferences()


            Dim lager As DxfLayer = cadControl.Model.Layers("NOTE")
            entityClone.Layer = lager
            block.Entities.Add(entityClone)
            entityClone.Layer = lager

            Dim commands As CommandGroup = New CommandGroup()
            Dim insertionPoint As Point3D = cadControl.TransformationProvider.CompleteTransform.GetInverse().Transform(New Point3D(0.5R * cadControl.Width, 0.5R * cadControl.Height, 0))
            Dim ok As Boolean = cadControl.AddSelectAndMove(New DxfInsert(block, insertionPoint) With {
                .ScaleFactor = Vector3D.FromScaleFactor(1)
            }, commands, insertionPoint)

            If ok Then
                Dim n As Integer = cadControl.Model.Blocks.Count
                Dim command As Command = New Command(Function()
                                                         cadControl.Model.Blocks.Add(block)
                                                     End Function, Function()
                                                                       cadControl.Model.Blocks.RemoveAt(n)
                                                                   End Function)
                cadControl.CommandInvoker.[Do](command)
                commands.UndoStack.Push(command)
            End If
        End If

Lagen
2/29/2020 9:59 PM

I found out that entityClone has the attribute.

So I guess it's "cadControl.AddSelectAndMove" not insert the attribute.


Visual Basic Code:
For Each Att As DxfAttribute In entityClone.Attributes
                MsgBox(Att.TagString)
            Next

Wout
2/29/2020 10:57 PM

Attributes are part of the insert, you can't insert an insert without its attributes.

- Wout

Lagen
2/29/2020 11:03 PM

Hi Wout
Thanks for the replay.

The problem I have is that the attributes not get inserted.
I only get the graphic.

I have a Insert with 2 attributes.
When I insert this Insert it's lose this 2 attribute.

/Patrik

Wout
3/5/2020 4:42 PM

Hi Patrik,

You created a new insert, but didn't add any attributes to it. This is your code:

Visual Basic Code:
New DxfInsert(block, insertionPoint) With {
                .ScaleFactor = Vector3D.FromScaleFactor(1)
            }

If you want the insert to have attributes, you have to create them and add them to DxfInsert.Attributes. See the DxfAttribute documentation for an example.

Note that the block may have attribute definitions (DxfAttributeDefinition), but that does not mean that the insert will have associated attributes. If you want them, you have to create them.

- Wout

Lagen
3/5/2020 4:58 PM

I not sure I understand you correct.

I use this code to add the Insert to the block:

Visual Basic Code:
block.Entities.Add(entityClone)

"entityClone" have the attribute I want.

I see attribute in "entityClone" with this code:

Visual Basic Code:
For Each Att As DxfAttribute In entityClone.Attributes
                MsgBox(Att.TagString)
            Next

So you mean that I should find the attribute that are include in "entityClone" and add to the my new DxfInsert?

Wout
3/5/2020 5:09 PM

Sorry, I didn't understand that entityClone was a DxfInsert. I will need your drawing to reproduce the issue.

- Wout

Lagen
3/5/2020 5:15 PM

Thanks Wout

I have send the block to you in mail.


/Patrik

Wout
3/6/2020 2:46 PM

Hi Patrik,

I don’t see a problem. There’s one visible attribute, with the value “2”, it is cloned correctly, and it is also displayed. See screenshot.

- Wout

Lagen
3/6/2020 3:50 PM

Hi Wout

Thanks for the replay.
There are 2 attribute, one have value and the other missing value.


When insert the block it's show the value it's have when it was inserted. but the value are a dummy, it's will not change if you change the value.

a better way to see this is to save the model after you insert this block. when you open the model with AutoCAD the block missing the attributes.

/Patrik

1 2    next >