AXDB type library

AXDB type library

officedrone
Participant Participant
2,229 Views
14 Replies
Message 1 of 15

AXDB type library

officedrone
Participant
Participant

I am having issues loading a type library for AxDB. Not sure about the capitalization.

My motivation for doing this is to access some numeric bom values that are too clunky to handle with vlax.

I already finished off the problem of inserting numeric bom values with autohotkey, but the time to run is several minutes for a simple drawing, which is not really good enough.

Meanwhile, back at the .NET app, I also struggled to load SymBBAuto, but managed to pull it off like this:

 

#+name: prepare-symbbauto

#+begin_src shell :results output :eval never-export :exports both

/c/Program\ Files\ \(x86\)/Microsoft\ SDKs/Windows/v10.0A/bin/NETFX\ 4.8.1\ Tools/TlbImp.exe \

/out:P:\\PersonalData\\AcmBomNum\\bin\\Debug\\net4.8.1\\SymBBAutoENU.dll /namespace:SymBBAuto /machine:Agnostic \

C:\\Program\ Files\\Autodesk\\AutoCAD\ 2023\\Acadm\\symbbautoenu.dll 2>&1

#+end_src

 

#+RESULTS: prepare-symbbauto

: Microsoft (R) .NET Framework Type Library to Assembly Converter 4.8.9037.0^M

: Copyright (C) Microsoft Corporation. All rights reserved.^M

: ^M

: TlbImp : Type library imported to P:\PersonalData\AcmBomNum\bin\Debug\net4.8.1\SymBBAutoENU.dll^M

 

Uh yes, sorry about the org stuff. However, I was not as successful with axdb:


#+name: prepare-axdb
#+begin_src shell :results output :eval never-export :exports both
/c/Program\ Files\ \(x86\)/Microsoft\ SDKs/Windows/v10.0A/bin/NETFX\ 4.8.1\ Tools/TlbImp.exe \
/productversion:1.0.0 /machine:Agnostic /out:P:\\PersonalData\\AcmBomNum\\bin\\Debug\\net4.8.1\\AxDb.dll \
/c/Users/myusername/ObjectARX/ObjectARX_for_AutoCAD_2023_Win_64bit_dlm/inc-x64/acax24ENU.tlb 2>&1
#+end_src

#+RESULTS: prepare-axdb
: Microsoft (R) .NET Framework Type Library to Assembly Converter 4.8.9037.0
: Copyright (C) Microsoft Corporation. All rights reserved.
:
: TlbImp : warning TI3019 : Interface 'IAcadShadowDisplay' is marked as [dual], but does not derive from IDispatch. It will be converted as an IUnknown-derived interface.
: TlbImp : Type library imported to P:\PersonalData\AcmBomNum\bin\Debug\net4.8.1\AxDb.dll

 

I also naïvely tried the one in the program files dir:

#+name: prepare-this-axdb
#+begin_src shell :results output verbatim :eval never-export :exports both
/c/Program\ Files\ \(x86\)/Microsoft\ SDKs/Windows/v10.0A/bin/NETFX\ 4.8.1\ Tools/TlbImp.exe \
/c/Program\ Files/Autodesk/AutoCAD\ 2023/axdb.dll 2>&1
echo
#+end_src

#+RESULTS: prepare-this-axdb
: Microsoft (R) .NET Framework Type Library to Assembly Converter 4.8.9037.0
: Copyright (C) Microsoft Corporation. All rights reserved.
:
: TlbImp : error TI1002 : The input file 'C:\Program Files\Autodesk\AutoCAD 2023\axdb.dll' is not a valid type library.
:

 

Now, I am probably doing at least 300 things wrong at once, but if I can wrap my head around how to make this ObjectARX stuff compatible with .NET, or figure some other way of getting the required type info, I'll be on my way to chip away at the remaining 299 things. Right now it compiles, but fails at runtime, when trying to load axdb.dll:

 

Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'AxDb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'AxDb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
at AutoCAD_Mechanical_BOM.NumericBOM.Main()
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

