Distinguished Contributor
Posts: 167
Registered: ‎07-01-2008
Message 1 of 2 (83 Views)

vb.net able to create attributes , but unable to alling them orderly

83 Views, 1 Replies
08-07-2014 05:08 AM

Pardon me but I am no good at vb.net for AutoCAD.


What I'm trying to achive is to create a Bill Of Matterials list that can be inserted into a drawing.


The general structure I want is to create a block with attributes, if a certain block exists then add a new attribute otherwise skip and check for the next block ect...


I had to start from scratch and though counting blocks works fine its the acctual adding of a new attribute which has me a little stuck.


The code i used to train with is as follows.



Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

Public Class Add_ATTRIBUTES

    <CommandMethod("abd")> _
    Public Sub abd()
        ' Get the current database and start a transaction
        Dim acCurDb As Autodesk.AutoCAD.DatabaseServices.Database
        acCurDb = Application.DocumentManager.MdiActiveDocument.Database

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            ' Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)

            If Not acBlkTbl.Has("CircleBlockWithAttributes") Then
                Using acBlkTblRec As New BlockTableRecord
                    acBlkTblRec.Name = "CircleBlockWithAttributes"

                    ' Set the insertion point for the block
                    acBlkTblRec.Origin = New Point3d(0, 0, 0)

                    ' Add a circle to the block
                    Using acCirc As New Circle
                        acCirc.Center = New Point3d(0, 0, 0)
                        acCirc.Radius = 2


                        ' Add an attribute definition to the block
                        Using acAttDef As New AttributeDefinition
                            acAttDef.Position = New Point3d(0, 0, 0)
                            acAttDef.Verifiable = True
                            acAttDef.Prompt = "Door #: "
                            acAttDef.Tag = "Door#"
                            acAttDef.TextString = "test door"
                            acAttDef.Height = 1
                            'acAttDef.Justify = AttachmentPoint.TopLeft

                            Dim acAttDef3 As New AttributeDefinition
                            'acAttDef3.Position = New Point3d(0, 0, 0)
                            acAttDef3.Verifiable = True
                            acAttDef3.Prompt = "window #: "
                            acAttDef3.Tag = "window#"
                            acAttDef3.TextString = "test window"
                            acAttDef3.Height = 1
                            acAttDef3.Justify = AttachmentPoint.TopLeft

                            acTrans.AddNewlyCreatedDBObject(acBlkTblRec, True)
                        End Using
                    End Using
                End Using
            End If

            ' Save the new object to the database

            ' Dispose of the transaction
        End Using
    End Sub

  the problem is not that i cant create a new attribute but allingning the newly created attributes so that theres space inbetween rows is the issue.

when tested test window is directly attached to test door?

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

Re: vb.net able to create attributes , but unable to alling them orderly

08-14-2014 04:40 AM in reply to: bart_van_tuyl



Can you please try assigning different Position values for those attribute definitions ?

I think the geometry extents of the first attribute definition can help your code decide the position of the next attribute definition.








Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
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.