{ 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.
Try to transform your point:
acText.Position = new Point3d(Convert.ToDouble(p.Position.X), Convert.ToDouble(p.Position.Y)), 0.TransformBy(Matrix3d.Inverse);
the above does not work. It is possible that I can replace this line. add the entity to a block.
acBlkTblRec.AppendEntity(acText);
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).
- alfred -
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.
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 -
Can't find what you're looking for? Ask the community or share your knowledge.