Author Topic: Attribute will sometimes move  (Read 1308 times)

0 Members and 1 Guest are viewing this topic.

WOWENS

  • Newt
  • Posts: 60
Attribute will sometimes move
« on: October 22, 2012, 08:42:42 AM »
AutoCad 2012...when using
db.ReadDwgFile(MyDwg, IO.FileShare.ReadWrite, False, "")

to change Attribute Values the Attribute will sometimes move
if i open the Drawing and run a audit on the drawing and regen then it moves back to is correct location

but if i use
Dim NewDoc As Document = Application.DocumentManager.Open(DocumentName, false)
and run the same code there is no problem.

so my question is why does it do that?

Sub SetAttributeValues(ByVal BlockReferenceID As ObjectId, ByVal AttributeTagsValues As Dictionary(Of String, String))
        Dim DwgEditor As Editor = TryCast(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor, Editor)

        Using myTrans As Transaction = BlockReferenceID.Database.TransactionManager.StartTransaction
            Try
                Dim myBRef As BlockReference = TryCast(BlockReferenceID.GetObject(OpenMode.ForRead), BlockReference)
                Dim myAttCollection As AttributeCollection = TryCast(myBRef.AttributeCollection, AttributeCollection)
                For Each myAttRefID As ObjectId In myAttCollection
                    Dim myAttRef As AttributeReference = TryCast(myAttRefID.GetObject(OpenMode.ForWrite), AttributeReference)
                    If AttributeTagsValues.ContainsKey(myAttRef.Tag) Then
                        myAttRef.TextString = AttributeTagsValues(myAttRef.Tag)
                    End If
                Next
                myTrans.Commit()
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                DwgEditor.WriteMessage(ex.Message + vbLf + ex.StackTrace)
                myTrans.Abort()
            End Try
        End Using
    End Sub

WOWENS

  • Newt
  • Posts: 60
Re: Attribute will sometimes move
« Reply #1 on: October 22, 2012, 08:55:26 AM »
and it only seems to do that on Attributes that are set to justificated = center

WOWENS

  • Newt
  • Posts: 60
Re: Attribute will sometimes move
« Reply #2 on: October 22, 2012, 10:57:09 AM »
got it working

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Attribute will sometimes move
« Reply #3 on: October 22, 2012, 11:10:17 AM »
What did you do DBText.AdjustAlignment?

WOWENS

  • Newt
  • Posts: 60
Re: Attribute will sometimes move
« Reply #4 on: October 22, 2012, 03:11:48 PM »
Sub SetAttributeValues(ByVal BlockReferenceID As ObjectId, ByVal AttributeTagsValues As Dictionary(Of String, String))
        Dim DwgEditor As Editor = TryCast(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor, Editor)

        Dim db As Database = BlockReferenceID.Database
        Dim workDb As Database = HostApplicationServices.WorkingDatabase


        Using myTrans As Transaction = db.TransactionManager.StartTransaction
            Try
                HostApplicationServices.WorkingDatabase = db

                Dim myBRef As BlockReference = TryCast(BlockReferenceID.GetObject(OpenMode.ForRead), BlockReference)
                Dim myAttCollection As AttributeCollection = TryCast(myBRef.AttributeCollection, AttributeCollection)
                For Each myAttRefID As ObjectId In myAttCollection
                    Dim myAttRef As AttributeReference = TryCast(myAttRefID.GetObject(OpenMode.ForWrite), AttributeReference)
                    If AttributeTagsValues.ContainsKey(myAttRef.Tag) Then
                        myAttRef.TextString = AttributeTagsValues(myAttRef.Tag)
                        myAttRef.AdjustAlignment(db)
                    End If
                Next

                HostApplicationServices.WorkingDatabase = workDb
                myTrans.Commit()
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                DwgEditor.WriteMessage(ex.Message + vbLf + ex.StackTrace)
                myTrans.Abort()
            End Try
        End Using

    End Sub