Reading objacts location (X Y)

Reading objacts location (X Y)

Anonymous
Not applicable
1,204 Views
7 Replies
Message 1 of 8

Reading objacts location (X Y)

Anonymous
Not applicable

 

hi, a noob quation:

i want to write a command in C# that alow user to do 2 things:
1. choose a layer to work on
2. make a list/table of all objects in that layer, and their X Y coordinates.

for example - if a DWG file contain few layers, one of them has names (and only names). there are ~1500 objacts (text type) in that layer. every objact have a string (100,101,...,1350,1351...) and locating (X and Y). I want to be able to pick this layer, then bild a text file like this: (name X Y)
100 20456 40789
101 20344 40348
102 21034 40456
.
.
.

its dont has to be sorted. how do I do it? can you give me the solution or any lift to proggress? 

thanks 🙂

0 Likes
1,205 Views
7 Replies
Replies (7)
Message 2 of 8

hgasty1001
Advisor
Advisor

Hi,

 

Are you sure you need an application to do that?, i think that is a good task for the dataextraction command.

 

-gnb

0 Likes
Message 3 of 8

Anonymous
Not applicable
thanks for your answer. My aim is to create a data stracture that holds all this info, for calculations and so. In the far end, I want it to be an auto script that bild that proccesed text file.

For start, how do I read the atributs of an entity? How do I choose a layer, and read every object from it?

Thanks, EATTEXT will help me for now, and I do wait for your help to continue.
0 Likes
Message 4 of 8

jamierobertson1
Enthusiast
Enthusiast

You can quite get the objectIDs of all text on a layer passing a SelectionFilter to the Editor.selectAll method::

 

TypedValue[] tv = new TypedValue[] {new TypedValue((int)DxfCode.Start, "TEXT"), new TypedValue((int)DxfCode.LayerName, "Layer 1")};

SelectionFilter sf = new SelectionFilter(tv);
SelectionSet set = ed.SelectAll(sf).Value;

 You can then open the text entities from the objectIDs in the selectionSet and then access their properties.

 

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

ok Man Happy

 

and how can I let the user to pick the layer he wants to work with?

0 Likes
Message 6 of 8

jamierobertson1
Enthusiast
Enthusiast

You could either get the user to type in a layer name using Editor.GetString() or you could put a combobox on a form and get the user to pick one or smething like that.

 

You can get all layer names by iterating through all the LayerTableRecords in the LayerTable:

 

List<string> names = new List<string>();
LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead);
foreach(ObjectId id in lt)
{
     LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(id, OpenMode.ForRead);
     names.Add(ltr.Name);
}
0 Likes
Message 7 of 8

Anonymous
Not applicable

@jamierobertson1 wrote:

You can quite get the objectIDs of all text on a layer passing a SelectionFilter to the Editor.selectAll method::

 

TypedValue[] tv = new TypedValue[] {new TypedValue((int)DxfCode.Start, "TEXT"), new TypedValue((int)DxfCode.LayerName, "Layer 1")};

SelectionFilter sf = new SelectionFilter(tv);
SelectionSet set = ed.SelectAll(sf).Value;

 You can then open the text entities from the objectIDs in the selectionSet and then access their properties.

 


 

Sorry for the begginer question, beside "Hello World" its my first program in this enviroment. Do I write it in a CommandMethod?  What do I do with the objectIDs?

 

thanks.

0 Likes
Message 8 of 8

jamierobertson1
Enthusiast
Enthusiast

Have a look at some of the .net training material and samples here

 

http://http://usa.autodesk.com/adsk/servlet/index?id=1911627&siteID=123112

0 Likes