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

Attribute Ref moves after text edit

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
366 Views, 4 Replies

Attribute Ref moves after text edit

If I change the text of an attribute reference, am I responsible for repositioning it based on it's justification? If so, what is the easiest way to do this.
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

If the attribute is in the active document, you shouldn't
have to do that.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5558098@discussion.autodesk.com...
If I change the text of an attribute reference, am I responsible for repositioning it based on it's justification? If so, what is the easiest way to do this.
Message 3 of 5
Anonymous
in reply to: Anonymous

It's not in the active document.

Example:

Public Shared Sub SetAttributeData(ByVal blkRef As BlockReference, fileName as string)
Dim Trans As Transaction = Nothing
dim db as New Database

db.ReadDwgFile(fileName, IO.FileShare.ReadWrite, False, Nothing)

Try
Trans = db.TransactionManager.StartTransaction

For Each oid As ObjectId In blkRef.AttributeCollection
Dim att As AttributeReference = Trans.GetObject(oid, OpenMode.ForWrite)

If string.compare(att.Tag, "test", true) = 0 Then
att.TextString = "test"
exit for

End If

att.Dispose()

Next

Trans.Commit()

db.Saveas(fileName)

Catch ex As Exception
If Not Trans Is Nothing Then
Trans.Abort()

End If

Finally
If Not Trans Is Nothing AndAlso Not Trans.IsDisposed Then
Trans.Dispose()

End If
End Try
End Sub
Message 4 of 5
Anonymous
in reply to: Anonymous

To make the attributes update their alignment
correctly, the WorkingDatabase property of the
HostApplicationServices object must be set to
the database that contains the attribute.

e.g.

AttributeReference att = // ...
Database current = HostApplicationServices.WorkingDatabase;
HostApplicationServices.WorkingDatabase = att.Database;
try
{
// modify text or attribute here
}
finally
{
HostApplicationServices.WorkingDatabase = current;
}




--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5558899@discussion.autodesk.com...
It's not in the active document.

Example:

Public Shared Sub SetAttributeData(ByVal blkRef As BlockReference, fileName as string)
Dim Trans As Transaction = Nothing
dim db as New Database

db.ReadDwgFile(fileName, IO.FileShare.ReadWrite, False, Nothing)

Try
Trans = db.TransactionManager.StartTransaction

For Each oid As ObjectId In blkRef.AttributeCollection
Dim att As AttributeReference = Trans.GetObject(oid, OpenMode.ForWrite)

If string.compare(att.Tag, "test", true) = 0 Then
att.TextString = "test"
exit for

End If

att.Dispose()

Next

Trans.Commit()

db.Saveas(fileName)

Catch ex As Exception
If Not Trans Is Nothing Then
Trans.Abort()

End If

Finally
If Not Trans Is Nothing AndAlso Not Trans.IsDisposed Then
Trans.Dispose()

End If
End Try
End Sub
Message 5 of 5
Anonymous
in reply to: Anonymous

You da man... Thanks Tony that worked great.

should I do this anytime I am editing a database?

I was confussed, I thought that the working database was only for Documents that are open. This will fix many problems I have been having.

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