.NET

.NET

Reply
Valued Contributor
newautocad123
Posts: 58
Registered: ‎09-03-2012
Message 1 of 7 (232 Views)

add text to points, without block creation.

232 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*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 7 (221 Views)

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
newautocad123
Posts: 58
Registered: ‎09-03-2012
Message 3 of 7 (215 Views)

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*
Alfred.NESWADBA
Posts: 9,595
Registered: ‎06-29-2007
Message 4 of 7 (211 Views)

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
newautocad123
Posts: 58
Registered: ‎09-03-2012
Message 5 of 7 (207 Views)

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*
Alfred.NESWADBA
Posts: 9,595
Registered: ‎06-29-2007
Message 6 of 7 (202 Views)

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
newautocad123
Posts: 58
Registered: ‎09-03-2012
Message 7 of 7 (198 Views)

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
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.