.NET

.NET

Reply
*Zhongwei Xia
Message 1 of 12 (1,119 Views)

How to insert block with attributes into a drawing using .NET

1119 Views, 11 Replies
09-26-2005 02:51 PM
Hello,

Has everyone tried to insert blocks with attributes into a drawing file by
using dotnet (C# or VB.NET)?

There is an example "How to insert block with attributes into a drawing
using VB.NET" from ADN web site. But unfortunately, it doesn't work. Anytime
the attributes are inserted on Original position no matter how Position
properties of the attributes are set.

Following is part of my code:

AttributeDefinition attDef = (AttributeDefinition)ent;

AttributeReference attRef = new AttributeReference();

attDef = (AttributeDefinition)ent;

attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);

Point3d ptBase = new Point3d(blkRef.Position.X + attDef.Position.X,

blkRef.Position.Y + attDef.Position.Y,

blkRef.Position.Z + attDef.Position.Z);

//attRef.Position = ptBase;

//attRef.Position = insPoint;

attRef.Position = new Point3d(50, 50, 50);

attRef.Rotation = attDef.Rotation;

attRef.Tag = attDef.Tag;

attRef.TextString = "Attribute Text";

attRef.Height = attDef.Height;

attRef.FieldLength = attDef.FieldLength;


Can anybody help? Thank you very much.
Zhongwei Xia
*Tony Tanzillo
Message 2 of 12 (1,119 Views)

Re: How to insert block with attributes into a drawing using .NET

09-27-2005 12:40 AM in reply to: *Zhongwei Xia
Does the sample code from ADN actually show a call
to SetAttributeFromBlock(), with Matrix3d.Identity as
the second parameter???

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message news:4967475@discussion.autodesk.com...
Hello,

Has everyone tried to insert blocks with attributes into a drawing file by
using dotnet (C# or VB.NET)?

There is an example "How to insert block with attributes into a drawing
using VB.NET" from ADN web site. But unfortunately, it doesn't work. Anytime
the attributes are inserted on Original position no matter how Position
properties of the attributes are set.

Following is part of my code:

AttributeDefinition attDef = (AttributeDefinition)ent;

AttributeReference attRef = new AttributeReference();

attDef = (AttributeDefinition)ent;

attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);

Point3d ptBase = new Point3d(blkRef.Position.X + attDef.Position.X,

blkRef.Position.Y + attDef.Position.Y,

blkRef.Position.Z + attDef.Position.Z);

//attRef.Position = ptBase;

//attRef.Position = insPoint;

attRef.Position = new Point3d(50, 50, 50);

attRef.Rotation = attDef.Rotation;

attRef.Tag = attDef.Tag;

attRef.TextString = "Attribute Text";

attRef.Height = attDef.Height;

attRef.FieldLength = attDef.FieldLength;


Can anybody help? Thank you very much.
Zhongwei Xia
*Zhongwei Xia
Message 3 of 12 (1,119 Views)

Re: How to insert block with attributes into a drawing using .NET

09-27-2005 06:44 AM in reply to: *Zhongwei Xia
Hi, Tony,

Yes, it does. Thank you for your reply.
Zhongwei

"Tony Tanzillo" wrote in message
news:4967690@discussion.autodesk.com...
Does the sample code from ADN actually show a call
to SetAttributeFromBlock(), with Matrix3d.Identity as
the second parameter???

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4967475@discussion.autodesk.com...
Hello,

Has everyone tried to insert blocks with attributes into a drawing file by
using dotnet (C# or VB.NET)?

There is an example "How to insert block with attributes into a drawing
using VB.NET" from ADN web site. But unfortunately, it doesn't work. Anytime
the attributes are inserted on Original position no matter how Position
properties of the attributes are set.

Following is part of my code:

AttributeDefinition attDef = (AttributeDefinition)ent;

AttributeReference attRef = new AttributeReference();

attDef = (AttributeDefinition)ent;

attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);

Point3d ptBase = new Point3d(blkRef.Position.X + attDef.Position.X,

blkRef.Position.Y + attDef.Position.Y,

blkRef.Position.Z + attDef.Position.Z);

