.NET

Reply
Contributor
GeoSchaap
Posts: 18
Registered: ‎06-02-2011
Message 1 of 8 (327 Views)

Reading objacts location (X Y)

327 Views, 7 Replies
06-04-2011 05:38 AM

 

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 :smileyhappy:

Distinguished Mentor
gasty1001
Posts: 534
Registered: ‎04-11-2010
Message 2 of 8 (300 Views)

Re: Reading objacts location (X Y)

06-04-2011 05:45 PM in reply to: GeoSchaap

Hi,

 

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

 

-gnb

Contributor
GeoSchaap
Posts: 18
Registered: ‎06-02-2011
Message 3 of 8 (295 Views)

Re: Reading objacts location (X Y)

06-04-2011 09:07 PM in reply to: GeoSchaap
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.
Active Contributor
jamierobertson1
Posts: 39
Registered: ‎04-11-2004
Message 4 of 8 (274 Views)

Re: Reading objacts location (X Y)

06-05-2011 07:20 AM in reply to: GeoSchaap

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.

 

 

Contributor
GeoSchaap
Posts: 18
Registered: ‎06-02-2011
Message 5 of 8 (269 Views)

Re: Reading objacts location (X Y)

06-05-2011 08:09 AM in reply to: jamierobertson1

ok :manhappy:

 

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

Active Contributor
jamierobertson1
Posts: 39
Registered: ‎04-11-2004
Message 6 of 8 (262 Views)

Re: Reading objacts location (X Y)

06-05-2011 09:05 AM in reply to: GeoSchaap

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);
}
Contributor
GeoSchaap
Posts: 18
Registered: ‎06-02-2011
Message 7 of 8 (242 Views)

Re: Reading objacts location (X Y)

06-05-2011 11:13 PM in reply to: jamierobertson1

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.

Active Contributor
jamierobertson1
Posts: 39
Registered: ‎04-11-2004
Message 8 of 8 (234 Views)

Re: Reading objacts location (X Y)

06-06-2011 12:56 AM in reply to: GeoSchaap

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.