필터 지우기
필터 지우기

ActiveX: How to post a path?

조회 수: 2 (최근 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 CenterFile Exchange에서 ActiveX에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by