=== Pre-bind state information ===
LOG: DisplayName = AxDb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/Autodesk/AutoCAD 2023/
LOG: Initial PrivatePath = NULL
Calling assembly : AcmBomNum, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Program Files\Autodesk\AutoCAD 2023\acad.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/AutoCAD 2023/AxDb.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/AutoCAD 2023/AxDb/AxDb.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/AutoCAD 2023/AxDb.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/AutoCAD 2023/AxDb/AxDb.EXE.
LOG: Attempting download of new URL file://our.domain/nodfsroot$/USERS/myusername/PersonalData/AcmBomNum/obj/Debug/net4.8.1/AxDb.DLL.
LOG: Attempting download of new URL file://our.domain/nodfsroot$/USERS/myusername/PersonalData/AcmBomNum/obj/Debug/net4.8.1/AxDb/AxDb.DLL.
LOG: Attempting download of new URL file://our.domain/nodfsroot$/USERS/myusername/PersonalData/AcmBomNum/obj/Debug/net4.8.1/AxDb.EXE.
LOG: Attempting download of new URL file://our.domain/nodfsroot$/USERS/myusername/PersonalData/AcmBomNum/obj/Debug/net4.8.1/AxDb/AxDb.EXE.

 

It's looking where the axdb.dll file is, but it is not the right kind of library:

