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

Attribute Help

2 REPLIES 2
Reply
Message 1 of 3
william.chandler
310 Views, 2 Replies

Attribute Help

Sorry if this is a dumb question I am new to vb.net I have attached code that creates a block that portion works but when I try and add Attributes to the block no attribute is created. any and all help would be appreciated.

Sorry again if this is a dumb question.

thanks
Bill
2 REPLIES 2
Message 2 of 3
Hallex
in reply to: william.chandler

Try this function from my working code
Just adapt it to your needs

Public Shared Function CreateLabelBlock() As ObjectId

Try
Dim ID As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase()
Using tr As Transaction = db.TransactionManager.StartTransaction()

Dim bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForWrite, False), BlockTable)
If (bt.Has("LABEL")) Then
ID = bt("LABEL")
Else

Dim btr As BlockTableRecord = New BlockTableRecord()
btr.Name = "LABEL"
btr.Origin = New Point3d(0, 0, 0)
btr.Units = UnitsValue.Inches
btr.BlockScaling = BlockScaling.Uniform
Dim line As Line = New Line(New Point3d(-2, -0.4, 0), New Point3d(2, -0.4, 0))
line.Layer = "0"
line.ColorIndex = 14
btr.AppendEntity(line)
line = New Line(New Point3d(-2, 0.4, 0), New Point3d(2, 0.4, 0))
line.Layer = "0"
line.ColorIndex = 14
btr.AppendEntity(line)
line = New Line(New Point3d(2, -0.4, 0), New Point3d(2, 0.4, 0))
line.Layer = "0"
line.ColorIndex = 14
btr.AppendEntity(line)
line = New Line(New Point3d(-2, -0.4, 0), New Point3d(-2, 0.4, 0))
line.Layer = "0"
line.ColorIndex = 14
btr.AppendEntity(line)
acadApp.SetSystemVariable("CECOLOR", "ByBlock")
Dim ad As AttributeDefinition = New AttributeDefinition
ad.Layer = "0"
ad.Tag = "DETAIL"
ad.TextString = "Ladder"
ad.Prompt = "Detail name"

ad.Position = New Point3d(0, 0, 0)
ad.HorizontalMode = TextHorizontalMode.TextMid
ad.VerticalMode = TextVerticalMode.TextVerticalMid
ad.AlignmentPoint = ad.Position
btr.AppendEntity(ad)

ID = bt.Add(btr)
acadApp.SetSystemVariable("CECOLOR", "ByLayer")
tr.AddNewlyCreatedDBObject(btr, True)
End If
tr.Commit()
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
acadApp.ShowAlertDialog("ERROR:" & vbCr & ex.Message & vbCr & ex.StackTrace)
End Try
End Function


~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 3
pellacad
in reply to: william.chandler

Hello Hallex,

I am trying to get your code to run inside my VB.NET app...no luck so far.

Here's the code I'm trying to use...

Public Shared Function CreateLabelBlock() As ObjectId

'http://discussion1.autodesk.com/forums/thread.jspa?messageID=6216355�
MsgBox("Inside the CreateLabelBlock sub...")
Try
Dim ID As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase()
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForWrite, False), BlockTable)
If (bt.Has("LABEL")) Then
ID = bt("LABEL")
Else
Dim btr As BlockTableRecord = New BlockTableRecord()
btr.Name = "LABEL"
btr.Origin = New Point3d(0, 0, 0)
btr.Units = UnitsValue.Inches
btr.BlockScaling = BlockScaling.Uniform
Dim line As Line = New Line(New Point3d(-2, -0.4, 0), New Point3d(2, -0.4, 0))
line.Layer = "0"
line.ColorIndex = 14
btr.AppendEntity(line)
line = New Line(New Point3d(-2, 0.4, 0), New Point3d(2, 0.4, 0))
line.Layer = "0"
line.ColorIndex = 14
btr.AppendEntity(line)
line = New Line(New Point3d(2, -0.4, 0), New Point3d(2, 0.4, 0))
line.Layer = "0"
line.ColorIndex = 14
btr.AppendEntity(line)
line = New Line(New Point3d(-2, -0.4, 0), New Point3d(-2, 0.4, 0))
line.Layer = "0"
line.ColorIndex = 14
btr.AppendEntity(line)
objAcad.SetSystemVariable("CECOLOR", "ByBlock")
Dim ad As AttributeDefinition = New AttributeDefinition
ad.Layer = "0"
ad.Tag = "DETAIL"
ad.TextString = "Ladder"
ad.Prompt = "Detail name"
ad.Position = New Point3d(0, 0, 0)
ad.HorizontalMode = TextHorizontalMode.TextMid
ad.VerticalMode = TextVerticalMode.TextVerticalMid
ad.AlignmentPoint = ad.Position
btr.AppendEntity(ad)
ID = bt.Add(btr)
objAcad.SetSystemVariable("CECOLOR", "ByLayer")
tr.AddNewlyCreatedDBObject(btr, True)
End If
tr.Commit()
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
objAcad.ShowAlertDialog("ERROR:" & vbCr & ex.Message & vbCr & ex.StackTrace)
End Try
End Function

It absolutely, positively refuses to run past the function call...if I comment out the function call to this function, the program runs as expected.

Must I do something specifically to get the Database and Transaction Manager parts to run properly?


I need to add a couple of invisible attributes to an existing user selected block...

Thank you in advance for any ideas or help you might be able to give me...

Pete

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