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 acBlkTblRec.AppendEntity(acCirc) ' 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 acBlkTblRec.AppendEntity(acAttDef) 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 acBlkTblRec.AppendEntity(acAttDef3) acBlkTbl.UpgradeOpen() acBlkTbl.Add(acBlkTblRec) acTrans.AddNewlyCreatedDBObject(acBlkTblRec, True) End Using End Using End Using End If ' Save the new object to the database acTrans.Commit() ' 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?
Hi,
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.
Regards,
Balaji