I am working on a ZT Node that imports AutoCAD groups containing line pairs into a list. This is to supply a Dynamo script with (parallel) lines in which to derive a centerline, creating walls in Revit. Have tried to “merge” code examples from @keanw and Virupaksha Aithal but can’t get over the finish line.
Any help or direction is appreciated!
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.DesignScript.Geometry;
using System.Collections.Generic;
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Runtime;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
namespace CADLineGroups
{
/// <summary>
/// Gets entity groups from CAD file and makes a list of respective pairs.
/// </summary>
/// <returns>Pairs of grouped lines</returns>
/// <search>AutoCAD, Walls, Lines</search>
///
public class ZTNode1
{
private ZTNode1()
{
}
private static AcadApplication GetAcApp()
{
return GetAcApp();
}
private static void SetAcApp(AcadApplication value)
{
SetAcApp(value);
}
public static ObjectId EntList()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
//AutoCAD Application
const string progID = "AutoCAD.Application.24.0";
SetAcApp(null);
try
{
SetAcApp((AcadApplication)Marshal.GetActiveObject(progID));
}
catch
{
try
{
Type acType = Type.GetTypeFromProgID(progID);
SetAcApp(
(AcadApplication)Activator.CreateInstance(acType, true));
}
catch
{
const string W = "Cannot create object of type";
return W;
}
}
if (GetAcApp() != null)
{
// By the time this is reached AutoCAD is fully
// functional and can be interacted with through code
GetAcApp().Visible = true;
//acApp.ActiveDocument.SendCommand("_MYCOMMAND ");
}
using Transaction tr = db.TransactionManager.StartTransaction();
DBDictionary groups = tr.GetObject(db.GroupDictionaryId, OpenMode.ForRead) as DBDictionary;
foreach (DBDictionaryEntry entry in groups)
{
Group group = (Group)tr.GetObject(
entry.Value, OpenMode.ForRead);
ObjectId[] ents = group.GetAllEntityIds();
foreach (ObjectId id in ents)
{
//get each entity....
}
return EntList;
}
}
}
}