Author Topic: Rename xref  (Read 1733 times)

0 Members and 1 Guest are viewing this topic.

krkec

  • Guest
Rename xref
« on: January 04, 2012, 02:17:42 AM »
Hi
I am trying to rename xref with this code:
Code: [Select]
'Contains the AutoCAD Type Library
Imports Autodesk.AutoCAD.Interop
'Contains the AutoCAD/ObjectDBX Type Library
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.LayerManager
Imports Autodesk.AutoCAD.Windows
Imports System.Windows.Forms

Public Class Form1
    Private xref1 As String
    Private fajlovi As Array
    Private mydio1 As System.IO.DirectoryInfo
    Private imexrefa As String

    Public ReadOnly Property ThisDrawing() As AcadDocument
        Get
            Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
        End Get
    End Property


    Function GetTopLevelBlocks(ByVal DatabaseIn As Database) As List(Of String)
        Dim myList As New List(Of String)
        Using myTrans As Transaction = DatabaseIn.TransactionManager.StartTransaction
            Dim myBT As BlockTable = DatabaseIn.BlockTableId.GetObject(OpenMode.ForRead)
            For Each myBTRid As ObjectId In myBT
                Dim myBTR As BlockTableRecord = myBTRid.GetObject(OpenMode.ForRead)
                If myBTR.IsAnonymous = False And myBTR.IsLayout = False And _
myBTR.IsFromExternalReference = False And _
myBTR.IsDependent = False Then
                    myList.Add(myBTR.Name)
                End If
            Next
        End Using
        Return myList
    End Function

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        xref1 = ComboBox1.SelectedItem.ToString
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles novixref.Click
        If OpenFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
            imexrefa = OpenFileDialog1.SafeFileName
            Label4.Text = "Odabreli ste:" & imexrefa
        End If
    End Sub

    Private Sub zamjeni_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zamjeni.Click
        For Each mojifajlovi As IO.FileInfo In mydio1.GetFiles("*.dwg")
            Using mdb As New Database(False, True)
                mdb.ReadDwgFile(mojifajlovi.FullName, _
                FileOpenMode.OpenForReadAndAllShare, True, "")
                Using mytrans As Transaction = mdb.TransactionManager.StartTransaction
                    Dim myBT As BlockTable = mdb.BlockTableId.GetObject(OpenMode.ForRead)
                    For Each myOID As ObjectId In myBT
                        Dim myBTR As BlockTableRecord = myOID.GetObject(OpenMode.ForWrite)
                        If myBTR.Name = xref1 Then
                            Dim putanja2 As String = ".\" & imexrefa
                            myBTR.PathName = putanja2
                        End If

                    Next
                    mytrans.Commit()
                End Using ' transa..
                mdb.SaveAs(mojifajlovi.Name.ToString, DwgVersion.Current)
            End Using
        Next
    End Sub

    Private Sub potrazi_fajlove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles potrazi_fajlove.Click
        Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog

        ' Descriptive text displayed above the tree view control in the dialog box
        MyFolderBrowser.Description = "Select the Folder"

        ' Sets the root folder where the browsing starts from
        'MyFolderBrowser.RootFolder = Environment.SpecialFolder.MyDocuments

        ' Do not show the button for new folder
        MyFolderBrowser.ShowNewFolderButton = False

        Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()

        If dlgResult = DialogResult.OK Then
            TextBox1.Text = MyFolderBrowser.SelectedPath
            Dim mydio As New IO.DirectoryInfo(MyFolderBrowser.SelectedPath)
            fajlovi = mydio.GetFiles
            For Each mojifajlovi As IO.FileInfo In mydio.GetFiles("*.dwg")
                Using mdb As New Database(False, True)
                    mdb.ReadDwgFile(mojifajlovi.FullName, _
                    FileOpenMode.OpenForReadAndAllShare, True, "")
                    Using mytrans As Transaction = mdb.TransactionManager.StartTransaction
                        Dim myBT As BlockTable = mdb.BlockTableId.GetObject(OpenMode.ForRead)
                        For Each myOID As ObjectId In myBT
                            Dim myBTR As BlockTableRecord = myOID.GetObject(OpenMode.ForRead)
                            If myBTR.IsFromExternalReference Then
                                If ComboBox1.Items.IndexOf(myBTR.Name) < 0 Then
                                    ComboBox1.Items.Add(myBTR.Name)
                                End If
                            End If

                        Next
                    End Using
                End Using
            Next

        End If

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Click
        Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog

        ' Descriptive text displayed above the tree view control in the dialog box
        MyFolderBrowser.Description = "Select the Folder"

        ' Sets the root folder where the browsing starts from
        'MyFolderBrowser.RootFolder = Environment.SpecialFolder.MyDocuments

        ' Do not show the button for new folder
        MyFolderBrowser.ShowNewFolderButton = False

        Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()

        If dlgResult = DialogResult.OK Then
            TextBox1.Text = MyFolderBrowser.SelectedPath
            Dim mydio As New IO.DirectoryInfo(MyFolderBrowser.SelectedPath)
            fajlovi = mydio.GetFiles
            For Each mojifajlovi As IO.FileInfo In mydio.GetFiles("*.dwg")
                Using mdb As New Database(False, True)
                    mdb.ReadDwgFile(mojifajlovi.FullName, _
                    FileOpenMode.OpenForReadAndAllShare, True, "")
                    Using mytrans As Transaction = mdb.TransactionManager.StartTransaction
                        Dim myBT As BlockTable = mdb.BlockTableId.GetObject(OpenMode.ForRead)
                        For Each myOID As ObjectId In myBT
                            Dim myBTR As BlockTableRecord = myOID.GetObject(OpenMode.ForRead)
                            If myBTR.IsFromExternalReference Then
                                If ComboBox1.Items.IndexOf(myBTR.Name) < 0 Then
                                    ComboBox1.Items.Add(myBTR.Name)
                                End If
                            End If

                        Next
                    End Using
                End Using
            Next

        End If

    End Sub

   
