Author Topic: Accessing CadMep Properties  (Read 3069 times)

0 Members and 1 Guest are viewing this topic.

mariana

  • Guest
Accessing CadMep Properties
« on: August 21, 2013, 10:21:43 AM »
Does anyone know a way to access/loop over the CadMep+ properties in Autocad?

I have no issues accessing the ‘General’ properties of entities but the CadMep ones cannot seem to be read.

People have mentioned the AddModifyPart sample which is supposed to come with AutoCAD MEP but this doesn’t exist on my installation. I’m using AutoCAD MEP 2014.



Here's the code I use to get the 'General' properties:


Code: [Select]
static private void GetEverything(ObjectId msId) {

Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

using (Transaction tr = doc.TransactionManager.StartTransaction()) {
 
        BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

  BlockTableRecord btrMs = (BlockTableRecord)tr.GetObject(msId, OpenMode.ForWrite);

// Test each entity in the container...
foreach (ObjectId entId in btrMs) {

Entity ent = tr.GetObject(entId, OpenMode.ForRead) as Entity;

Type tType = ent.GetType();

if (ent != null) {
 
ObjectId entityId = ent.Id;
String entLayer = ent.Layer;
String entType = tType.Name;
String objName = entityId.ObjectClass.Name;

//String entBlockName = ent.BlockName; // all are *Model_Space
//ObjectId entBlockId = ent.BlockId; // all are (8796087795216)
//Object entAcadObj = ent.AcadObject; // all are System.__ComObject
//Type entAcadType = entAcadObj.GetType(); // all are System.__ComObject

// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("D:\\Autodesk\\ms_rnd\\output.txt", true);                               
file.WriteLine(entityId + ": " + entType + ": " + entLayer + ": " + objName);
file.Close();
}
       }
}
}

All the CadDuct objects have a type of 'ImpEntity' and ObjectClass Name of 'MapsContainer'


jabowabo

  • Mosquito
  • Posts: 20
Re: Accessing CadMep Properties
« Reply #1 on: August 22, 2013, 08:52:00 PM »
I hope you get a better answer but I spent a good deal of time trying to access CADmep objects directly and could not find a way.  I contacted Andy Robbins (formerly of MAP and now with Autodesk) and he informed me that it was not possible at this time.  I was able to accomplish my end goal through a combination of .Net and the CSVEXPORT function of CADmep.  Basically, I just ran CSVEXPORT and used StreamReader to get the data into my program.  If you want to see the end results see here:  http://www.xtracad.com/forum/index.php/topic,11399.msg79080.html#msg79080

Also, you might find the following helpful:
http://www.theswamp.org/index.php?topic=44287.msg496105#msg496105
http://www.xtracad.com/forum/index.php/topic,11167.msg75505.html#msg75505

Good luck!

mariana

  • Guest
Re: Accessing CadMep Properties
« Reply #2 on: August 23, 2013, 09:41:20 AM »
Thanks for the advice! I'll check out the links and post any progress here :)

mariana

  • Guest
Re: Accessing CadMep Properties
« Reply #3 on: August 27, 2013, 06:02:21 AM »
I followed Jason's advice and using CSVExport in AutoCAD and then importing the csv in .NET works ok. However this does not give me access to the points the objects occupies in space...

So I'll probably try to make do without accessing the CADmep properties.

jabowabo

  • Mosquito
  • Posts: 20
Re: Accessing CadMep Properties
« Reply #4 on: August 31, 2013, 09:37:38 AM »
You can access objects via their object IDs. The key is getting the object IDs to line up with your csv file.  You can do this by making sure the csvexport format is NOT sorted in the CADmep settings which will generate a csv that is in the same order of the selection set that is passed to the csvexport command. This will allow you to create a datatable with object IDS and CADmep properties.