Loop/filter/query Map object data

Loop/filter/query Map object data

pieter_souvereyns
Enthusiast Enthusiast
658 Views
2 Replies
Message 1 of 3

Loop/filter/query Map object data

pieter_souvereyns
Enthusiast
Enthusiast

It look's to me that there is no way to query the objects that have objectdata (OD).
That you have to loop trough all object and look if they have objectdata.
Is this correct or do I miss something?
A dxfcode or a method like PropertyDataServices.GetAllPropertySetsUsingDefinition for propertiesets?
Thanks
Pieter

0 Likes
659 Views
2 Replies
Replies (2)
Message 2 of 3

АлексЮстасу
Advisor
Advisor

Hi, Pieter,


Which problem do you want to solve in the end?
I'm not a programmer, and I don't know how it works inside, but we did Search OD - group of commands for selecting graphical elements by OD criteria.

ODEDIT_menu_demo_eng_Search.png

Do you want to do this or solve other problems?

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

0 Likes
Message 3 of 3

fieldguy
Advisor
Advisor

The last project I worked on was a data importer. Before the import occurs, the existing data in the dwg is checked for duplicates (don't import if that entity exists already). This is accomplished by checking a field in an object data table.

Using a documentlock and a transaction (tr) you can obtain a list of all entities that have object data from the modelspace blocktable record:

// using acapp = Autodesk.AutoCAD.ApplicationServices;

// using acdb = Autodesk.AutoCAD.DatabaseServices;

// reference managedmapapi.dll

// using acgis = Autodesk.Gis.Map;

 

acapp.Document doc = acapp.Application.DocumentManager.MdiActiveDocument;
acdb.Database db = doc.Database;
using (acapp.DocumentLock docloc = doc.LockDocument())
{
	using (acdb.Transaction tr = db.TransactionManager.StartTransaction())
        {
        	acgis.MapApplication mapapp = acgis.HostMapApplicationServices.Application;
                acgis.Project.ProjectModel mapprj = mapapp.ActiveProject;
                Tables tbls = mapprj.ODTables;
                acdb.BlockTable bt = (acdb.BlockTable)tr.GetObject(db.BlockTableId, acdb.OpenMode.ForRead);
                acdb.BlockTableRecord mspace = (acdb.BlockTableRecord)tr.GetObject(bt[acdb.BlockTableRecord.ModelSpace], acdb.OpenMode.ForRead);
                acgis.ObjectData.Records recs = tbls.GetObjectRecords(0, mspace.ObjectId, acgis.Constants.OpenMode.OpenForRead, false);
                acdb.ObjectIdCollection recobjids = new acdb.ObjectIdCollection();
                recs.CountObjects(recobjids);	// CountObjects returns an objectidcollection
                recs.Dispose();
                foreach (acdb.ObjectId oid in recobjids)
                {
                	acdb.DBObject fobj = (acdb.DBObject)tr.GetObject(oid, acdb.OpenMode.ForRead);
                        acgis.ObjectData.Table t = null;
                        try
                        {
                            t = tbls["TABLE NAME"];
                            acgis.ObjectData.Records objrecs = t.GetObjectTableRecords(0, fobj, acgis.Constants.OpenMode.OpenForRead, false);
                            if (objrecs.Count > 0)
                            {
                                foreach (acgis.ObjectData.Record rec in objrecs)
                                {
                                    acgis.Utilities.MapValue myval = rec[0];  // the unique id is the first field in the definitions list
                                    flights.Add(myval.StrValue);   // add values to a list to be checked when importing
                                }// foreach record
                            }// if records are found
                            objrecs.Dispose();
                        }// try
                        catch { }   // table doesn't exist
                      
                    }// foreach object
                    tr.Commit();
                }// using tr
            }// using docloc


Other notes:

StringCollection sc = tbls.GetTableNames();   // a list of all object data tables

ADEDEFDATA (autocad command to see object data tables and definitions)

 

There are other code samples available in this forum but you have to search.

@АлексЮстасу has a link to "odclass-odedit.com" which may do what you require.

@norman.yuan has contributed lots of code (example >>here<< ).

 

IMHO - it's odd that Autodesk has never produced an FDO driver for their own data (DWG).

0 Likes