.NET

Reply
Active Contributor
cokhitp
Posts: 31
Registered: ‎02-19-2011
Message 1 of 2 (154 Views)

Problem with VS2008 & autocad

154 Views, 1 Replies
11-26-2012 08:09 AM

Hello to everybody.

 

I have tried to write a code that can update attribute data in block of autocad file.

 

I found alot of example in this forum, but i dont know why my programe can not work.

 

My PC is winXP, VS2008, autocad2009.

 

1. This code is work ofcouse:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("hello")
    End Sub

 

2. But this one does not work:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("hello")
        Dim myBT As DatabaseServices.BlockTable    
    End Sub

 

As long as i insert in the code which relative to reference .dll; i got error: "The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

It means that problem is my PC sysem, sofware... not about the code.

 

Please help me to fix it, i spent two but still not found the reason.

 

 

Here the code i used:

 Function PopulateOIDCs(ByVal BlockName As String) _
As DatabaseServices.ObjectIdCollection
        Dim myBT As DatabaseServices.BlockTable
        Dim myBTR As DatabaseServices.BlockTableRecord
        Dim myBTRE As DatabaseServices.SymbolTableEnumerator
        Dim myDB As DatabaseServices.Database
        Dim myTransMan As DatabaseServices.TransactionManager
        Dim myTrans As DatabaseServices.Transaction
        Dim myOIDs As New DatabaseServices.ObjectIdCollection
        Dim myOIDs2 As DatabaseServices.ObjectIdCollection
        Dim I As Long
        Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        myDB = acDoc.Database

        myTransMan = myDB.TransactionManager
        myTrans = myTransMan.StartTransaction
        myBT = myDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
        myBTR = myBT(BlockName).GetObject(DatabaseServices.OpenMode.ForRead)
        myOIDs2 = myBTR.GetBlockReferenceIds(True, False)
        For I = 1 To myOIDs2.Count
            myOIDs.Add(myOIDs2.Item(I - 1))
        Next
        myBTRE = myBT.GetEnumerator
        While myBTRE.MoveNext
            myBTR = myBTRE.Current.GetObject(DatabaseServices.OpenMode.ForRead)
            If myBTR.IsLayout = False Then
                Select Case myBTR.IsAnonymous
                    Case True
                        myOIDs2 = myBTR.GetBlockReferenceIds(True, False)
                        If myOIDs2.Count > 0 Then
                            Dim myBRef As DatabaseServices.BlockReference
                            myBRef = myOIDs2(0).GetObject(DatabaseServices.OpenMode.ForRead)
                            Dim myBTR2 As DatabaseServices.BlockTableRecord
                            myBTR2 = myBRef.DynamicBlockTableRecord.GetObject( _
                            DatabaseServices.OpenMode.ForRead)

                            If myBTR2.Name.CompareTo(BlockName) = 0 Then
                                For I = 1 To myOIDs2.Count
                                    myOIDs.Add(myOIDs2.Item(I - 1))
                                Next
                            End If
                        End If
                End Select
            End If
        End While
        myTrans.Dispose()
        myTransMan.Dispose()
        Return myOIDs
    End Function

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 2 of 2 (102 Views)

Re: Problem with VS2008 & autocad

12-03-2012 08:20 AM in reply to: cokhitp

Hello,

 

Is that a compile error ?

Have you set the right .Net framework version in your project settings ?

 

For .Net applications, you can use VS 2008 but need to set the target framework to 3.0

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.