//attRef.Position = ptBase;

//attRef.Position = insPoint;

attRef.Position = new Point3d(50, 50, 50);

attRef.Rotation = attDef.Rotation;

attRef.Tag = attDef.Tag;

attRef.TextString = "Attribute Text";

attRef.Height = attDef.Height;

attRef.FieldLength = attDef.FieldLength;


Can anybody help? Thank you very much.
Zhongwei Xia
*Tony Tanzillo
Message 4 of 12 (1,119 Views)

Re: How to insert block with attributes into a drawing using .NET

09-27-2005 08:35 AM in reply to: *Zhongwei Xia
Amazing.

The Matrix3d argument to SetAttributeFromBlock()
should be set to the value of the BlockTransform
property of the owning BlockReference object.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message news:4967872@discussion.autodesk.com...
Hi, Tony,

Yes, it does. Thank you for your reply.
Zhongwei

"Tony Tanzillo" wrote in message
news:4967690@discussion.autodesk.com...
Does the sample code from ADN actually show a call
to SetAttributeFromBlock(), with Matrix3d.Identity as
the second parameter???

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4967475@discussion.autodesk.com...
Hello,

Has everyone tried to insert blocks with attributes into a drawing file by
using dotnet (C# or VB.NET)?

There is an example "How to insert block with attributes into a drawing
using VB.NET" from ADN web site. But unfortunately, it doesn't work. Anytime
the attributes are inserted on Original position no matter how Position
properties of the attributes are set.

Following is part of my code:

AttributeDefinition attDef = (AttributeDefinition)ent;

AttributeReference attRef = new AttributeReference();

attDef = (AttributeDefinition)ent;

attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);

Point3d ptBase = new Point3d(blkRef.Position.X + attDef.Position.X,

blkRef.Position.Y + attDef.Position.Y,

blkRef.Position.Z + attDef.Position.Z);

//attRef.Position = ptBase;

//attRef.Position = insPoint;

attRef.Position = new Point3d(50, 50, 50);

attRef.Rotation = attDef.Rotation;

attRef.Tag = attDef.Tag;

attRef.TextString = "Attribute Text";

attRef.Height = attDef.Height;

attRef.FieldLength = attDef.FieldLength;


Can anybody help? Thank you very much.
Zhongwei Xia
*Zhongwei Xia
Message 5 of 12 (1,118 Views)

Re: How to insert block with attributes into a drawing using .NET

09-27-2005 08:55 AM in reply to: *Zhongwei Xia
Hi, Tony,

Guess what!? I just comment the following line out, and set TextStyle from
AttributeDefinition. It works!!!.

// attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);
attRef.TextStyle = attDef.TextStyle;

Thank you very much. You emails help me alot.
Zhongwei

"Tony Tanzillo" wrote in message
news:4968102@discussion.autodesk.com...
Amazing.

The Matrix3d argument to SetAttributeFromBlock()
should be set to the value of the BlockTransform
property of the owning BlockReference object.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4967872@discussion.autodesk.com...
Hi, Tony,

Yes, it does. Thank you for your reply.
Zhongwei

"Tony Tanzillo" wrote in message
news:4967690@discussion.autodesk.com...
Does the sample code from ADN actually show a call
to SetAttributeFromBlock(), with Matrix3d.Identity as
the second parameter???

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4967475@discussion.autodesk.com...
Hello,

Has everyone tried to insert blocks with attributes into a drawing file by
using dotnet (C# or VB.NET)?

There is an example "How to insert block with attributes into a drawing
using VB.NET" from ADN web site. But unfortunately, it doesn't work. Anytime
the attributes are inserted on Original position no matter how Position
properties of the attributes are set.

Following is part of my code:

AttributeDefinition attDef = (AttributeDefinition)ent;

AttributeReference attRef = new AttributeReference();

attDef = (AttributeDefinition)ent;

attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);

Point3d ptBase = new Point3d(blkRef.Position.X + attDef.Position.X,

blkRef.Position.Y + attDef.Position.Y,

blkRef.Position.Z + attDef.Position.Z);

