.NET

Reply
Valued Contributor
raghulan
Posts: 74
Registered: ‎01-11-2012
Message 1 of 6 (373 Views)
Accepted Solution

Create Object and get oject id or add to collection

373 Views, 5 Replies
11-08-2012 03:18 AM

Hello ppl,

 

I trying to create an autocad obbject eg: line. after creating i need to add object data to the created object.

unfortunately i am not able to get the objectid of the created object.

 

could some one help me with a code snippet on how to do this..

 

1. creating a object and add the created object to collect or selectionset

2. get the object id or refernece so i can attach object dat relavent to the objedt...

Regards,

Raghulan Gowthaman Cert IV TAA, B.E,.
Senior BIM Specialist IT & Infrastructure
CSI Global pty Limited. - Singapore | Sydney
Web : www.csigs.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au
Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 2 of 6 (356 Views)

Re: Create Object and get oject id or add to collection

11-08-2012 07:29 AM in reply to: raghulan

Your question makes it somewhat obvious that you're new to AutoCAD .NET programming.  

 

My suggestion would be to download the learning materials Autodesk provides, as they include examples of the basic tasks you've described, and study them.

 

 

*Expert Elite*
Posts: 896
Registered: ‎04-27-2009
Message 3 of 6 (354 Views)

Re: Create Object and get oject id or add to collection

11-08-2012 07:38 AM in reply to: raghulan

What do you actually mean by "not able to get objectid of created object"? How do you create the object? After you created, do you append it into a proper layout block (modelspace or paperspace) and add it to current transaction?

 

A newly created Entity object (Line, Circle...) is only assigned an ObjectId when being appended to a Layouy block.

 

So, you need to do your task in 2 steps:

 

1. create the needed Entity and append it to appropriate space (model/paper space) and commit the transaction, so that the entity become database residing object. Then you pass the entity's ObjecId to step 2

 

2. attach ObjectData to the entity, identified by the ObjectId passed in.

Valued Contributor
raghulan
Posts: 74
Registered: ‎01-11-2012
Message 4 of 6 (345 Views)

m

11-08-2012 02:08 PM in reply to: norman.yuan

Thanks Norman for your advice.

I am indeed a newbie but I know few things..

Sorry if I didnt explain clearly...

 

I know I can only get the object ID after I append the table...all I want is how to get the object ID of last created object.

===============================================================================

//open block table
BlockTable blktbl;


blktbl = tr.GetObject(Global.variables.db.BlockTableId, caddb.OpenMode.ForRead) as BlockTable;

 

//open blk table for write
BlockTableRecord blktblrec = tr.GetObject(blktbl[BlockTableRecord.ModelSpace], caddb.OpenMode.ForWrite) as BlockTableRecord;

 

//create line
Autodesk.AutoCAD.DatabaseServices.Line line = new Autodesk.AutoCAD.DatabaseServices.Line(startPoint, EndPoint);
line.Layer = Global.variables.pipes_layer; //get the layer name

line.SetDatabaseDefaults();

//add new object to the block table
blktblrec.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);

=================================================================================

 

please advice me how to get the object id of last created object..

 

Thanks all

Regards,

Raghulan Gowthaman Cert IV TAA, B.E,.
Senior BIM Specialist IT & Infrastructure
CSI Global pty Limited. - Singapore | Sydney
Web : www.csigs.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au
*Expert Elite*
Posts: 896
Registered: ‎04-27-2009
Message 5 of 6 (335 Views)

Re: m

11-08-2012 02:26 PM in reply to: raghulan

line.ObjectId is what you need (after the line being added into drawing database).

Valued Contributor
raghulan
Posts: 74
Registered: ‎01-11-2012
Message 6 of 6 (330 Views)

Re: get lat created object

11-08-2012 03:01 PM in reply to: norman.yuan

Thanks Norman, 

 

I was trying to get line.objectId before tr.commit() thats why I was getting "0"

 

just for some one who may need

 

======================

 

//open block table
BlockTable blktbl;
blktbl = tr.GetObject(Global.variables.db.BlockTableId, caddb.OpenMode.ForRead) as BlockTable;

//open blk table for write
BlockTableRecord blktblrec = tr.GetObject(blktbl[BlockTableRecord.ModelSpace], caddb.OpenMode.ForWrite) as BlockTableRecord;

//create line
Autodesk.AutoCAD.DatabaseServices.Line line = new Autodesk.AutoCAD.DatabaseServices.Line(startPoint, EndPoint);
//line.Layer = Global.variables.pipes_layer;

line.SetDatabaseDefaults();
Global.variables.mess_out(line.ObjectId.ToString());
//add new object to the block table
blktblrec.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);

tr.Commit(); // make sure you commit

 

line.ObjectId //will fetch you the object id of the line object.

 

=========================

 

Regards,

Raghulan Gowthaman Cert IV TAA, B.E,.
Senior BIM Specialist IT & Infrastructure
CSI Global pty Limited. - Singapore | Sydney
Web : www.csigs.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au

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 interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

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

Ask the Community