Hi Gile,
I want to update Block attributes values without explode process. After attributes updation, the block has been exploded. If i go and search that block in the drawing its not displayed due to exploded.
But i want update attributes without explode the block.
Please help me to go further process.
Thnks
Balaji
Hi,
No need to explode the block reference to edit attribute reference values.
There're many examples here and elsewhere.
The process is:
Open the BlockReference
For each ObjectId in the BlockReference.AttributeCollection:
Open the AttributeReference
If the AttributeReference.Tag matches:
Set the AttributeReference.TextString value
You should show what you have done so far, so that anyone over here (not only me) can help you.
Hi gile
Sorry, i forget to add my code.
Please check my code what i done so far.
Sub OpenDrwg()
Dim objdoc As Object
Dim ListItem As Object
Dim dwgfile, dwgfilelog
Dim filelist, flpth, i
actdoc = Nothing
actdb = Nothing
actdb = New Database
Dim docmgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
DocumentCollectionExtension.CloseAll(docmgr)
actdoc = DocumentCollectionExtension.Open(docmgr, "D:\Drawingconversion\Batch-7\Input\STER-DRIEHOEK BEDIENING OP 2 LOCATIES.DWG")
actdoc.LockDocument()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim id As ObjectId = GetBlockTableRecordId(doc.Database, "M112")
Dim tag As String = "LC"
Dim newValue As String = "EXTERN-INFO"
Using tr As Transaction = doc.TransactionManager.StartTransaction
Dim btr As BlockTableRecord = TryCast(id.GetObject(OpenMode.ForRead), BlockTableRecord)
Dim cnt As Integer = GlobalModule.SetAttributeValue(btr, tag, newValue)
doc.Editor.WriteMessage(vbNewLine & "Updated {0} attributes", New Object() {cnt})
'btr.Explodable = False
tr.Commit()
'tr.Dispose()
End Using
'actdoc.Database.Save()
actdoc.Database.SaveAs("D:\Drawingconversion\Batch-7\Input\STER-DRIEHOEK BEDIENING OP 2 LOCATIES-2.DWG", True, DwgVersion.Current, actdoc.Database.SecurityParameters)
DocumentCollectionExtension.CloseAll(docmgr)
End Sub
Public Function SetAttributeValue(ByVal btr As BlockTableRecord, ByVal tag As String, ByVal newValue As String) As Integer
Dim cnt As Integer = 0
Using tr As Transaction = btr.Database.TransactionManager.StartTransaction
Dim ids As ObjectIdCollection = btr.GetBlockReferenceIds(True, True)
If (Not ids Is Nothing) Then
Dim btrId As ObjectId
For Each btrId In ids
Dim blockref As BlockReference = TryCast(btrId.GetObject(OpenMode.ForRead, False), BlockReference)
If (Not blockref.AttributeCollection Is Nothing) Then
Dim attId As ObjectId
For Each attId In blockref.AttributeCollection
Dim att As AttributeReference = TryCast(attId.GetObject(OpenMode.ForRead, False), AttributeReference)
If String.Equals(att.Tag, tag, StringComparison.OrdinalIgnoreCase) Then
Try
att.UpgradeOpen()
MsgBox(newValue)
att.TextString = newValue
att.DowngradeOpen()
'att.Dispose()
Catch ex As Global.Autodesk.AutoCAD.Runtime.Exception
If (ex.ErrorStatus <> ErrorStatus.OnLockedLayer) Then
Throw
End If
Exit For
End Try
cnt += 1
Exit For
End If
Next
blockref.ExplodeToOwnerSpace()
End If
Next
End If
tr.Commit()
'tr.Dispose()
End Using
Return cnt
End Function
My process is :
1. Open drawing file
2. Check the block and Tag
3. Update the value to particular attribute
4. Saveas file
After complition that process, if open saved file, my updated block is not available because of my block has been exploded.
I don't want that block to be exploded.
Values should be update without explode method.
Please help me to do without explode process.
Thnks
Balaji
@Anonymous wrote:
Public Function SetAttributeValue(ByVal btr As BlockTableRecord, ByVal tag As String, ByVal newValue As String) As Integer
Dim cnt As Integer = 0
Using tr As Transaction = btr.Database.TransactionManager.StartTransaction
Dim ids As ObjectIdCollection = btr.GetBlockReferenceIds(True, True)
If (Not ids Is Nothing) Then
Dim btrId As ObjectId
For Each btrId In ids
Dim blockref As BlockReference = TryCast(btrId.GetObject(OpenMode.ForRead, False), BlockReference)
If (Not blockref.AttributeCollection Is Nothing) Then
Dim attId As ObjectId
For Each attId In blockref.AttributeCollection
Dim att As AttributeReference = TryCast(attId.GetObject(OpenMode.ForRead, False), AttributeReference)
If String.Equals(att.Tag, tag, StringComparison.OrdinalIgnoreCase) Then
Try
att.UpgradeOpen()
MsgBox(newValue)
att.TextString = newValue
att.DowngradeOpen()
'att.Dispose()Catch ex As Global.Autodesk.AutoCAD.Runtime.Exception
If (ex.ErrorStatus <> ErrorStatus.OnLockedLayer) Then
Throw
End If
Exit For
End Try
cnt += 1
Exit For
End If
Next
blockref.ExplodeToOwnerSpace()
End If
Next
End If
tr.Commit()
'tr.Dispose()
End Using
Return cnt
End Function
Did you try removing: blockref.ExplodeToOwnerSpace()?
Hi gile,
Thanks for your immediate reply.
Even if remove blockref.ExplodeToOwnerSpace()
I am facing same problem, after upation block attributes. That block has been exploded.
But i don't want to be exploded.
What i am looking is, i want to open drawing file and update particular block/tag attribute values and save as new dwg. Open saved dwg and check whether block/tag attributes has changed.
Currently,i can able to find block/tag and update the value.
is it correct coding(i posted) for what i am looking my process.??
Thnks
Balaji
Hi Gile,
Once again i will check with my code, if i done any mistake, i will correct and update you.
Thnks
Balaji