myusername at myworkstation MSYS ~
$ file /p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/*.dll
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AcCoreMgd.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AcCui.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AcDbMgd.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AcDx.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AcMgd.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AcTcMgd.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AcmBomNum.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AdUIMgd.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AdUiPalettes.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AdWindows.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/Autodesk.AutoCAD.Interop.Common.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/Autodesk.AutoCAD.Interop.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/AxDb.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/SymBBAutoENU.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/System.Runtime.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections
/p/PersonalData/AcmBomNum/bin/Debug/net4.8.1/acdbmgdbrep.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows, 3 sections

myusername at myworkstation MSYS ~
$ file /c/Program\ Files/Autodesk/AutoCAD\ 2023/axdb.dll
/c/Program Files/Autodesk/AutoCAD 2023/axdb.dll: PE32+ executable (DLL) (GUI) x86-64, for MS Windows, 6 sections

 

Any idea how to get some traction here?

I already loaded a bunch of ObjectARX dlls, so aside from this one obstacle, I seem to be getting close.

Here is what I reckon fails at runtime:

          var cadApp = new AxDb.AcadApplication(); // for ObjectDBX
          cadApp.Visible = true;
          var cadDoc = cadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.24");

 

0 Likes
2,230 Views
14 Replies
Replies (14)
Message 2 of 15

Ed__Jobe
Mentor
Mentor

AxDb is an ActiveX api. It's used by lisp and vba. In managed .NET you just open the database "on the side" or a "side database".

 

 

// Read the DWG into a side database
Database sourceDb = new Database(false, true);
sourceDb.ReadDwgFile("filePath\file.dwg",
                    System.IO.FileShare.Read,
                    true,
                    "");

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 15

officedrone
Participant
Participant

Thank you for clarifying, Ed.

 

I have already opened a Database this way:

  using System;
  using System.Runtime;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Autodesk.AutoCAD.Runtime;
  using Autodesk.AutoCAD.ApplicationServices;
  using Autodesk.AutoCAD.DatabaseServices;
  using Autodesk.AutoCAD.Geometry;
  using Autodesk.AutoCAD.EditorInput;
  //using SymBBAuto;
  //using Autodesk.AutoCAD.Interop;
  //using AxDb; // <- the remaining issue 

  [assembly: CommandClass(typeof(AutoCAD_Mechanical_BOM.NumericBOM))]
  namespace AutoCAD_Mechanical_BOM
  {
    public class NumericBOM
    {
      [CommandMethod("AcmBomNum")]
      public static void Main()
      {
        Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
        Database acCurDb = acDoc.Database;
        Editor ed = acDoc.Editor;
        
        ed.WriteMessage("Hello, AutoCAD Numeric BOM");
        
        using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
        {
          BlockTable acBlkTbl;
          acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

          BlockTableRecord acBlkTblRec;
          acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;

          int nCnt = 0;
          int rCnt = 0;
          ed.WriteMessage("\nModel space objects: ");

          foreach (ObjectId acObjId in acBlkTblRec)
          {
            ed.WriteMessage("\n" + acObjId.ObjectClass.DxfName);
            nCnt = nCnt + 1;

            if (acObjId.ObjectClass.DxfName == "AcmPartRef")
            {
              rCnt = rCnt + 1;
            }
          }

          if (nCnt == 0)
          {
            ed.WriteMessage("\n No objects found");
          }
          
          ed.WriteMessage("\n" + Convert.ToString(nCnt) + " acObjId found");
          ed.WriteMessage("\n" + Convert.ToString(rCnt) + " AcmPartRef found");

        }
      }
    }
  }

 

I am not sure if this counts as opening it "on the side". It finds a bunch of DxfName entries, but not AcmPartRef. I found a DXF reference doc from 2012 which does not mention AutoCAD Mechanical. There is some more that I've commented out because it does not work yet.

          try
          {
            IMcadSymbolBBMgr3 I_symBBmgr3 = null;
            //I_symBBmgr3 = (IMcadSymbolBBMgr3)cadApp.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr");
            I_symBBmgr3 = (IMcadSymbolBBMgr3)sourceDb.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr");

            SymBBAuto.IMcadBOMMgr3 I_cadBOMMgr3 = null;
            I_cadBOMMgr3 = (SymBBAuto.IMcadBOMMgr3)I_symBBmgr3.BOMMgr;

            SymBBAuto.McadBOMMgr cadBOMmgr = null; // contents
            cadBOMmgr = (SymBBAuto.McadBOMMgr)I_cadBOMMgr3;

            I_cadBOMMgr3 = null; // dispose
            
            // error CS0012: The type 'IAcadDictionary' is defined in an assembly that is not referenced.
            //   You must add a reference to assembly 'AXDB Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
            
            if (cadBOMmgr.BOMTableExists(BomName))
            {
              SymBBAuto.McadBOM cadBom = null;
              // error CS0012: The type 'IAcadDictionary' is defined in an assembly that is not referenced.
              // You must add a reference to assembly 'AXDB Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
              
              cadBom = (SymBBAuto.McadBOM)cadBOMmgr.GetBOMTableByName(BomName);
              
              if (cadBom != null)
              {
              //  cadBOMmgr.ExportBOM2(SymBBAuto.McadBOMExportFormatType.exCSV, cadBom, FullPathName, "Main", true);
              }
                  
           }
            
          }
          catch (Autodesk.AutoCAD.Runtime.Exception acEx)
          {
            
          }
          catch (System.Exception ex)
          {
            
          }

But I did not manage to get the interface object. VSCode tells me:

CS1061 'Database' does not contain a definition for 'GetInterfaceObject' and no accessible extension method 'GetInterfaceObject' accepting a first argument of type 'Database' could be found (are you missing a using directive or an assembly reference?)

 

Am I going about this the wrong way? The inspiration I am relying on is admittedly quite old, and things may have changed a lot since then. Thanks for your time.

0 Likes
Message 4 of 15

Ed__Jobe
Mentor
Mentor

@officedrone wrote:

Thank you for clarifying, Ed.

 

Am I going about this the wrong way?


It's hard to know. You haven't said what you're trying to do. Since you said you wanted to use AxDb, I assumed that you wanted to open the file 'on the side'. AxDb (Also known as ObjectDbx. AxDb is just the dll name) has the same api as the regular AutoCAD api, except that there is no Editor gui. You can only work with the database. In your code, you ignored the snippet I gave you and used the DocumentManager to access the current drawing opened in the Editor. My code simply sets a Database object to the contents of a file.

 

As to the SymBBAuto part, you haven't stated if you are working inside amech. The correct dll's have to be loaded to work with a BOM.

 

Also, there's no need to write messages to the command line to find out drawing contents. You can use @_gile 's Inspector tool to browse the database. It adds some Rt+Click menus to the context menu.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 15

officedrone
Participant
Participant

 

 

Well I sure am glad you appear to know how things work, because I am not that well versed yet. I'll try and be more clear.

 

What I am trying to do, is to programmatically set BOM values of numeric types, such as Qty and Item.

I am able to set the text types using lisp, and am currently setting Qty and Item with autohotkey, a process that takes way too long for comfort, even though it works. vlax-safearray will not let me mix data types.

 

Of course, you'd have to make some assumptions, in order to help out someone who doesn't know what information is relevant. Your snipped is not ignored, just not copied into the last post. Despite my walls of text, I am trying to avoid inundating you with irrelevant info.. When I tried using sourceDb.GetInterfaceObject, VSCode notified me that said method could not be found. What I showed you I had done up front, but omitted for brevity. Are there different kinds of Database objects defined? I mean, did one of them use to inherit GetInterfaceObject?

 

I am indeed working inside AutoCAD Mechanical (2023). Which dll's would have to be loaded? Here is the list I've cobbled together:

  <ItemGroup>
    <!--  warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. PE image does not have metadata. PE image does not have metadata.
    <Reference Include="SymBBAuto">
      <HintPath>C:\Users\myusername\ObjectARX\AutoCAD_Mechanical_SDK_2023_English_Win_64bit_dlm\acadmapi\lib-x64\acmsymbb_crx.lib</HintPath>
      <Private>true</Private>
    </Reference>
    This an ActiveX (COM Automation) API file -->
    <!-- warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. PE image does not have metadata. PE image does not have metadata.
    This is a PE32 executable (DLL) (GUI), while the others are PE32 executable (DLL) (console) -->

    <Reference Include="SymBBAuto">
      <HintPath>P:\PersonalData\AcmBomNum\bin\Debug\net4.8.1\SymBBAutoENU.dll</HintPath>
      <Private>false</Private>
    </Reference>
    <!-- TlbImp to generate SymBBAuto metadata  -->

    <Reference Include="AxDB">
      <!--
      <HintPath>C:\Users\myusername\ObjectARX\ObjectARX_for_AutoCAD_2023_Win_64bit_dlm\lib-x64\axdb.lib</HintPath>
      <Private>true</Private>
      -->
      
      <HintPath>P:\PersonalData\AcmBomNum\bin\Debug\net4.8.1\AxDb.dll</HintPath>
      <Private>false</Private>
      
      <!--
      <HintPath>C:\Program Files\Autodesk\AutoCAD 2023\axdb.dll</HintPath>
      <Private>true</Private>
      -->
      
    </Reference>
     <!--
    warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. PE  image does not have metadata. PE image does not have metadata.
    -->
    <!-- TlbImp : error TI1002 : The input file 'C:\Program Files\Autodesk\AutoCAD 2023\axdb.dll' is not a valid type library.
    P:\PersonalData\AcmBomNum\bin\Debug\net4.8.1\\AxDb.dll -->
    
    <Reference Include="Autodesk.Autocad.Interop">
      <HintPath>C:\Users\myusername\ObjectARX\ObjectARX_for_AutoCAD_2023_Win_64bit_dlm\inc-x64\Autodesk.AutoCAD.Interop.dll</HintPath>
      <Private>true</Private>
    </Reference>
    <Reference Include="System.Runtime">
      <Private>true</Private>
    </Reference>
    <Reference Include="AcCoreMgd">
      <HintPath>C:\Users\myusername\ObjectARX\ObjectARX_for_AutoCAD_2023_Win_64bit_dlm\inc\AcCoreMgd.dll</HintPath>
      <Private>true</Private>
    </Reference>
    <Reference Include="AcCui">
      <HintPath>C:\Users\myusername\ObjectARX\ObjectARX_for_AutoCAD_2023_Win_64bit_dlm\inc\AcCui.dll</HintPath>
      <Private>true</Private>
    </Reference>
    <Reference Include="AcDbMgd">
      <HintPath>C:\Users\myusername\ObjectARX\ObjectARX_for_AutoCAD_2023_Win_64bit_dlm\inc\AcDbMgd.dll</HintPath>
      <Private>true</Private>
    </Reference>
    <Reference Include="AcDx">
      <HintPath>C:\Users\myusername\ObjectARX\ObjectARX_for_AutoCAD_2023_Win_64bit_dlm\inc\AcDx.dll</HintPath>
      <Private>true</Private>
    </Reference>
    <Reference Include="AcMgd">
      <HintPath>C:\Users\myusername\ObjectARX\ObjectARX_for_AutoCAD_2023_Win_64bit_dlm\inc\AcMgd.dll</HintPath>
      <Private>true</Private>
    </Reference>
  </ItemGroup>

Some are probably superfluous, but I reckon I'll consider pruning the code once it is able to address the task at hand. Thanks for the tip, I'll look into the inspector tool. As an aside, do I really have to stop autocad to release the dll file handle, then do dotnet build, start autocad again, finally netload to continue? It is a bit tedious, and something like NETUNLOAD would be handy, but I digress.

 

Anyways, thanks for your input so far. Much appreciated.

0 Likes
Message 6 of 15

Ed__Jobe
Mentor
Mentor

@officedrone wrote:

 

Well I sure am glad you appear to know how things work, because I am not that well versed yet. I'll try and be more clear.


Don't worry about providing too much info. Asking for help on the forums is sort of like taking your car to the mechanic. You don't want to just say "It's broke". The more info you provide, the quicker we can give a response without asking a lot of questions. For the purpose of programming, we need to know exactly what you are trying to do. Sometimes users post code and want it fixed, but if we know what your goal is, we can suggest a better way. When posting code, always post the latest, most relevant version.

 


@officedrone wrote:

 

What I am trying to do, is to programmatically set BOM values of numeric types, such as Qty and Item.

I am able to set the text types using lisp, and am currently setting Qty and Item with autohotkey, a process that takes way too long for comfort, even though it works. vlax-safearray will not let me mix data types.

 


Does this require you to edit the bom without opening the dwg in the dwg editor? You can't see what's being done until you open the dwg again in the editor. Usually, the main reason for accessing the db on the side is to speed up a batch process. I ask this because SymBBAuto is an ActiveX interface and using the GetInterfaceObject method requires an ActiveX version of the database object.

 


@officedrone wrote:

As an aside, do I really have to stop autocad to release the dll file handle, then do dotnet build, start autocad again, finally netload to continue? It is a bit tedious, and something like NETUNLOAD would be handy, but I digress.


Are you referring to debugging? For using .NET in AutoCAD, Visual Studio is a better tool than VS Code, in my opinion. You can get the Community version for free. Here is a tutorial for working with a VS project and debugging it. You can't unload a .NET dll. You have to restart AutoCAD, but the tutorial shows you how to automate the process. You just hit F5 to start debugging.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 15

ActivistInvestor
Mentor
Mentor

@officedrone wrote:

 

vlax-safearray will not let me mix data types.


What data types do you need to pass in a safearray that the vlax safearray functions do not support?

 

As far as AxDb.dll goes, it does not contain a type library and it shouldn't be added as a project reference. The type library is stored in axdb24enu.tlb, which is what you reference from a project..

0 Likes
Message 8 of 15

fieldguy
Advisor
Advisor

"...and something like NETUNLOAD would be handy".

its here if you search that exact term.  the public domain app is called NET-RELOAD.

link: https://forums.autodesk.com/t5/net/net-reload-utility-for-visual-studio-download-here/m-p/3185104  

0 Likes
Message 9 of 15

kerry_w_brown
Advisor
Advisor

@officedrone 

. . . or you could use VisualStudio instead of VSCode,

and then use HotReload from the menu or ShortcutKeys

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 10 of 15

officedrone
Participant
Participant

Since @ActivistInvestor thinks I may got the right type library, and @Ed__Jobe says there is an ActiveX version of the Database object, I'll dig some more next week. If anyone reading this knows what docs apply, please share. I was not thinking of debugging just yet, because I reckon the type library issue has to be sorted out first.

 

Huh, @fieldguy that's good to know. Seems like it's meant for Visual Studio though. It was indeed mentioned as the recommended editor in some docs I came across, and now I am starting to see why.  HotReload is evidently also a thing. Thanks @kerry_w_brown. Thanks guys, and have a nice weekend. Edit: formatting.

0 Likes
Message 11 of 15

Ed__Jobe
Mentor
Mentor

You didn't answer my questions in post 6.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 12 of 15

officedrone
Participant
Participant

I intended to wave my hands and return next week, as I'm pressed for time and running on fumes now. I don't think I understand your question, but I'll try answering nonetheless. By dwg editor, I am assuming you mean autocad itself. 

 

The application I have in mind does not require that, no.  I just want to set AmPartRef values using some command then move along. However, if opening it "on the side" is what's required for batch processing, then probably yes. The reasoning appears to match. I do not want to manipulate the dwg from elsewhere than inside autocad, if that's somehow an option. As for debugging, that's not a priority yet. You appear to know of a distinction that may be useful, but I don't get how to instantiate the ActiveX flavor of this Database object. Sorry, please enlighten me.

 

@ActivistInvestor I didn't directly answer your question either. I simply need to pass int values for Qty and Item. I think it would work if the entire array had the same types, but I couldn't figure out how to set string values first, then ints afterwards, without overwriting the previous assignment.

0 Likes
Message 13 of 15

Ed__Jobe
Mentor
Mentor

@officedrone wrote:

I intended to wave my hands and return next week, as I'm pressed for time and running on fumes now. I don't think I understand your question, but I'll try answering nonetheless. By dwg editor, I am assuming you mean autocad itself. 

 


By Editor, that is the part of the application that loads when you load a dwg. Its what allows a user to interact with the file. By 'on the side', we mean opening the dwg in memory only. There's no way for a user to interact with the file. You can only do it programmatically. To do this in .NET, you use the code I gave you in post 2. You just simply set a Database object. If you need to use ActiveX (introduced with VBA more than 20 years ago), then you can use ObjectArx (AxDb). It's just older tech to open a side db. So do you need a command that will work on the currently opened dwg? Then abandon the idea of a side database. If you're trying to batch process without user interaction, then choose a side db.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 14 of 15

ActivistInvestor
Mentor
Mentor

@officedrone wrote:

 

I simply need to pass int values for Qty and Item. I think it would work if the entire array had the same types, but I couldn't figure out how to set string values first, then ints afterwards, without overwriting the previous assignment.


AFAIK, passing mixed types to an ActiveX server from LISP isn't a problem. I've done it many times. You pass each argument to (vlax-make-variant), and then pass them as arguments to (vlax-invoke-method). If  the Active server requires a safearray as a single argument with different element types, you can use  helper functions like the  ones below to  convert a standard LISP list to a safearray, using vlax-vbvariant as the array type:

 

 

; ========================================================
;; Function: vlxx-List->Variant
;; 
;; (vlxx-List->Variant <List>)
;;
;; Converts a LISP list into a Visual LISP
;; Variant Array. Supports nested lists.

(defun vlxx-List->Variant (Lst)
   (if (and lst (listp lst))
      (vlxx-VarArray 
         vlax-vbVariant
         (mapcar 'vlxx-List->Variant lst)
      )
      lst
   )
)

;; ========================================================
;; Function: vlxx-VarArray
;; 
;; (vlxx-VarArray <varType> <List>)
;; 
;; Converts a simple list to a one-dimensional
;; variant array of a specified type.
;;
;; <varType> is one of the vlax-vbXxxx constants
;; that specify the type of the iist. If the
;; list is heterogenous (e.g., not all elements
;; are of the same type), this argument should
;; be vlax-vbVariant.

(defun vlxx-VarArray (vtype lst)
   (vlax-Make-Variant
      (vlax-SafeArray-Fill 
         (vlax-Make-SafeArray 
            vtype 
            (cons 0 (1- (length lst)))
         )
         lst
      )
   )
)

 

 

 

Message 15 of 15

norman.yuan
Mentor
Mentor

I think the discussion after message 4 went no help/use for you, or made you more confused.  Back to your original message, the key issue that you could not proceed is you tried to import the AutoCAD type library and generate the managed interop DLL.

 

These are the mistakes you had:

 

1. You use VS Code, instead of Visual Studio (I wonder why?). With Visual Studio, you do not need to run the TlbImport.exe. You simply select the COM library in the "References" dialog box, and Visual Studio will does generate the interop managed DLL for you. Had you used Visual Studio, you would have not made the mistake 2 (see next);

 

2. You mistakenly named the interop managed DLL for AutoCAD COM type library to AxDb.dll. AutoCAD comes with native DLL named AxDb.dll, which is neither COM DLL, not a managed DLL. When you generated the interop as "AxDb.dll" and try to load it into AutoCAD, therefore the error you got. If you let Visual Studio to create the interop DLL (in the "References" dialog box, COM tab, you select "Autodesk 202X type library" and/or "AutoCAD/ObjectDBX common 2x.0 type library", the generated interop dlls would be "Interop.AutoCADxxx.dll", In the case of AutoCAD/ObjectDBX Common library", which probably is what you try to use, it is "interop.AxDbLib.dll". As you can see, there is no name conflict with existing AxDb.dll file.

 

3. In the case of AutoCAD, you do not even have to import COM  type library: AutoCAD install comes with the COM interop managed DLLs: Autodesk.AutoCAD.interop.dll and Autodesk.AutoCAD.Interop.Common.dll. You can directly set references to one or both (but do not deploy them with your app by setting "Copy Local" to false, because AutoCAD installs them already).

 

You mentioned an old discussion as your code inspiration and assumes things may have changed a lot since. I browsed that thread and I'd bet the code show there should still work. The COM API of AutoCAD and its verticals (Mechanical, in your case) has been there very long and almost no changes in last 15 years (or even longer). I do not use Mechanical, but know that you are to access Mechnical's BOM via its COM API: its enter point is to create SymBBAuto.McadSymbolBBMgr object via COM API's AcadApplication.GetInterfaceObject() method (thus you import Acad type library in the first place).

 

Again, I do not know much about Mechanical's COP API, but you just need to create SymBBAuto.McadSymbolBBMgr to begin with, you do not even need to reference AutoCAD COM API with early binding, you could easily call GetInterfaceObject() method via late binding in C#, something like:

 

public class NumericBOM
    {
      [CommandMethod("AcmBomNum")]
      public static void Main()
      {
        Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
        Editor ed = acDoc.Editor;
        
        ed.WriteMessage("Hello, AutoCAD Numeric BOM");
	IMcadSymbolBBMgr bbMgr = null;
        try
        {
	    dynamic comCad=Autodesk.AutoCAD.ApplicationSergices.Application.AcadApplication;
            IMcadSymbolBBMgr bbMgr=(IMcadSymbolBBMgr3)comCad.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr");
        }
        catch(System.Exception ex)
        {
           ed.WriteMessage($"\nCreate BOM Manager failed: {ex.Message}");
           return;
        }

        ed.WriteMemessage("\nBOM Manager instantiated. Procedding...");
        // do what ever with the bbMgr object...
      }
    }

 

 

Norman Yuan

Drive CAD With Code

EESignature