.NET

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

Reading objacts location (X Y)

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

Valued Mentor
gasty1001
Posts: 448
Registered: ‎04-11-2010
Message 2 of 8 (288 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 (283 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 (262 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 (257 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 (250 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 (230 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 (222 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community