Author Topic: Run this c# 2013 routine in Autocad 2018  (Read 286 times)

0 Members and 1 Guest are viewing this topic.

jtm2018hyo

  • Newt
  • Posts: 56
Run this c# 2013 routine in Autocad 2018
« on: March 26, 2019, 08:30:47 PM »
how can I run this c# 2013 routine in CIVIL 3D or AUTOCAD VANILLA?

Code: [Select]
/*
 * Andrey Bushman, 2013
 * AutoCAD 2014 x64 Enu
 *
 * AutoCAD references:
 *
 * AcCoreMgd.dll
 * AcDbMgd.dll
 * AcMgd.dll
 * Interop.ACSMCOMPONENTS19Lib.dll
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using cad = Autodesk.AutoCAD.ApplicationServices.Application;
using App = Autodesk.AutoCAD.ApplicationServices;
using Db = Autodesk.AutoCAD.DatabaseServices;
using Ed = Autodesk.AutoCAD.EditorInput;
using Rtm = Autodesk.AutoCAD.Runtime;
using Comp = ACSMCOMPONENTS19Lib;
 
[assembly: Rtm.CommandClass(typeof(Bushman.AutoCAD.SheetSetEditor.Commands))]
 
namespace Bushman.AutoCAD.SheetSetEditor {
 
    public class Commands {
 
        const String ns = "bush"; // namespace
 
        [Rtm.CommandMethod(ns, "test", Rtm.CommandFlags.Modal)]
        public void Renumber() {
            App.Document doc = cad.DocumentManager.MdiActiveDocument;
            Db.Database db = doc.Database;
            Ed.Editor ed = doc.Editor;
            Comp.AcSmSheetSetMgr mng = new Comp.AcSmSheetSetMgr();
            Comp.IAcSmEnumDatabase enumerator = mng.GetDatabaseEnumerator();
            Comp.AcSmDatabase smDb = null;
            while ((smDb = enumerator.Next()) != null) {
                String fname = smDb.GetFileName();
                Comp.AcSmSheetSet sheetset = smDb.GetSheetSet();
                String name = sheetset.GetName();
                String descr = sheetset.GetDesc();
                ed.WriteMessage("\nSheet Set: {0}\n", name);
                Comp.IAcSmEnumComponent encomp = sheetset.GetSheetEnumerator();
                Comp.IAcSmComponent component = null;
                while ((component = encomp.Next()) != null) {
                    ProcessElement(ed, component, 0);
                }
                encomp.Reset();
            }
            enumerator.Reset();
        }
 
        // Recursive processing of the elements
        void ProcessElement(Ed.Editor ed, Comp.IAcSmComponent component, Int32 level) {
            ed.WriteMessage("\t{0}{1} (Subset)\n", new String('\t', level), component.GetName());
            Array array = null;
            component.GetDirectlyOwnedObjects(out array);
            if (array != null) {
                Int32 sheet_number = 0;
                foreach (var item in array) {
                    if (item is Comp.IAcSmSubset) {
                        ProcessElement(ed, (Comp.IAcSmSubset)item, level + 1);
                    }
                    else if (item is Comp.IAcSmSheet) {
                        Comp.IAcSmSheet sheet = (Comp.IAcSmSheet)item;
                        ed.WriteMessage("\t\t{0}{1} (Sheet)", new String('\t', level), sheet.GetName());
                        sheet.SetNumber(sheet_number.ToString()); // I get an exception here!
                        ++sheet_number;
                    }
                    else if (item is Comp.IAcSmPersist) {
                        Comp.IAcSmPersist persist = (Comp.IAcSmPersist)item;
                        ed.WriteMessage("\t\t{0}Additional info: {1}", new String('\t', level), persist.GetTypeName());
                    }
                    else {
                        ed.WriteMessage("\t\t{0}Unknown object: {1}", new String('\t', level), item.GetType().ToString());
                    }
                    ed.WriteMessage("\n");
                }
            }
        }
    }
}
 

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1264
  • class keyThumper<T>:ILazy<T>
Re: Run this c# 2013 routine in Autocad 2018
« Reply #1 on: March 26, 2019, 10:01:43 PM »
Which AutoCAD build ?

It will need to be compiled in Visual Studio with references to the suitable Librarys to match your AutoCAD build.

DUH : just re-read the title :)

« Last Edit: March 26, 2019, 10:17:55 PM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.

jtm2018hyo

  • Newt
  • Posts: 56
Re: Run this c# 2013 routine in Autocad 2018
« Reply #2 on: April 01, 2019, 10:31:21 PM »
Which AutoCAD build ?

It will need to be compiled in Visual Studio with references to the suitable Librarys to match your AutoCAD build.

DUH : just re-read the title :)


for autocad 2018- 2019- 2020

I already tried but I always have errors when try BUILD.
I need an special guide to built for autocad 2018-2019-2020?

n.yuan

  • Bull Frog
  • Posts: 270
Re: Run this c# 2013 routine in Autocad 2018
« Reply #3 on: April 02, 2019, 11:02:42 AM »
Since the code is mainly about Sheet Set via its COM API. So, it has very little to do with AutoCAD API itself. In terms of building error, you really should have include more details on what the errors are, or attach pictures to show the errors.

But, I would guess the errors would most likely come from the COM API reference "AcSmComponents2x.tlb", where 2x could be 21, 22, 23, depending on AutoCAD version. So, check the "References" in the VS project to make sure you have correct version Sheet Set COM API library references, corresponding to your AutoCAD version (for AutoCAD2018, it is 22), besides the correct version of AutoCAD .NET API references, of course.