When obtaining coordinates in IJCAD 2018 Mechanical, coordinates far away from the drawing are acquired.

Asked 1 years ago, Updated 1 years ago, 84 views

We are developing C# at IJCAD 2018 Mechanical.


when obtaining rectangular coordinates for the entire drawing on the program You may get coordinates far away from the drawing.

Even if you open the drawing and make a quick selection or run E with the ZOOM command,
There is nothing in that coordinate.
Even if you run the PURGE command to save the drawing and then program it again,
As expected, large coordinates will be acquired.

The program for obtaining rectangular coordinates in the drawing is as follows:

minX=double.MaxValue;
minY = double.MaxValue;
maxX = double.MinValue;
maxY = double.MinValue;
Document acDoc=GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb=acDoc.Database;
try
{
    // lock a document
    using(acDoc.LockDocument())
    using(Transaction acTrans=acCurDb.TransactionManager.StartTransaction())
    using (LayerTable acLayTbl=acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable)
    {
        // Get Object
        PromptSelectionResult acRes=acDoc.Editor.SelectAll();
        if(acRes.Value.Count!=0)
        {
            foreach(ObjectId acObjId in acRes.Value.GetObjectIds())
            {
                using (Entity acEnt=acTrans.GetObject(acObjId, OpenMode.ForRead) as Entity)
                {
                    // exclude hiding
                    if(acLayTbl.Has(acEnt.Layer))
                    {
                        using (LayerTableRecord acLyrTblRec = acTrans.GetObject (acLayTbl [acEnt.Layer], OpenMode.ForWrite) as LayerTableRecord)
                        {
                            if(acLyrTblRec.IsOff)
                            {
                                continue;
                            }
                        }
                    }
                    if (acEnt.Visible==false)
                    {
                        continue;
                    }

                    if(acEnt.Bounds.HasValue)
                    {
                        if (acEnt.GeometricExtents.MinPoint.X.CompareTo(minX)<0)
                        {
                            minX=acEnt.GeometricExtents.MinPoint.X;
                        }
                        if (acEnt.GeometricExtents.MaxPoint.X.CompareTo(maxX)>0)
                        {
                            // get a funny value
                            maxX=acEnt.GeometricExtents.MaxPoint.X;
                        }
                        if (acEnt.GeometricExtents.MinPoint.Y.CompareTo(minY)<0)
                        {
                            minY = acEnt.GeometricExtents.MinPoint.Y;
                        }
                        if (acEnt.GeometricExtents.MaxPoint.Y.CompareTo(maxY)>0)
                        {
                            // get a funny value
                            maxY = acEnt.GeometricExtents.MaxPoint.Y;
                        }
                    }
                }
            }
        }
    }
}

If you look at maxX or maxY on the above program,
In addition to around 500 objects, nearly 7000 objects will be mixed.

How do I remove the object from the drawing?
Or you can judge and exclude the object on the program. Is it possible?

c# .net ijcad

2022-09-30 14:07

1 Answers

If you want to get all the figures, you may want to use an iterator of the object for the model space or layout space block.
If you pass a graphic filter to SelectAll(), exclude hidden layers (with GC8 specifying hidden layers and -4 NOT expression), and temporarily exclude hidden (GC60) figures, you don't have to exclude them in the loop.
You can add graphic boundaries, so why don't you use them?

public void cmdGetExtents2()
    {
        var doc = Application.DocumentManager.MdiActiveDocument;
        variable = doc.Editor;
        varres=ed.SelectAll();
        variable = new Extents 3d();
        using(vartr=doc.TransactionManager.StartTransaction())
        {
            foreach (SelectedObject objins.Value)
            {
                variant=tr.GetObject(obj.ObjectId, OpenMode.ForRead) as Entity;
                ext.AddExtents(ent.GeometricExtents);
            }
            ed.WriteMessage("\nEXT={0}", ext.ToString());
            tr.Commit();
        }
    }


2022-09-30 14:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.