End Class
What am I doing wrong??????
Please help!!!!!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Rename xref
« Reply #1 on: January 04, 2012, 03:54:25 AM »

What is happening ... why do you think it is wrong ?

How do you start the application ?

Do you have any form code ?

It looks to me like a collection of code from various places ... and is incomplete
for example
the Function GetTopLevelBlocks(..) if not called from the code you provided.

and the Form Control events have nothing to react to.

Regards
kdub
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

krkec

  • Guest
Re: Rename xref
« Reply #2 on: January 04, 2012, 05:16:06 AM »
Thanks for replay 

function gettoplevelblocks is declared in provided code :
Code: [Select]
    Function GetTopLevelBlocks(ByVal DatabaseIn As Database) As List(Of String)
        Dim myList As New List(Of String)
        Using myTrans As Transaction = DatabaseIn.TransactionManager.StartTransaction
            Dim myBT As BlockTable = DatabaseIn.BlockTableId.GetObject(OpenMode.ForRead)
            For Each myBTRid As ObjectId In myBT
                Dim myBTR As BlockTableRecord = myBTRid.GetObject(OpenMode.ForRead)
                If myBTR.IsAnonymous = False And myBTR.IsLayout = False And _
myBTR.IsFromExternalReference = False And _
myBTR.IsDependent = False Then
                    myList.Add(myBTR.Name)
                End If
            Next
        End Using
        Return myList
    End Function

The code provided i previos post is from may form code, I also have class.vb wich start form and code for it is :
Code: [Select]
Public Class Class1
    Public ReadOnly Property ThisDrawing() As AcadDocument
        Get
            Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
        End Get
    End Property

    <CommandMethod("chxr")> _
Public Sub Blok()
        Dim myForm As New Form1
        Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(myForm)


    End Sub


Problem is that I always get Fatal error in autocad saying:

FATAL ERROR:  Unhandled Access Violation Reading 0x0000 Exception at 3e49e059h

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Rename xref
« Reply #3 on: January 04, 2012, 05:27:09 AM »
Thanks for replay 

function gettoplevelblocks is declared in provided code :
< .. >
Problem is that I always get Fatal error in autocad saying:

FATAL ERROR:  Unhandled Access Violation Reading 0x0000 Exception at 3e49e059h

Yes, the Function was included with your first post ... but it was not used.

You may have to attach your complete solution to determine the problem.

Have you tried debugging the code to see roughly where the error occurs.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

krkec

  • Guest
Re: Rename xref
« Reply #4 on: January 04, 2012, 05:38:15 AM »
Quote
Yes, the Function was included with your first post ... but it was not used.

yes that true i copy it accidentally from another project witch I work.

I attached my whole solution now.