acdbmgd.dll, accoremgd.dll, acmgd.dll more issues

acdbmgd.dll, accoremgd.dll, acmgd.dll more issues

Anonymous
Not applicable
5,567 Views
12 Replies
Message 1 of 13

acdbmgd.dll, accoremgd.dll, acmgd.dll more issues

Anonymous
Not applicable

Hi all,

 

I managed to load the 3 reference files in order to have access to: Imports Autodesk...

 

Now I have the three imports without problems:

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices

 

and the module also without editor problems:

Public Sub UpdateBlockAttributes(ByVal attName As String, ByVal attValue As String)

Dim acDb = HostApplicationServices.WorkingDatabase
Dim acEd = Application.DocumentManager.MdiActiveDocument.Editor
Dim blockName = "blkAttributes" ' Same block name for all drawings
Dim _success As Boolean = False
Dim _attempts As Integer = 1

While _success = False And _attempts < MAX_ATTEMPTS
Try
Using acTrans = acDb.TransactionManager.StartTransaction()
Dim acBlockTable As BlockTable = acTrans.GetObject(acDb.BlockTableId, OpenMode.ForRead)
Dim acBlockTableRecord As BlockTableRecord = acTrans.GetObject(acBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForRead)
For Each blkId In acBlockTableRecord
Dim acBlock As BlockReference = acTrans.GetObject(blkId, OpenMode.ForRead)
If acBlock.Name.Equals(blockName, StringComparison.CurrentCultureIgnoreCase) Then
For Each attId In acBlock.AttributeCollection
Dim acAtt As AttributeReference = acTrans.GetObject(attId, OpenMode.ForRead)
If acAtt.Tag.Equals(attName, StringComparison.CurrentCultureIgnoreCase) Then
acAtt.UpgradeOpen()
acAtt.TextString = attValue
End If
Next
End If
Next
acTrans.Commit()
End Using

If _attempts > 1 Then DebugAttempt(_attempts, Me, GetCurrentMethod().Name)
_success = True

Catch ex As Exception
DebugError(GetCurrentMethod().Name, ex.Message)
System.Threading.Thread.Sleep(15)
_attempts += 1

End Try
End While

End Sub

 

 When I run the application, I get the following erorr: [autocad reference error.jpg]

and exception unhandleded: [autocad exception unhandleded.jpg]

 

On my computer I have installed:

Visual Studio 2017 version 15.9.10

.NET Framework Version 4.7.03062

Autocad full version 2016

Windows 8.1 Pro

 

After installing new version of AutoCAD and new version of Visaul Studio, I don't know what else to do.

 

Please help.

 

Thanks,

alex

 

 

0 Likes
5,568 Views
12 Replies
Replies (12)
Message 2 of 13

_gile
Consultant
Consultant

Did you set the Copy Local property of these references to False?

Did you attetively read and follow step by step the topic I recommended you?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 13

Anonymous
Not applicable

Yes, I did set them to false

0 Likes
Message 4 of 13

_gile
Consultant
Consultant

Which version of the .NET Framework is targeting your project? It should be 4.5 or upper.

Do you NETLOAD your plugin (i.e., a Class Library DLL) or is it a stand alone execuatble (i.e.,  Console Application or Windows Form EXE)? In the second case you cannot directly use the AutoCAD .NET API.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 13

kerry_w_brown
Mentor
Mentor

 

Perhaps,

Comment out all your app code and

add a Hello_World application code.

 

Try to compile and load and run the HelloWorld.

 

When that works, uncomment your app code and try again.

 

Regards,

 


// 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 6 of 13

Anonymous
Not applicable

Target framework is: .NET Framework 4.7.2

It is a stand alone exe. I guess this is the problem I have.

If it's not possible to use AutoCAD .NET API in an .exe application, is there a way to read and write attributes inside a block attribute?

Thank you for all your help _gile

 

Alex

 

 

0 Likes
Message 7 of 13

Norman_Yuan
Mentor
Mentor

Well, if you are doing EXE to automate AutoCAD, you use AutoCAD's COM API by setting reference to AutoCAD COM API's interop assemblies: Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll, both can be found in AutoCAD installation folder. Make sure to set "Copy Local" to False. 

 

