ActiveX: How to post a path?

4 ビュー (過去 30 日間)
BA
BA 2018 年 4 月 19 日
編集済み: Guillaume 2018 年 4 月 26 日

Hi, I've started using the ActiveX interface to communicate with Autodesk AutoCAD (version 2016). Therefore I use the invoke command. This works pretty fine as it comes to execute basic commands (both create circle (1) & (2)) but I haven't found a solution on how I can post paths along with invoke. I am trying to attach an image to a drawing therefore I call the -ATTACH command. A backspace usually ends an entry as in the following example after the -ATTACH command.

acad=actxGetRunningServer('AutoCAD.Application'); % get the instance of AutoCAD which is running priorly
documents.Add %create a new drawing
c_doc=get(acad,'ActiveDocument');   % current document instance
% both of the following commands do work:
invoke(c_doc,'PostCommand','_Circle 2,2,0 4 '); %create circle(1)
invoke(c_doc,'PostCommand','_Circle vbCr 2,2,0 vbCr 4 vbCr') %create circle(2)
% However, this command is not posted to ACAD correctly:
invoke(c_doc,'PostCommand','-ATTACH C:\users\me\myimage.jpg  0,0 490 0 '); %-ATTACH Path Insertpoint Scale angle

But this doesn´t work after the specified path, all entries are recognized as part of the path, commonly used commands from VBA (vbCr, &vbCr,...) also don´t work or I just haven´t found the right one, yet. Does someone have a solution for this?

Thanks very much!

  1 件のコメント
Guillaume
Guillaume 2018 年 4 月 26 日
編集済み: Guillaume 2018 年 4 月 26 日
Two notes:
  • this has nothing to do with activex (or matlab). The problem is with the format of the text that your autocad function expect. At a push, your question is about inserting control characters in a char array.
  • In all likelyhood you don't need to use invoke or get. The following code would probably work:
acad = actxGetRunningServer('AutoCAD.Application');
documents.Add; %Looks like you're missing a line: documents = acad.Documents
c_doc = acad.ActiveDocument;
c_doc.PostCommand('_Circle 2,2,0 4 ');
c_doc.PostCommand('_Circle vbCr 2,2,0 vbCr 4 vbCr');
c_doc,'PostCommand(sprintf('-ATTACH C:\users\me\myimage.jpg\r\r0,0 490 0 '));
And if the Add method of the Documents collection of autocad is properly designed,
c_doc = documents.Add;
would be more reliable than going through ActiveDocument.

サインインしてコメントする。

採用された回答

BA
BA 2018 年 4 月 26 日
Solution is simple but took me some time:
Use sprinf to create a char which can understand the \r method:
sprintf('Some String\rSome Other String');
In this case are two \r required to 'hit' the <enter>button two times:
MyCommand=sprintf('-ATTACH C:\users\me\myimage.jpg\r\r0,0 490 0 ');
invoke(c_doc,'PostCommand',MyCommand);
Hope this will help others in the future!
  1 件のコメント
Stephen23
Stephen23 2018 年 4 月 26 日
You will probably need to escape those backslashes:
sprintf('-ATTACH C:\\users\\me\\myimage.jpg\r\r...')
or alternatively supply it as an input:
sprintf('-ATTACH %s\r\r..:','C:\users\me\myimage.jpg')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeActiveX についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by