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

add text to points, without block creation.

6 REPLIES 6
Reply
Message 1 of 7
newautocad123
527 Views, 6 Replies

add text to points, without block creation.

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

6 REPLIES 6
Message 2 of 7
Hallex
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
Message 3 of 7
newautocad123
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);

 

Message 4 of 7

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 7

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.

Message 6 of 7

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 7

Thanks,

 

The size was the issue.

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