Running AutoCAD from MatLAB

Hello, \\trying to run AutoCAD from MATLAB.
Tried the code proposed here
Unfortunately I got this error
Error using dotnetAutoCADExample
Message: Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
Source: Autodesk.AutoCAD.Interop
HelpLink: None
The topic was closed so I was not able to ask questions there.
Any useas?
What I need to do is plot some objects based on numbers calculated in a loop in MATLAB
Thank you

5 Comments

Cool! This is something new.
Is this the correct root path for your AutoCAD version
rootdir = 'C:\Program Files\Autodesk\AutoCAD 2023'
Have you made sure that these are correct, what is the output of these lines?
fullfile(rootdir,Interop)
fullfile(rootdir,InteropCommon)
In my script the rootdir was changed to reflect the right autocad version
the output of the lines above is:
'C:\Program Files\Autodesk\AutoCAD 2016\Autodesk.AutoCAD.Interop.dll'
'C:\Program Files\Autodesk\AutoCAD 2016\Autodesk.AutoCAD.Interop.Common.dll'
Thanks
could it be a security access issue? how would I know that? this is the full code I use
%% dotnetAutoCADExample.m
%% Locate the AutoCAD assemblies
% Change these, as needed.
rootdir = 'C:\Program Files\Autodesk\AutoCAD 2016';
Interop = 'Autodesk.AutoCAD.Interop.dll';
InteropCommon = 'Autodesk.AutoCAD.Interop.Common.dll';
%% Make the assemblies visible to MATLAB
% Return NET.Assembly objects
NET.addAssembly(fullfile(rootdir,Interop));
NET.addAssembly(fullfile(rootdir,InteropCommon));
%% Open a new instance of AutoCAD
app = Autodesk.AutoCAD.Interop.AcadApplicationClass;
app.Visible = 1;
%% Open a document
filename = 'C:\Users\nqh1127\Documents\MATLAB\test1.dwg';
doc = app.Documents.Open(filename);
%% Add a PolyLine in the form of a rectangle and get the Exploded parts
coords=[2;0;0;4;0;0;4;4;0;0;4;0];
% Add the PolyLine to the Model Space
rec = doc.ModelSpace.AddPolyline(coords);
% Explode the rectangle
reckage = rec.Explode;
app.Update
app.ZoomAll
%% Create another region from an arc and a line
% Create the arc and line
arc = doc.ModelSpace.AddArc([5; 3; 0], 2, 0, 3.141592);
chord = doc.ModelSpace.AddLine(arc.EndPoint, arc.StartPoint);
% Add a region composed of different object types
% See output of: >> superclasses(arc) and >> superclassess(arcline)
% arc and arcline have IAcadEntity as a superclass
% Create an array of type IAcadEntity
acadEntityArray = NET.createArray('Autodesk.AutoCAD.Interop.Common.IAcadEntity',2);
acadEntityArray(1) = arc;
acadEntityArray(2) = chord;
halfCircleRegion = doc.ModelSpace.AddRegion(acadEntityArray);
%% Save the changes
doc.Save
this is the error message I get:
Error using dotnetAutoCADExample
Message: Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
Source: Autodesk.AutoCAD.Interop
HelpLink: None
I don't know much about dotnet function, it might be possible that AutoCAD allows the access in newer versions. If you have the newer version, try with it.
Otherwise, try to start it with actxserver. You need to find out the exact name for your version though on internet. Maybe this helps.
AcadApp=actxserver('AutoCAD.Application.19.1'); % AutoCAD2014
AcadApp.Visible = true();
AcadDoc = AcadApp.ActiveDocument;
AcadModelSpace = AcadDoc.ModelSpace;
lineObj = AcadModelSpace.AddLine([0,0,0]',[1,0,0]'); % drawing a line

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 26 Aug 2024

Commented:

on 27 Aug 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!