See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Delete XData with a specified application name from a selected entity

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,133
    Login to Give a bone
    0

    Default Delete XData with a specified application name from a selected entity

    One thing that has always been problematic with xdata is you can't delete it from an entity (with ActiveX).

    Apparently there is a way with entmod (see below)

    We have always been limited to vla-setxdata and vla-getxdata.

    Although it is possible to delete xdata using .net

    Code:
    Imports Autodesk.AutoCAD
    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.EditorInput
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.ApplicationServices
    ''' <summary>
    ''' Functions to delete (dispose) XData from Entities
    ''' </summary>
    
    Public Class XdataDisposeClass1
        ''' <summary>
        ''' LISP Function to delete (dispose) of specific Xdata application information from an entity.
        ''' </summary>
        ''' <param name="rbfArguments"></param>
        ''' <returns> T for success - nil for failure </returns>
        ''' <remarks> LISP Syntax: (XdataDispose (entlast) "TEST") </remarks>
        <LispFunction("XdataDispose")> _
        Public Function XdataDelete(ByVal rbfArguments As ResultBuffer)
            Try
                Dim arrArguments As TypedValue() = rbfArguments.AsArray
                If arrArguments.Length = 2 And _
                    arrArguments(0).TypeCode = LispDataType.ObjectId And _
                    arrArguments(1).TypeCode = LispDataType.Text Then
                    If Not XdataDispose(arrArguments(0).Value, _
                                        arrArguments(1).Value.ToString.ToUpper) = Nothing Then
                        Return New TypedValue(LispDataType.T_atom, -1)
                    End If
                End If
            Catch exception As Exception
            End Try
            Return Nothing
    
        End Function
    
        ''' <summary>
        ''' Comand line function to delete (dispose) of specific xdata application information.
        ''' </summary>
        ''' <remarks></remarks>
        <CommandMethod("XdataDispose")> _
        Public Sub XdataDispose()
            Dim document As Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim editor As Editor = document.Editor
            Dim promptresult As PromptResult = editor.GetString("Enter XData Application Name")
            Dim strApplication As String = promptresult.StringResult.ToUpper
            Dim transaction As Transaction = document.TransactionManager.StartTransaction
            Try
                Dim promptEntityResult As PromptEntityResult = editor.GetEntity("Select Entity")
                If promptEntityResult IsNot Nothing Then
                    Dim entity As Entity = transaction.GetObject(promptEntityResult.ObjectId, OpenMode.ForRead)
                    XdataDispose(promptEntityResult.ObjectId, strApplication.ToUpper)
                    transaction.Commit()
                End If
            Catch exception As Exception
                transaction.Abort()
            End Try
            transaction.Dispose()
        End Sub
    
        ''' <summary>
        ''' General Function to Delete (Dispose) of a specific xdata application from an object
        ''' </summary>
        ''' <param name="oidItem"></param>
        ''' <param name="strApplication"></param>
        ''' <returns>True for Success - Nothing for Failure</returns>
        Public Function XdataDispose(ByVal oidItem As ObjectId, ByVal strApplication As String)
            Dim document As Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim transaction As Transaction = document.TransactionManager.StartTransaction
            Try
                Dim entity As Entity = transaction.GetObject(oidItem, OpenMode.ForRead)
                Dim rbfXdata As ResultBuffer = entity.GetXDataForApplication(strApplication)
                If rbfXdata IsNot Nothing Then
                    entity.UpgradeOpen()
                    entity.XData = New ResultBuffer(New TypedValue(1001, strApplication))
                    rbfXdata.Dispose()
                    transaction.Commit()
                    Return True
                End If
            Catch exception As Exception
                transaction.Abort()
            End Try
            Return Nothing
        End Function
    End Class
    Last edited by peter; 2014-02-17 at 06:06 PM.
    AutomateCAD

Similar Threads

  1. Lisp file to delete All Xdata from selected entities regardless app name
    By diaa.caliph423218 in forum Bridging the Gap: LISP -> .NET -> LISP
    Replies: 1
    Last Post: 2015-09-29, 08:33 PM
  2. command reactor selected entity
    By Serhan_BAKIR in forum AutoLISP
    Replies: 3
    Last Post: 2012-01-13, 01:10 PM
  3. Replies: 3
    Last Post: 2011-02-09, 04:29 PM
  4. Write XData to an entity
    By avinash00002002 in forum AutoLISP
    Replies: 1
    Last Post: 2007-04-29, 01:31 PM
  5. How can I write a Xdata to a new fresh entity
    By avinash00002002 in forum AutoLISP
    Replies: 1
    Last Post: 2007-04-13, 03:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •