.NET

.NET

Reply
Valued Contributor
58 Posts
0 Kudos
Registered: ‎09-03-2012
Post 1 of 7

add text to points, without block creation.

238 Views, 6 Replies
10-14-2012 09:22 PM
{
                    Entity e = (Entity)tr.GetObject(id, OpenMode.ForRead);
    
                    DBPoint p = (DBPoint)e;
                    ed.WriteMessage(" p.Position.X --> " + p.Position.X + " / Y= " + p.Position.Y + " / Z= " + p.Position.Z);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = new Point3d(Convert.ToDouble(p.Position.X), Convert.ToDouble(p.Position.Y), 0);
                    acText.Height = 0.5;
                    acText.TextString = "Hello, World.";
                    ents.Add(acText);

                    acBlkTblRec.AppendEntity(acText);
                    tr.AddNewlyCreatedDBObject(acText, true);
                }
                tr.Commit();

 In the above I can add text to the drawing with the blocks defined as below:

BlockTable acBlkTbl;
                acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

 Can I add text to a dwg file which has shp data imported, without using a block. The above code to add text to a new file with points works well.

But if my file has some points imported from a SHP file, the text does not get created.

Please suggest a way to add a text to this dwg file with imported shp data.

 

Thanks.

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 2 of 7

Re: add text to points, without block creation.

10-14-2012 10:57 PM in reply to: newautocad123

Try to transform your point:

 

acText.Position = new Point3d(Convert.ToDouble(p.Position.X), Convert.ToDouble(p.Position.Y)), 0.TransformBy(Matrix3d.Inverse);

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
58 Posts
0 Kudos
Registered: ‎09-03-2012
Post 3 of 7

Re: add text to points, without block creation.

10-14-2012 11:36 PM in reply to: Hallex

the above does not work. It is possible that I can replace this line. add the entity to a block. 

 

 acBlkTblRec.AppendEntity(acText);

 

*Expert Elite*
9,836 Posts
1,219 Kudos
Registered: ‎06-29-2007
Post 4 of 7

Re: add text to points, without block creation.

10-14-2012 11:55 PM in reply to: newautocad123

Hi,

 

>> But if my file has some points imported from a SHP file, the text does not get created.

That makes me thinking that there is any other problem but not AutoCAD (plain AutoCAD).

  • First: to import SHP-data needs Map3D or Civil3D or a 3rd-party app. So what product did you use (including version and servicepack as info)?
  • Next: you may have really imported using command _MAPIMPORT or you have it referenced via _DATACONNECT or it was a function of an external app, what did you use?
  • Last but not least: "the text does not get created" ... just ot make sure: you don't see the text (then zoom to the coordinates or run _FIND for "Hello World", make sure none of the layers are off or frozen) or you get an error message ==> which one?

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
58 Posts
0 Kudos
Registered: ‎09-03-2012
Post 5 of 7

Re: add text to points, without block creation.

10-15-2012 12:14 AM in reply to: Alfred.NESWADBA

1. Version: autocad3D 2012

2. with MAPIMPORT, imported the point data and zoom , extent to get it in the current display. Also attached the object data also, which is with the SHP file.

3. I want to add a point near to these points with a text that displays Hello world.

 

With the objectid's of these point, I get the x,y and z values which I use to define the position of the text .

 

acText.Position = new Point3d(Convert.ToDouble(p.Position.X), Convert.ToDouble(p.Position.Y), 0);

 but the text does not get created if the dwg contains the imported points.

 

else on any other dwg I can create text and also add text to the points created with POINT command.

 

 

Thanks.

*Expert Elite*
9,836 Posts
1,219 Kudos
Registered: ‎06-29-2007
Post 6 of 7

Re: add text to points, without block creation.

10-15-2012 12:29 AM in reply to: newautocad123

Hi,

 

>> but the text does not get created

Take a look to my response above, to all questions/all suggestions, e.g. using the _FIND command to search for the text.

I think as you have set the text-height to 0.5 and you are using shape-data that zoom extents is so big that a text with height of 0.5 is just not visible, but it's there, ...especially because you don't get an error message, or do you?

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
58 Posts
0 Kudos
Registered: ‎09-03-2012
Post 7 of 7

Re: add text to points, without block creation.

10-15-2012 12:47 AM in reply to: Alfred.NESWADBA

Thanks,

 

The size was the issue.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!