Xdata, BlockReference and hatch problem

Xdata, BlockReference and hatch problem

Gdiael
Enthusiast Enthusiast
469 Views
2 Replies
Message 1 of 3

Xdata, BlockReference and hatch problem

Gdiael
Enthusiast
Enthusiast

i have a custom command that inserts a BlockReference with Xdata associated, the app name used in the xdata is validated in the method:

 

Public Sub gdAddApp(ByVal AppName As String, Optional db As Database = Nothing)
            If IsNothing(db) Then
                db = HostApplicationServices.WorkingDatabase
            End If
            Using trans As Transaction = db.TransactionManager.StartTransaction()
                Dim appTbl As RegAppTable = trans.GetObject(db.RegAppTableId, OpenMode.ForRead)
                If Not appTbl.Has(AppName) Then
                    Dim appTblRec As New RegAppTableRecord
                    appTbl.UpgradeOpen()
                    appTblRec.Name = AppName
                    appTbl.Add(appTblRec)
                    trans.AddNewlyCreatedDBObject(appTblRec, True)
                End If
                trans.Commit()
            End Using
        End Sub

 

 

the xdata is setted in this method

 

 

    Friend Sub setXRec(ByVal br As BlockReference)
        Dim rb As New ResultBuffer()
        rb.Add(New TypedValue(DxfCode.ExtendedDataRegAppName, SpParede.appName)) '0
        rb.Add(New TypedValue(DxfCode.ExtendedDataAsciiString, Me.id)) '1
        rb.Add(New TypedValue(DxfCode.ExtendedDataAsciiString, Me.hatchName)) '2
        rb.Add(New TypedValue(DxfCode.ExtendedDataReal, Me.ptIni.X)) '3
        rb.Add(New TypedValue(DxfCode.ExtendedDataReal, Me.ptIni.Y)) '4
        rb.Add(New TypedValue(DxfCode.ExtendedDataReal, Me.ptFim.X)) '5
        rb.Add(New TypedValue(DxfCode.ExtendedDataReal, Me.ptFim.Y)) '6
        rb.Add(New TypedValue(DxfCode.ExtendedDataReal, Me.altura)) '7
        rb.Add(New TypedValue(DxfCode.ExtendedDataReal, Me.largura)) '8
        rb.Add(New TypedValue(DxfCode.ExtendedDataInteger16, If(Me.isDrawgin, 1, 0))) '9
        rb.Add(New TypedValue(DxfCode.ExtendedDataInteger16, If(Me.selectMe, 1, 0))) '10
        rb.Add(New TypedValue(DxfCode.ExtendedDataInteger16, If(Me.eixShow, 1, 0))) '11
        rb.Add(New TypedValue(DxfCode.ExtendedDataInteger16, If(Me.eixGripShow, 1, 0))) '12
        rb.Add(New TypedValue(DxfCode.ExtendedDataInteger16, If(Me.hatchShow, 1, 0))) '13
        rb.Add(New TypedValue(DxfCode.ExtendedDataReal, Me.hatchScale)) '14
        rb.Add(New TypedValue(DxfCode.ExtendedDataInteger16, Me.hatchColor)) '15
        br.XData = rb
    End Sub

 

 

All is working ok, i have overrules that add grips and stretch points to the block reference and everything is fine.

The problem is, when the document has one or more of this BlockReference on it, if the user calls a hatch command, when the variable HPQUICKPREVIEW is set to ON, AutoCAD crashes with fatal error, even if the blockReference is not involved direct with the hatch boundary.

 

Tested in 2019 and 2021, with all updates.

470 Views
2 Replies
Replies (2)
Message 2 of 3

deepak.a.s.nadig
Alumni
Alumni

Is this issue reproducible without overrules to add grips and stretch points? 

Can you please isolate the issue and provide minimal sample code to recreate it at our end ? This helps us to investigate.

0 Likes
Message 3 of 3

Gdiael
Enthusiast
Enthusiast

Thanks for the reply!
I was thinking that the problem was due to some error in my way of using xdata because the error happened even when the entity was not being used in the hatch boundary.
But as you suggested I disabled all overrules and it stopped happening.
I was able to isolate the error when my transform overrule is activated, more specifically in the Explode method.
What happens is that when the hatch command is called with HPQUICKPREVIEW in ON mode, it performs a virtual explosion of all visible entities.
Now I don't know what to do to deal with this situation, in my explosion method, what it does is put the entities that are created by the explosion and are in layer zero, in the same layer of the BlockReference that is being exploded.
I thought about taking the name of the command currently being executed and just proceed to change the layers if it is the "explode" command, but I don't know if there would be a more adequate solution.

 

 

Public Overrides Sub Explode(entity As Entity, entitySet As DBObjectCollection)
        MyBase.Explode(entity, entitySet)
        For Each dbo As DBObject In entitySet
            If TypeOf dbo Is Entity Then
                Dim ent As Entity = dbo
                If ent.Layer = "0" Then
                    ent.Layer = entity.Layer
                End If
            End If
        Next
    End Sub

 

 

0 Likes