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

insert a block with attribute doesn't show up

6 REPLIES 6
Reply
Message 1 of 7
wang890
2525 Views, 6 Replies

insert a block with attribute doesn't show up

i am trying to insert a block with 4 attribute to paperspace and i got the block inserted ok, but then you can't see it unless you do a quickselect and it's there, but you only see the insertion grip but not the attribute grips. try to insert the created block with autocad command works ok. so which means block created properly.

'insert revision block
Dim br As New BlockReference(New Point3d(dX_RevisionInsert, y2 - dRev_V_Offset * dBorderScale, 0), Create_Revision_Note_Block(db))
BTR_Layout.AppendEntity(br)

'Dim revBtr As BlockTableRecord = trans.GetObject(br.BlockTableRecord, OpenMode.ForRead)
Dim revBtr As BlockTableRecord = trans.GetObject(bt(Rev_Block_Name), OpenMode.ForRead)

For Each id As ObjectId In revBtr

Dim oAttDef As AttributeDefinition
Dim oAttRef As AttributeReference = New AttributeReference()
Dim ent As Entity = trans.GetObject(id, OpenMode.ForRead, False)

If TypeOf ent Is AttributeDefinition Then
oAttDef = CType(ent, AttributeDefinition)

oAttRef.Height = oAttDef.Height
oAttRef.Rotation = oAttDef.Rotation
oAttRef.Tag = oAttDef.Tag

Select Case oAttDef.Tag

Case Rev_No_Tag
oAttRef.TextString = CStr(iRevision)
Case Rev_Date_Tag
oAttRef.TextString = sRevDate
Case Rev_Desc_Tag
oAttRef.TextString = sRevDesc
Case Rev_Sig_Tag
oAttRef.TextString = sRevSig
End Select
End If

br.AttributeCollection.AppendAttribute(oAttRef)
trans.AddNewlyCreatedDBObject(oAttRef, True)
Next

br.SetDatabaseDefaults()
trans.AddNewlyCreatedDBObject(br, True)
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
6 REPLIES 6
Message 2 of 7
BrentBurgess1980
in reply to: wang890

Try look at this post

http://discussion.autodesk.com/forums/message.jspa?messageID=6144800#6144800
Message 3 of 7
wang890
in reply to: wang890

attributes showed up now, but the text positions is not the same as the block that i created, see picture attached. look at the last line of text.

is there a way to synchronize the block? that way the position will be reset.

why is it this .net controlling autocad so much more complicated than the com programming? so much work just to insert a block. it's like this doesn't make sense. i already created the block in the drawing, and you have to re-add all attributes again when you insert the block. i didn't know that attribute definition and attribute reference are different things. when you do stuff in autocad you never have to pay attention to there things. there is only one object: attribute definition.

all i am trying to do is let the program go through couple thousand drawings, get the revision number, updated it by one, insert a block which i have to remake because people don't know what they are doing and do strange stuff to show the drawing revision text. i am doing all these by "db.ReadDwgFile" which doesn't open the drawing, or else this program will take forever to run consider each drawing has to be opened in editor. to make this in com would be so easy, i just want to learn this .net thing. seems 100 times more powerful.

thanks a lot.
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 4 of 7
wang890
in reply to: wang890

figured this one out, have to use new matrix, was using the matrix from block

oAttRef.SetAttributeFromBlock(oAttDef, New Matrix3d)

how come the program only works when i have 1 layout in drawing, once i have 2 layouts the block is inserted to each layout, but invisible like the first time. what i did is for each layout:

Dim br As New BlockReference(New Point3d..........

Dim revBtr As BlockTableRecord = trans.GetObject(br.BlockTableRecord, OpenMode.ForRead)

For Each id As ObjectId In revBtr

'here i go through each and find attribute definition and change the textstring.

Next

br.AttributeCollection.AppendAttribute(oAttRef)

trans.AddNewlyCreatedDBObject(oAttRef, True)

trans.AddNewlyCreatedDBObject(br, True)

maybe because i add a new object everytime? there's only 1 block with that name and i am trying to add many times?
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 5 of 7
Anonymous
in reply to: wang890

public bool AppendAttribRefToBlockRef(ObjectId blockdefid, ObjectId blockrefid, List attribs)
{
try
{
BlockTableRecord blkdef = (BlockTableRecord)m_Transaction.GetObject(blockdefid, OpenMode.ForRead);
int i = 0;
if (blkdef.HasAttributeDefinitions)
{
BlockReference blkref = (BlockReference)m_Transaction.GetObject(blockrefid, OpenMode.ForWrite);
foreach (ObjectId id in blkdef)
{
DBObject ent = GetObject(id, OpenMode.ForRead);
if (ent.GetType() == typeof(AttributeDefinition))
{
AttributeDefinition attdef = (AttributeDefinition)ent;
AttributeReference attref = new AttributeReference();
attref.SetAttributeFromBlock(attdef, blkref.BlockTransform);
if (attdef.Justify == AttachmentPoint.BaseLeft)
attref.Position = attdef.Position.TransformBy(blkref.BlockTransform);
else
attref.AlignmentPoint = attdef.AlignmentPoint.TransformBy(blkref.BlockTransform);
if (attref.IsMTextAttribute)
attref.UpdateMTextAttribute();
if (i < attribs.Count)
attref.TextString = attribs[i++];
else
attref.TextString = attdef.TextString;
blkref.AttributeCollection.AppendAttribute(attref);
m_Transaction.AddNewlyCreatedDBObject(attref, true);
}
}
}
return true;
}
catch
{ }
return false;
}
Message 6 of 7
wang890
in reply to: wang890

after 30 hours of playing around. i finally found the problem and i can say that i am sure it is the bug with the API.

so i am doing this whole thing by accessing the db like this:

Dim db As Database = New Database(False, False)
db.ReadDwgFile(TestPath, IO.FileShare.ReadWrite, True, "")

instead of

Dim db As Database = New Database(False, False)
db = Application.DocumentManager.MdiActiveDocument.Database

i tried open the drawing first in editor then the block is perfect, for some reason if i open the database by "readingdwgfile" then the block insertion is always lower left. is there a way to call an update block withing the API, like synchronize block in Cad.

thank you
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 7 of 7
Anonymous
in reply to: wang890

wang,

could you tell me how did you make the attribute show up?

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