Inserted block lose attribute

< previous    1 2
Wout
3/6/2020 3:57 PM

Hi Patrik,

I'm totally lost here. If you can create a small console application to reproduce the problem I can have a look at it.

- Wout

Lagen
3/6/2020 4:08 PM

Thanks Wout

I have send you a model with the block I have inserted.

/Patrik

Wout
3/6/2020 4:27 PM

Hi Patrik,

I had a look, but the attributes are not missing. See screenshot. Here's how you can see them:

  • Open file in AutoCAD.
  • Click on the insert. Note that the top level insert has no attributes, as you created this yourself without attributes.
  • Click on your right mouse button and choose "Block editor".
  • Click on the insert that's inside the block. It is the cloned insert, different from the one mentioned above. This insert has the cloned attributes, not the insert above. This is probably where you got confused.
  • Right click, and choose "Edit attribute". You will now see all attributes in the cloned insert, as shown in the screenshot.
So summarizing: there are 2 inserts (1 top level, and 1 nested inside the block), and I think you are confused about which insert has the attributes.

Edit: in this case, you should probably decide if you really need to wrap the cloned insert in another block + insert. I don't see how this is useful.

- Wout

Lagen
3/6/2020 5:05 PM

I understand now.
I use the "explode" and then I see the my block with the attribute.
I was not understanding that I create a new block with my original block inside.

I will try to not create a new block, only insert the original DWG. is that possible for me to do?
I only have one block inside the model.


Visual Basic Code:
 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

Lagen
3/6/2020 6:08 PM

Hi Wout I use this code to insert the Insert.
I save and that work great.

the problem are that the model get corrupt when open it next time.


Visual Basic Code:
Dim from = CadReader.Read(FileName, True)
            Dim entity As DxfInsert = from.Entities(0)
            Dim boundsCalculator As BoundsCalculator = New BoundsCalculator()
            boundsCalculator.GetBounds(from, entity)
            entity.InsertionPoint = CType(boundsCalculator.Bounds.Center, Vector3D)
            Dim commands As CommandGroup = New CommandGroup()
            Dim Ok As Boolean = cadControl.AddSelectAndMove(entity, commands, entity.InsertionPoint)

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

Wout
3/6/2020 6:57 PM

You didn't clone the insert. It's illegal to mix objects from different models. If you just use entityClone like your original code without the additional block/insert it should be ok.

- Wout

Lagen
3/7/2020 5:26 AM

Thanks Wout

Everything works perfectly now.

Just a thought.
In AutoCAD I recognize blocks but not Insert.
Is a block and an Insert the same?

/Patrik

Wout
3/7/2020 2:05 PM

Hi Patrik,

See the DxfInsert/DxfBlock documentation.

- Wout

Lagen
3/18/2020 9:40 PM

Hi Wout

Post in wrong topic

< previous    1 2