Or, you can set references to AutoCAD COM API via "References" dialog box->COM Tab", and let Visual Studio to generate the COM interop assemblies for your project. (I am not recommending it, but it is a workable way of doing things anyway).

 

However, before you go too deep, you might want to ask yourself: do you really want an external EXE app to automate AutoCAD for your business needs? Since that kind of solution still needs a running AutoCAD session, why bother with yet another application to let AutoCAD do something that can be done a lot faster within AutoCAD alone? Not to mention possible of code development saving without having to deal with 2 applications. I'd only choose EXE to automate AutoCAD if the business requirements leave me ABSOLUTELY no other choice.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 8 of 13

_gile
Consultant
Consultant

I totally agree with @Norman_Yuan about avoiding as much as possible standalone applications.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 13

Anonymous
Not applicable

Thanks Norman.

 

I'm not sure how to avoid .exe application. 

The company has ~50 projects/year. Each project contains ~300 drawings.

There are ~100 dimensions in each drawing. For each drawing I have a table with 2 columns (description and value) and 1 row for each dimension in the drawing. 

We have an excel sheet with 300 rows (one for each drawing) and 100 columns (one for each dimension).

We also have a master folder that contains those 300 drawings. All the cells from the table (column 2) are linked to all the dimensions on the drawing.

The excel sheet for each project contains a few thousands formulas and generates ~30,000 values that need to be plugged in those 300 drawings. My program is simple: open each drawing (of the 300 ), populate data in the table then close the drawing. Then when the drafter opens any drawing, he/she will have a drawing with all correct dimensions. This part works fine. It takes about 10 min to update all those drawings. And for that, I'm using Imports AutoCAD with no problems.

 

About a month ago, my boss asked me to look into block attributes and see if it makes sense to replace existing system of importing data from excel to drawings. Here is where I had to import all the other Autodesk libraries.

 

So I'm not sure how I can change one simple function that I have in this large .exe application with something that will run in AutoCAD session. I am open to any ideas if there is an easier way or more efficient way to do the imports.

 

Thank you all for your help.

Alex

 

0 Likes
Message 10 of 13

_gile
Consultant
Consultant

So, you have mainly two ways:

Use the ActiveX/COM API instead of the .NET one to directly update the attributes from your executable.

Build a custom command using the .NET API, then load the DLL and run the command with SendCommand from the executable as shown in this topic.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 13

Anonymous
Not applicable

_gile thank you for all your help. I have learned a lot in the past couple of days.

So for a stand alone .exe application could you please point me to a code that read and write an attribute?

I have a test drawing with a block attribute named blkAttributes. Inside the block I have two attributes: tag:ATTLENGTH and tag: ATTWIDTH. How do I go about changing the values of the attributes?

 

Thanks,

Alex

 

0 Likes
Message 12 of 13

_gile
Consultant
Consultant

While using the COM API, you should find more help in the Visual Basic forum (COM is the API used by AutoCAD VBA).

 

Anyway, here's a little (not tested) example.

 

        private void UpdateBlockAttribute (AcadBlockReference br, string tag, string value)
        {
            foreach (AcadAttributeReference attRef in br.GetAttributes())
            {
                if (attRef.TagString.ToUpper() == tag.ToUpper())
                {
                    attRef.TextString = value;
                    break;
                }
            }
        }

        public void UpdateBlockAttributes(string tag1, string tag2, string val1, string val2)
        {
            AcadDocument thisDrawing = AcadApp.ActiveDocument;
            foreach (AcadEntity entity in thisDrawing.ModelSpace)
            {
                if (entity.ObjectName == "AcDbBlockReference")
                {
                    AcadBlockReference br = (AcadBlockReference)entity;
                    if (br.EffectiveName == "blkAttributes")
                    {
                        UpdateBlockAttribute(br, tag1, val1);
                        UpdateBlockAttribute(br, tag2, val2);
                    }
                }
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 13 of 13

Anonymous
Not applicable

Thank you _gile. This is awesome. But I have bigger problems now. Since I have upgraded AutoCAD and Visual Studio, they don't communicate anymore. I'm waiting for the IT department to solve it.

 

Thank you again for your help and support

Alex

 

0 Likes