TheSwamp
Code Red => .NET => Topic started by: vnsharifi on April 26, 2011, 10:20:21 AM
-
I have to add 80 Xdata to some objects. How to populate them within a loop. This what I did for 11 of them . But
I am pretty sure there is a way to do it in a loop which I don't know . Any help from experts would be appreciated.
Public Sub SetXData2()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
' Ask the user to select an entity
' for which to set XData
Dim opt As New PromptEntityOptions(vbLf & "Select entity: ")
Dim res As PromptEntityResult = ed.GetEntity(opt)
If res.Status = PromptStatus.OK Then
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
Dim obj As DBObject = tr.GetObject(res.ObjectId, OpenMode.ForWrite)
AddRegAppTableRecord1("Hello")
Dim rb As New ResultBuffer(New TypedValue(1001, "Hello"), _
New TypedValue(1000, "test1"), New TypedValue(1000, "test2") _
, New TypedValue(1000, "test3"), New TypedValue(1000, "test4") _
, New TypedValue(1000, "test5"), New TypedValue(1000, "test6") _
, New TypedValue(1000, "test7"), New TypedValue(1000, "test8") _
, New TypedValue(1000, "test9"), New TypedValue(1000, "test10") _
, New TypedValue(1000, "test11"))
obj.XData = rb
rb.Dispose()
tr.Commit()
End Using
End If
End Sub
-
ResultBuffer buf = new ResultBuffer();
for (int idx = 0; idx < 80; idx++)
{
buf.Add(new TypedValue(1000,string.Format("test{0}",idx)));
}
-
I have to add 80 Xdata to some objects. How to populate them within a loop.
You want to use the ResultBuffer.Add() method. Keep in mind that XData is seriously limited in the total amount of data (~16 K), consider using an Extension Dictionary instead.
An alternative for stuffing a ResultBuffer with varying amounts of data via params array was presented way back by Tony Tanzillo in his Command Line tool (http://www.caddzone.com/CommandLine.cs).
-
Another vote for 1
please please please please please please please please please let 1 get the most votes
-
ResultBuffer buf = new ResultBuffer();
for (int idx = 0; idx < 80; idx++)
{
buf.Add(new TypedValue(1000,string.Format("test{0}",idx)));
}
[/quote
]
Thanks Assume. I used Online C# converter tools , to convert your code to vb. Is this in C# ? I don't know how to make it work ? Sorry.It is my fault. Could somebody help me to incorporate Assume comment in my Code . Thanks for help.
-
ResultBuffer buf = new ResultBuffer();
for (int idx = 0; idx < 80; idx++)
{
buf.Add(new TypedValue(1000,string.Format("test{0}",idx)));
}
Does same thing
Dim resBuf As New ResultBuffer
For i As Integer = 1 To 80
resBuf.Add(New TypedValue(1000, String.Format("test{0}", i)))
Next
-
Thanks To Everybody. Assume - Jeff - (Special Thaks to Fixo ). attached find the coplete code which does the job for people who may face this in future.
<CommandMethod("Link6")> _
Public Sub SetXData()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim opt As New PromptEntityOptions(vbLf & "Select entity: ")
Dim res As PromptEntityResult = ed.GetEntity(opt)
If res.Status = PromptStatus.OK Then
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
Dim obj As DBObject = tr.GetObject(res.ObjectId, OpenMode.ForWrite)
AddRegAppTableRecord1("TCB")
Dim lstXdata As List(Of Object) = New List(Of Object)
For i As Integer = 0 To 99
lstXdata.Add("Test" + (i + 1).ToString)
Next
Dim rb As New ResultBuffer
rb.Add(New TypedValue(1001, "TCB"))
For Each strVal As String In lstXdata
rb.Add(New TypedValue(1000, strVal))
Next
obj.XData = rb
rb.Dispose()
tr.Commit()
End Using
End If
End Sub
Private Shared Sub AddRegAppTableRecord1(ByVal regAppName As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
Dim rat As RegAppTable = DirectCast(tr.GetObject(db.RegAppTableId, OpenMode.ForRead, False), RegAppTable)
If Not rat.Has(regAppName) Then
rat.UpgradeOpen()
Dim ratr As New RegAppTableRecord()
ratr.Name = regAppName
rat.Add(ratr)
tr.AddNewlyCreatedDBObject(ratr, True)
End If
tr.Commit()
End Using
End Sub
End Class