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

Create Object and get oject id or add to collection

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
raghulan
1284 Views, 5 Replies

Create Object and get oject id or add to collection

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 Technical Consultant | Developer - R&D
A2K Technologies Sydney
Web : www.a2ktechnologies.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au
www.raghulangowthaman.com
5 REPLIES 5
Message 2 of 6

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.

 

 

Message 3 of 6
norman.yuan
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.

Message 4 of 6
raghulan
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 Technical Consultant | Developer - R&D
A2K Technologies Sydney
Web : www.a2ktechnologies.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au
www.raghulangowthaman.com
Message 5 of 6
norman.yuan
in reply to: raghulan

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

Message 6 of 6
raghulan
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 Technical Consultant | Developer - R&D
A2K Technologies Sydney
Web : www.a2ktechnologies.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au
www.raghulangowthaman.com

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