//attRef.Position = ptBase;

//attRef.Position = insPoint;

attRef.Position = new Point3d(50, 50, 50);

attRef.Rotation = attDef.Rotation;

attRef.Tag = attDef.Tag;

attRef.TextString = "Attribute Text";

attRef.Height = attDef.Height;

attRef.FieldLength = attDef.FieldLength;


Can anybody help? Thank you very much.
Zhongwei Xia
*Tony Tanzillo
Message 6 of 12 (1,118 Views)

Re: How to insert block with attributes into a drawing using .NET

09-27-2005 11:19 AM in reply to: *Zhongwei Xia
Most of the code from the example is not required if
you make the change I noted. For example, there
should be no need for manual translation, rotation,
and scaling since the BlockTransform matrix contains
all of that information, and SetAttributeFromBlock()
should do the transformation for you.

If I'm wrong about that, please let me know.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message news:4968152@discussion.autodesk.com...
Hi, Tony,

Guess what!? I just comment the following line out, and set TextStyle from
AttributeDefinition. It works!!!.

// attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);
attRef.TextStyle = attDef.TextStyle;

Thank you very much. You emails help me alot.
Zhongwei

"Tony Tanzillo" wrote in message
news:4968102@discussion.autodesk.com...
Amazing.

The Matrix3d argument to SetAttributeFromBlock()
should be set to the value of the BlockTransform
property of the owning BlockReference object.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4967872@discussion.autodesk.com...
Hi, Tony,

Yes, it does. Thank you for your reply.
Zhongwei

"Tony Tanzillo" wrote in message
news:4967690@discussion.autodesk.com...
Does the sample code from ADN actually show a call
to SetAttributeFromBlock(), with Matrix3d.Identity as
the second parameter???

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4967475@discussion.autodesk.com...
Hello,

Has everyone tried to insert blocks with attributes into a drawing file by
using dotnet (C# or VB.NET)?

There is an example "How to insert block with attributes into a drawing
using VB.NET" from ADN web site. But unfortunately, it doesn't work. Anytime
the attributes are inserted on Original position no matter how Position
properties of the attributes are set.

Following is part of my code:

AttributeDefinition attDef = (AttributeDefinition)ent;

AttributeReference attRef = new AttributeReference();

attDef = (AttributeDefinition)ent;

attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);

Point3d ptBase = new Point3d(blkRef.Position.X + attDef.Position.X,

blkRef.Position.Y + attDef.Position.Y,

blkRef.Position.Z + attDef.Position.Z);

//attRef.Position = ptBase;

//attRef.Position = insPoint;

attRef.Position = new Point3d(50, 50, 50);

attRef.Rotation = attDef.Rotation;

attRef.Tag = attDef.Tag;

attRef.TextString = "Attribute Text";

attRef.Height = attDef.Height;

attRef.FieldLength = attDef.FieldLength;


Can anybody help? Thank you very much.
Zhongwei Xia
*Zhongwei Xia
Message 7 of 12 (1,118 Views)

Re: How to insert block with attributes into a drawing using .NET

09-28-2005 08:30 AM in reply to: *Zhongwei Xia
Thank you for your email.

SetAttributeFromBlock() can't be called. If I call this function, attributes
will go to (0,0,0) position.
And also, if I set HorisontalMode of attribute, the attributes go to (0,0,0)
again.
attRef.HorizontalMode =
Autodesk.AutoCAD.DatabaseServices.TextHorizontalMode.TextCenter;

Zhongwei


"Tony Tanzillo" wrote in message
news:4968338@discussion.autodesk.com...
Most of the code from the example is not required if
you make the change I noted. For example, there
should be no need for manual translation, rotation,
and scaling since the BlockTransform matrix contains
all of that information, and SetAttributeFromBlock()
should do the transformation for you.

If I'm wrong about that, please let me know.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4968152@discussion.autodesk.com...
Hi, Tony,

Guess what!? I just comment the following line out, and set TextStyle from
AttributeDefinition. It works!!!.

// attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);
attRef.TextStyle = attDef.TextStyle;

Thank you very much. You emails help me alot.
Zhongwei

"Tony Tanzillo" wrote in message
news:4968102@discussion.autodesk.com...
Amazing.

The Matrix3d argument to SetAttributeFromBlock()
should be set to the value of the BlockTransform
property of the owning BlockReference object.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4967872@discussion.autodesk.com...
Hi, Tony,

Yes, it does. Thank you for your reply.
Zhongwei

"Tony Tanzillo" wrote in message
news:4967690@discussion.autodesk.com...
Does the sample code from ADN actually show a call
to SetAttributeFromBlock(), with Matrix3d.Identity as
the second parameter???

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4967475@discussion.autodesk.com...
Hello,

Has everyone tried to insert blocks with attributes into a drawing file by
using dotnet (C# or VB.NET)?

There is an example "How to insert block with attributes into a drawing
using VB.NET" from ADN web site. But unfortunately, it doesn't work. Anytime
the attributes are inserted on Original position no matter how Position
properties of the attributes are set.

Following is part of my code:

AttributeDefinition attDef = (AttributeDefinition)ent;

AttributeReference attRef = new AttributeReference();

attDef = (AttributeDefinition)ent;

attRef.SetAttributeFromBlock(attDef, Matrix3d.Identity);

Point3d ptBase = new Point3d(blkRef.Position.X + attDef.Position.X,

blkRef.Position.Y + attDef.Position.Y,

blkRef.Position.Z + attDef.Position.Z);

//attRef.Position = ptBase;

//attRef.Position = insPoint;

attRef.Position = new Point3d(50, 50, 50);

attRef.Rotation = attDef.Rotation;

attRef.Tag = attDef.Tag;

attRef.TextString = "Attribute Text";

attRef.Height = attDef.Height;

attRef.FieldLength = attDef.FieldLength;


Can anybody help? Thank you very much.
Zhongwei Xia
*Tony Tanzillo
Message 8 of 12 (1,118 Views)

Re: How to insert block with attributes into a drawing using .NET

09-28-2005 10:45 AM in reply to: *Zhongwei Xia
>> SetAttributeFromBlock() can't be called.
>> If I call this function, attributes will go to (0,0,0) position.

Did you pass the value of the BlockTransform property of
the BlockReference object to the second argument to
SetAttributesFromBlock, as I had mentioned earlier?


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message news:4969406@discussion.autodesk.com...
Thank you for your email.
*Zhongwei Xia
Message 9 of 12 (1,118 Views)

Re: How to insert block with attributes into a drawing using .NET

09-28-2005 11:47 AM in reply to: *Zhongwei Xia
I just tried it. I works great.
I appreciate your helps very much.
Zhongwei


"Tony Tanzillo" wrote in message
news:4969620@discussion.autodesk.com...
>> SetAttributeFromBlock() can't be called.
>> If I call this function, attributes will go to (0,0,0) position.

Did you pass the value of the BlockTransform property of
the BlockReference object to the second argument to
SetAttributesFromBlock, as I had mentioned earlier?


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4969406@discussion.autodesk.com...
Thank you for your email.
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 10 of 12 (1,118 Views)

Re: How to insert block with attributes into a drawing using .NET

09-30-2005 01:14 AM in reply to: *Zhongwei Xia
Is it possible for you to post the final code?
Roland


"Zhongwei Xia" schrieb im Newsbeitrag
news:4969745@discussion.autodesk.com...
I just tried it. I works great.
I appreciate your helps very much.
Zhongwei


"Tony Tanzillo" wrote in message
news:4969620@discussion.autodesk.com...
>> SetAttributeFromBlock() can't be called.
>> If I call this function, attributes will go to (0,0,0) position.

Did you pass the value of the BlockTransform property of
the BlockReference object to the second argument to
SetAttributesFromBlock, as I had mentioned earlier?


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Zhongwei Xia" wrote in message
news:4969406@discussion.autodesk.com...
Thank you for your email.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.