Hi,
I'm creating a routine to fill in my terminal strips. This routine worked perfectly in Vba but I'm now rewriting it for .NET
The problem is that I want to insert a block with attributes into different cells.
The tables already exists. Below my function, I'm stuck on this part
Dim lonReturnedIds = FunBlockId() ' Calls the function FunBlockID to get the ID's of the attributes
' 0 = BlockID
' 1 = AttributeID of KleurB
' 2 = AttributeID of KleurO
TS.Cells(i, intPosition).Contents.Add()
TS.Cells(i, intPosition).Contents(0).BlockTableRecordId = lonReturnedIds(0)
TS.Cells(i, intPosition).SetBlockAttributeValue(lonReturnedIds(1), strCableConductor2WriteFirst)
Thanks in advance.
Gerald
Public Function Fun_StripUp(ByVal Po3dXY As Point3d, ByVal str_CableName As String, ByVal Str_CableConductor As String, ByVal strCableConductor2Write As String, ByVal strCableConductor2WriteFirst As String, ByVal intPosition As Integer) As String Dim tAcadDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim myDB As DatabaseServices.Database Dim myDWG As ApplicationServices.Document Dim myEd As EditorInput.Editor Dim myPSR As EditorInput.PromptSelectionResult Dim mySS As EditorInput.SelectionSet Dim myFilter(0) As DatabaseServices.TypedValue myFilter(0) = New DatabaseServices.TypedValue(DatabaseServices.DxfCode.Start, "ACAD_TABLE") ' myFilter(0) = New DatabaseServices.TypedValue(DatabaseServices.DxfCode.Start, "POLYLINE") ' myFilter(0) = New DatabaseServices.TypedValue(DatabaseServices.DxfCode.Start, "MTEXT")''' ' Change items commented out above for testing. Dim mySF As New EditorInput.SelectionFilter(myFilter) myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument myDB = myDWG.Database myEd = myDWG.Editor myPSR = myEd.SelectAll(mySF) Dim GetInfofromIni As New Readini Dim str_CableNumber_UP As Integer = GetInfofromIni.IniInfo("External", "FieldNumber_Cable") Dim tTrAct As DatabaseServices.Transaction = Nothing Try mySS = myPSR.Value tTrAct = tAcadDoc.TransactionManager.StartTransaction If Not IsNothing(mySS) Then ' MsgBox(mySS.Count) For Each tObjID As DatabaseServices.ObjectId In myPSR.Value.GetObjectIds 'here we go through the returned ObjectID's 'Dim e As Entity = tTrAct.GetObject(tObjID, OpenMode.ForWrite) Dim TS As Table = tTrAct.GetObject(tObjID, OpenMode.ForWrite) If TS.Position <> Po3dXY Then 'MsgBox("No action will be taken") Else 'MsgBox(TS.Position) Dim itotaal = TS.Rows.Count Dim itotal_columns = TS.Columns.Count Dim i As Integer 'Dim ii = 0 i = itotaal - 1 Do While i > 0 Dim strCableNumber = TS.Cells(i, str_CableNumber_UP).TextString If strCableNumber = "" Then TS.Cells(i, str_CableNumber_UP).TextString = str_CableName 'we have to determine the position for the cable conductor ' also check for the conductor numbers, if it's only 2 then nothing ' else we have place a block inside the cellvalue ' kleur2 is for conductor with 3 or 4 characters If strCableConductor2Write <> "" Then If strCableConductor2WriteFirst = "" Then TS.Cells(i, intPosition).TextString = strCableConductor2Write TS.Cells(i, intPosition).Alignment = CellAlignment.MiddleCenter Else Dim lonReturnedIds = FunBlockId() ' Calls the function FunBlockID to get the ID's of the attributes ' 0 = BlockID ' 1 = AttributeID of KleurB ' 2 = AttributeID of KleurO TS.Cells(i, intPosition).Contents.Add() TS.Cells(i, intPosition).Contents(0).BlockTableRecordId = lonReturnedIds(0) TS.Cells(i, intPosition).SetBlockAttributeValue(lonReturnedIds(1), "TTEEST") TS.Cells(i, intPosition).SetBlockAttributeValue(lonReturnedIds(2), "TTEEST") End If Else TS.Cells(i, intPosition).TextString = Str_CableConductor TS.Cells(i, intPosition).Alignment = CellAlignment.MiddleCenter End If GoTo endfunction End If i = i - 1 Loop End If Next EndFunction: tTrAct.Commit() End If Catch ex As SystemException MsgBox(Err.Description) Finally If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing End Try Return Nothing End Function
Solved! Go to Solution.
Try this post:
http://through-the-interface.typepad.com/through_the_interface/2007/06/creating_an_aut_1.html
The original post does not deal with attributes, but there is some activity in the comments that talks about how to do it.
Thanks for your reply, I already had seen that post.
But when I now looked at the code I saw my mistake.
It should be
TS.UpgradeOpen()
TS.Cells(i, intPosition).BlockTableRecordId = lonreturnedIds(0)
Again thanks.