.NET

Reply
Valued Contributor
Nawara17
Posts: 52
Registered: ‎03-27-2006
Message 1 of 5 (106 Views)

transforming DWG Entities to Blocks

106 Views, 4 Replies
07-16-2006 04:18 PM
Hi everyone,
Please, can somebody help? i am a programmer, and i am novice in autocad drawings. I had attached a drawing, that i don't know how it was created. it seems that the entities were grouped. but they are not blocks. am I right????

i want to read each group of entities and add a block definition for it if i didn't read similar group before and the group of entities that i read should be a block reference. can i do that using C#?? and are these groups of entities or blocks??
or everything that i said is wrong??

Thanks in advance :smileyhappy:
Valued Contributor
Nawara17
Posts: 52
Registered: ‎03-27-2006
Message 2 of 5 (106 Views)

Re: transforming DWG Entities to Blocks

07-16-2006 04:40 PM in reply to: Nawara17
Sorry this is the attachment.
Valued Contributor
mjwalsh51
Posts: 79
Registered: ‎03-24-2006
Message 3 of 5 (106 Views)

Re: transforming DWG Entities to Blocks

07-17-2006 08:31 PM in reply to: Nawara17
Nawara17,

The entities are not grouped or made into blocks. Go to help & you will see that creating blocks are pretty straightforward.
You can tell what an entity is selected by clicking on it & it is hilighted. if the properties window is open you will see what type of entity or entities are there. If you are really good with C# it would be nice if you would share some of your successes.

The advantage to blocks usually is attaching associated data & subnesting other blocks etc. Also the ability to reuse the already defined group of entities called a block.

I do not know of a situation where it makes sense to initially create block with any type of programming.

I personally think that connecting just the entity's xdata directly to a relational database makes more sense than blocks but requires some programming ability.
Valued Contributor
Nawara17
Posts: 52
Registered: ‎03-27-2006
Message 4 of 5 (106 Views)

Re: transforming DWG Entities to Blocks

07-18-2006 02:52 PM in reply to: Nawara17
thanks Mike, I found that there are entities when I created this peace of code.

using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Collections;
using AcadAPP=Autodesk.AutoCAD.ApplicationServices.Application;

namespace ClassLibrary4
{
///
/// Summary description for Class1.
///

public class Class1:Autodesk.AutoCAD.Runtime.IExtensionApplication
{
public void Initialize()
{
Autodesk.AutoCAD.Interop.AcadApplication AcadApp=(Autodesk.AutoCAD.Interop.AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.16.2");
Autodesk.AutoCAD.Interop.AcadDocument AcadDoc=AcadApp.ActiveDocument;
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
//MessageBox.Show();
foreach (ObjectId id in btr)
{
MessageBox.Show("HI");
Entity ent = (Entity)trans.GetObject(id, OpenMode.ForWrite, false);
////////////////////////////////The following code i copied it from RonaldF Message in
////////////// http://discussion.autodesk.com/thread.jspa?messageID=5205357
ObjectId[] ids = new ObjectId[1];

ids[0] = ent.Id;

SubentityId index = new SubentityId(SubentityType.Edge, 0);

FullSubentityPath path = new FullSubentityPath(ids, index);

ent.Highlight(path, true);
///////////////////////////////////////////////////////////////////////////////


}
}
finally
{
trans.Dispose();
}
}
public void Terminate()
{
}
}


I found that when each message box appear the whole shelves where highlighted.

if I create the code which i asked to I will post it here in this discussion. Nawara17
Valued Contributor
Nawara17
Posts: 52
Registered: ‎03-27-2006
Message 5 of 5 (106 Views)

Re: transforming DWG Entities to Blocks

07-18-2006 05:40 PM in reply to: Nawara17
ent.equals(anotherEnt);
ent.CompareTo(anotherEnt);

these two statments are comparing the objects not the shapes of the entities.

Please, Can anybody tell me, how could i know by comparing two entities that their shapes are similar??

Thanks in advance.

Nawara==>Noora
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.