.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to declare an attributes variable in VB.NET?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
celsoven
2312 Views, 8 Replies

How to declare an attributes variable in VB.NET?

Hello to everybody.

 

I'm using API.COM with Visual Studio 2008

 

My question is very simple, in VB6.0, VBA, etc.  I declared an attribute variable like this:

 

Dim attr as variant

 

How i have to declare now in VB.net??

 

Thanks in advance.

 

8 REPLIES 8
Message 2 of 9
JamieVJohnson2
in reply to: celsoven

An attribute is an object in the AutoCAD.DatabaseServices namespace used in AutoCAD Blocks to hold text strings that can be modified after insertion.  Do you mean that attribute, or just the old fashion, an attribute is a place holder for any data in code?  For the latter Dim x as Object.  "Object" is the 'anything goes' name for an empty variant.

 

jvj

jvj
Message 3 of 9
celsoven
in reply to: JamieVJohnson2

I have this code

 

Dim blockCruce As Autodesk.AutoCAD.Interop.Common.AcadBlockReference

Dim Atributos As Object

 

Atributos = blockCruce.GetAttributes

atributos.TextString = "X= xxx"

 

 

'the blockCruce has an attribute i have to change the value to "X=xxx"

'but when i type atributos.   doesn't show the method <<TextStrinh>> and I don't know why?

 

Message 4 of 9
JamieVJohnson2
in reply to: celsoven

You are using the Attribute object as it is already inserted, so declare it like this:

Dim attr As Autodesk.AutoCAD.DatabaseServices.AttributeReference

 

jvj

jvj
Message 5 of 9
arcticad
in reply to: JamieVJohnson2

Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices

Public Class Class1

    <CommandMethod("getAtt")> _
  Public Sub GetBlock()
        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor()
        Dim sOptions As New PromptEntityOptions(vbCr & "Select Block: ")
        sOptions.SetRejectMessage(vbLf & "Invalid Selection: ")
        sOptions.AddAllowedClass(GetType(BlockReference), False)
        Dim sRes As PromptEntityResult = Nothing
        While (True)
            sRes = ed.GetEntity(sOptions)
            If Not sRes.Status <> PromptStatus.OK Then
                Getatt(sRes.ObjectId)
            Else
                Exit While
            End If
        End While

    End Sub


    Sub Getatt(ByVal objID As ObjectId)

        Using db As Database = HostApplicationServices.WorkingDatabase()
            Using tr As Transaction = db.TransactionManager.StartTransaction
                Dim myDWG As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
                Using lock As DocumentLock = myDWG.LockDocument
                    Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead, False)
                    Dim bl As BlockReference = DirectCast(tr.GetObject(objID, OpenMode.ForRead), BlockReference)
                    Dim AtCol As AttributeCollection = bl.AttributeCollection
                    For Each AttID In AtCol
                        Dim AtRef As AttributeReference = tr.GetObject(AttID, OpenMode.ForRead, False, True)
                        MsgBox(AtRef.Tag & "-" & AtRef.TextString)
                    Next AttID
                    tr.Commit()
                End Using
            End Using
        End Using

    End Sub
End Class
netload

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 6 of 9
norman.yuan
in reply to: celsoven

There have been a few replies to your question, but none of them is straight to your question. I am not questioning on why you use COM API instead of .NET API (if so, arcticad's repoly has detailed code for you to use) here, but you may want to make sure you do have good reason using COM API instead of .NET API.

 

Yes, in your case, you do declare

 

Dim Atributos As Object

Atributos = blockCruce.GetAttributes

 

Because GetAttributes() method DOES NOT return an AcadAttributeRefernce object, rather it returns an Viriant (in COM API) or Object (in .NET  it is equivelant to Variant in COM), which is an ARRAY of AcadAttributeReference object.

 

So, you cannot declare it as anything else but Object

 

The next line of code is wrong:

 

atributos.TextString = "X= xxx"

 

because atributos is an ARRAY of AcadAttributeReference object, not an AcadAttributeReference, thus, the array DOES NOT have a property "TextString". The code should be something like:

 

atributos(index).TextStriing="xxxxxx"

 

That is, only a specific element in the array is an AcadAttributeReference and has "TextString" property that you can get/set.

 

Again, make sure you have GOOD reason to use COM API.

 

Message 7 of 9
celsoven
in reply to: JamieVJohnson2

I change the declaration to this:

Dim atributos As Autodesk.AutoCAD.DatabaseServices.AttributeReference

 

and now the program sends me the next error:

 

No se puede cargar el archivo o ensamblado 'acdbmgd, Version=17.0.51.0, Culture=neutral, PublicKeyToken=null' ni una de sus dependencias. El sistema no puede hallar el archivo especificado.

 

What could be the problem?

 

I change the declaration to:

Dim atributos As Object

 

and use it with and index like this

 

atributos(0).TextString = "X=" & insX(0)

 

and it works OK, but it runs slow, my program insert like 200 blocks and set the attribute to "X=1, X=2, X= 3, ... X= n  

 

I don't know if I'm doing it on the correct way

 

Thanks

Message 8 of 9
celsoven
in reply to: norman.yuan

Hello Norman

 

I'm using API.com because I learned with VB6.0 and is easier for me to use API.COM instead API.NET

 

I supose is better to use API.NET than API.COM but I don't know how to start wiht API.NET. it seems hard to learn isn't it?

 

Thanks a lot for your information.

 

Message 9 of 9
Balaji_Ram
in reply to: celsoven

If you need help in learning AutoCAD .Net API, you can download the AutoCAD .Net Labs and watch the DevTV from

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1911627

 

The lab projects have code both in VB .Net and C#.

 

Hope this helps.



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost