从AutoCAD .NET Editor.CommandAsync调用LISP命令

时间:2015-12-16 00:23:41

标签: .net vb.net autocad-plugin autolisp

我试图从.NET调用内置的AutoCad Electrical LISP命令(c:wd_insym2 "HPB11.dwg" (list 0 0) 1.0 nil) 。 我最近安装了AutoCad 2016,它现在有Editor.Command和Editor.CommandAsync功能,但是我能找到的所有帮助/论坛帖子都是用它来调用AutoCad命令,如LINE,CIRCLE等。 我想调用lisp命令,例如:

0, 0

<CommandMethod("SendCmdAsync", CommandFlags.Modal)> Async Sub SendCmdAsync() Dim doc As Document = DocumentManager.MdiActiveDocument Dim ed As Editor = doc.Editor Dim cmd As String = "(c:wd_insym2 " & ControlChars.Quote & "HPB11.dwg" & ControlChars.Quote & " (list 0 0) nil nil)" ed.WriteMessage(vbNewLine & "Trying to execute: <" & cmd & ">" & vbNewLine) Await ed.CommandAsync(cmd) ed.WriteMessage(vbNewLine & "Done.") End Sub 处插入按钮符号。

这是我所拥有的(我一直在使用CommandAsync,因为我在使用Application.Invoke同步发送该命令时遇到了麻烦:AutoCad Command Rejected "Undo" when using Application.Invoke()

import pprint
import httplib2
import googleapiclient.discovery
import googleapiclient.http
import googleapiclient.errors
import oauth2client.client


class DriveClient():
    def __init__(self):
        self.oauth2_scope = 'https://www.googleapis.com/auth/drive'
        self.client_secrets = 'client_secrets.json'
        self.mimetype = 'application/vnd.google-apps.document'
        self.flow = self.set_flow()
        self.drive_service = self.authorize_url()

    def set_flow(self):
        flow = oauth2client.client.flow_from_clientsecrets(self.client_secrets,
                                                           self.oauth2_scope)
        flow.redirect_uri = oauth2client.client.OOB_CALLBACK_URN
        return flow

    def authorize_url(self):
        authorize_url = self.flow.step1_get_authorize_url()
        print('Go to the following link in your browser: ' + authorize_url)
        code = input('Enter verification code: ').strip()
        credentials = self.flow.step2_exchange(code)

        http = httplib2.Http()
        credentials.authorize(http)
        drive_service = googleapiclient.discovery.build('drive', 'v2',
                                                        http=http)
        return drive_service

    def push_file(self, file_src, title, description=''):
        media_body = googleapiclient.http.MediaFileUpload(
                file_src, mimetype=self.mimetype, resumable=True)
        body = {
            'title': title,
            'description': description
        }
        try:
            new_file = self.drive_service.files().insert(body=body,
                                                     media_body=media_body
                                                     ).execute()
            pprint.pprint(new_file)
        except googleapiclient.errors.HttpError as error:
            print('An error occured: %s' % error)


if __name__ == '__main__':
    d = DriveClient()
    d.push_file('document.txt', 'mTitle', 'mDescription')

当我运行它时,它说&#39; LISP命令不可用&#39;。

我做的是什么,如果是的话,我做错了什么?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题 - 显然你不能使用Command和CommandAsync来运行Lisp命令 - 它们只适用于AutoCAD命令。

执行此操作的最佳方法是Application.Invoke:https://forums.autodesk.com/t5/net/unable-to-find-an-entry-point-in-dll-acad-exe/m-p/5522036/highlight/true#M43404

虽然,通过我的特定电气命令(c:wd_insym2),当我在AutoCAD 2014中尝试这种技术时,它会给我一个错误'AutoCAD命令拒绝UNDO'。但是,我刚刚注意到在AutoCAD 2016中它工作正常 - 我猜他们已经在某处改变了API。

相关问题