.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Get matrix3d from Database
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello everyone.
i gets some coordinates when i use MdiActiveDocument:
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
//
...
foreach (ObjectId oi in ids)
{
Line ln = (Line) tr.GetObject(oi, OpenMode.ForWrite);
Matrix3d m = doc.Editor.CurrentCoordinateSystem.Inverse();
Point3d pt = ln.StartPoint.TransformBy(m);
//some coordinates calculations
...
}But in case when i dont use MdiActiveDocument (i have only Database), i cant gets matrix m. Can i get this matrix "m" from db only?
am doing the next:
Database db = new Database(false, true);
db.ReadDwgFile("C:\\test.dwg", System.IO.FileShare.ReadWrite, true, "");
...
Matrix3d m = getUcsMatrix(db);
using (Transaction trLn = db.TransactionManager.StartTransaction())
{
try
{
BlockTable bt = (BlockTable)trLn.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)trLn.GetObject(bt[BlockTableReco rd.ModelSpace], OpenMode.ForWrite);
foreach (ObjectId objId in btr)
{
Entity ent = (Entity)trLn.GetObject(objId, OpenMode.ForRead);
if (ent.GetType().Name == "Line")
{
Line ln = ent as Line;
//if (ln.Layer == "0")
{
geoPoint = ln.StartPoint.TransformBy(m);
sRiga = geoPoint.X.ToString() + "," + geoPoint.Y.ToString() + ",";
geoPoint = ln.EndPoint.TransformBy(m);
sRiga += geoPoint.X.ToString() + "," + geoPoint.Y.ToString() + ";";
StreamWriter sw = new StreamWriter(FO, true);
sw.WriteLine("COORDINATE;");
sw.WriteLine(sRiga);
sw.Close();
StreamWriter swFO = new StreamWriter(FOS, true);
swFO.WriteLine("COORDINATE;");
swFO.WriteLine(sRiga);
swFO.Close();
}
}
}
}
catch (SystemException ex)
{
MessageBox.Show(ex.Message);
}
trLn.Commit();
}
public static Matrix3d getUcsMatrix (Database db)
{
System.Diagnostics.Debug.Assert(db != null);
Point3d toOrigin;
Vector3d toXAxis, toYAxis, toZAxis;
toOrigin = db.Ucsorg;
toXAxis = db.Ucsxdir;
toYAxis = db.Ucsydir;
toZAxis = toXAxis.CrossProduct(toYAxis);
return Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, toOrigin, toXAxis, toYAxis, toZAxis).Inverse();
} Maybe i have some errors in the code?
i have a little idea, maybe its wrong that i opened Entity object "forRead" only?
But if i set OpenMode.ForWrite... i have error(
and with Database my code is not working(
i wrote 2 variants of code
- with Editor
- without Editor
u can compile them and test on drawing, and u will see that results are differents(
P.S.: am working only in a Model Space
in first case we have (That's the result of a successful transformation to my UCS):
COORDINATE;
1516200.2924,5031892.933,1516385.5636,5031892.8813
COORDINATE;
1516354.1415,5032032.582,1516354.1834,5032182.7509
COORDINATE;
1516210.8185,5032032.622,1516354.1415,5032032.582;
in second case we have (That's the result of a unsuccessful transformation to my UCS):
COORDINATE;
387.0067,315.2043,530.3297,315.2043;
COORDINATE;
530.3297,315.2043,530.3297,465.3732;
COORDINATE;
376.5197,175.5124,561.7909,175.5124;
Re: Get matrix3d from Database
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
i think i know where is the problem:
when i use
Matrix3d m = getUcsMatrix(db);
getUcsMatrix retun for me m = Matrix3d.Identity;
thats why i cant trnslate coordinates.
But the other question why getUcsMatrix return wrong matrix?
Re: Get matrix3d from Database
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Get matrix3d from Database
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
yeap. now i know the difference.
thx, again




