Read start- / endpoint coordinates of edges from space using .NET

Read start- / endpoint coordinates of edges from space using .NET

Anonymous
Not applicable
562 Views
3 Replies
Message 1 of 4

Read start- / endpoint coordinates of edges from space using .NET

Anonymous
Not applicable

Dear community,

I am trying do display room "shapes" from a Autocad file in a custom .net application (Floorplan). I managed to read out polylines using .NET (C#), but I have no Idea how to read a Space (Architecture, not Model- or Paperspace). with Properties and a roomtag. I am looking to get the points (start / end) of the single edges that make up the space to sort of "overlay" them on a pdf that is show in our application.

OR... maybe you have a better solution how to do this, even other software recomendations (with a short reason).

THANK YOU IN ADVANCE!!!

Best regards
Gerrit

0 Likes
563 Views
3 Replies
Replies (3)
Message 2 of 4

cadMeUp
Collaborator
Collaborator

This might serve as a start point...

 

Document doc = AcadApp.DocumentManager.CurrentDocument;
BlockTable bt = doc.Database.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForRead) as BlockTableRecord;

foreach (ObjectId id in btr)
{
	if (id.ObjectClass.GetRuntimeType() == typeof(Autodesk.Aec.Arch.DatabaseServices.Space))
	{
		Autodesk.Aec.Arch.DatabaseServices.Space spaceObj = id.GetObject(OpenMode.ForRead) as Space;
		Autodesk.Aec.Geometry.Profile prof = spaceObj.GetProfile(Autodesk.Aec.Arch.DatabaseServices.SpaceProfileType.Base);

		Matrix2d mat = Matrix2d.Displacement(new Point2d(spaceObj.Location.X, spaceObj.Location.Y) - Point2d.Origin);

		foreach (Autodesk.Aec.Geometry.CompoundCurve2dVertex v in prof.Vertices)
		{
			Point2d p = v.Point.TransformBy(mat);
			doc.Editor.WriteMessage("\n{0}", p);
		}
	}
}
Message 3 of 4

Anonymous
Not applicable

CadMeUp,

thank you so much for proposing something. I am very new to the Autocad programming though I am very experienced with .NET. I started testing your solution to see where it leads me. Unfortunately I am receiving a NullReferenceException when calling GetObject on the BlockTableID. It shows a valid object and ID in the Debugger for doc.Database.BlockTableId though. No idea why this happens. Do I need to set prerequisites in my AutoCAD file?!

Thanks again and best regards

Gerrit

0 Likes
Message 4 of 4

cadMeUp
Collaborator
Collaborator

Oh, yeah, the code I posted was partial thinking you would have it within an active transaction, that's probably why the null reference?? The attached is more complete.

 

0 Likes