Author Topic: [Help]Through the interface  (Read 2865 times)

0 Members and 1 Guest are viewing this topic.

chlh_jd

  • Guest
[Help]Through the interface
« on: October 13, 2014, 11:48:47 PM »
Hi all .
How can I get which object can be use through the interface , and how to use it ?
like
Code - Auto/Visual Lisp: [Select]
or
Code - Auto/Visual Lisp: [Select]
  1. (vlax-create-object  "wscript.Shell")
This object's method can't be dump by (vlax-dump-object obj T)

Is it possible to get all interfaceobject and their method ?

Many thanks .

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: [Help]Through the interface
« Reply #1 on: October 14, 2014, 02:58:51 AM »
Unfortunately the dump-object function only lists methods & properties which were exported properly as publicly accessible. Some COM assemblies didn't follow the rules everywhere (actually it's more like most of them didn't), so some of these properties aren't listed normally.

Though there is the tlbinf32.dll which can interrogate even such mis-created assemblies. And thanks to MP a very nice AutoLisp function to make use of it: http://www.theswamp.org/index.php?topic=19890.25
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

chlh_jd

  • Guest
Re: [Help]Through the interface
« Reply #2 on: October 14, 2014, 06:03:58 AM »
Unfortunately the dump-object function only lists methods & properties which were exported properly as publicly accessible. Some COM assemblies didn't follow the rules everywhere (actually it's more like most of them didn't), so some of these properties aren't listed normally.

Though there is the tlbinf32.dll which can interrogate even such mis-created assemblies. And thanks to MP a very nice AutoLisp function to make use of it: http://www.theswamp.org/index.php?topic=19890.25
Thanks Irneb , thank you a lot .
And thanks MP , too  .

chlh_jd

  • Guest
Re: [Help]Through the interface
« Reply #3 on: October 16, 2014, 10:44:04 AM »
Through following code , I found 922 Interface Object can be used in VLIDE .
(Test in my case :  WIN7 64BIT ,  AutoCAD2011 , not VBA support .)
Code: [Select]
(vl-load-com)
;;
(defun registry-interface-classes  (/ l b lst f)
  (setq l (vl-registry-descendents "HKEY_CLASSES_ROOT\\Interface"))
  (vl-file-delete "C:\\InterfaceClasses.txt")
  (setq f (open "C:\\InterfaceClasses.txt" "w"))
  (foreach a  l
    (setq b (vl-registry-read (strcat "HKEY_CLASSES_ROOT\\Interface" "\\" a)))
    (if (and b (not (vl-position b lst)))
      (setq lst (cons b lst))))
  (foreach a  (setq lst (reverse lst))
    (write-line a f))
  (close f)
  )
;;(registry-interface-classes)

(defun registry-interface-classes-base (/ l b lst f)
  (setq l (vl-registry-descendents "HKEY_CLASSES_ROOT"))
  (vl-file-delete "C:\\InterfaceClassesBase.txt")
  (setq f (open "C:\\InterfaceClassesBase.txt" "w"))
  (foreach a  l
    (setq b (vl-registry-read (strcat "HKEY_CLASSES_ROOT" "\\" a)))
    (if (and b (not (vl-position b lst)))
      (setq lst (cons b lst))))
  (foreach a  (setq lst (reverse lst))
    (write-line a f))
  (close f)
  lst
  )

(defun registry-interface-classes-name (/ l f)
  (setq l (vl-registry-descendents "HKEY_CLASSES_ROOT"));_(length (vl-remove-if (function (lambda (a) (or (= a "*") (wcmatch a "`.*"))))(vl-registry-descendents "HKEY_CLASSES_ROOT")))
  (vl-file-delete "C:\\InterfaceClassesObjectName.txt")
  (setq f (open "C:\\InterfaceClassesBObjectName.txt" "w"))
  (foreach a  l
    (write-line a f))
  (close f)
  )
;; (registry-interface-classes-name)

;; (registry-interface-classes-base)
;; (vlax-dump-object (vla-getInterfaceObject (vlax-get-acad-object) "TapiMigPlugin.MigrationPlugin.1"))

(defun c:IFOTest  (/ l l1 cad obj lst f)
  ;; through the interface object Test
  (setq l (registry-interface-classes-base))
  (setq cad (vlax-get-acad-object))
  (foreach a  l
    (setq a (vl-string-subst "." " " a))
    (setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
    (if (not (vl-catch-all-error-p obj))
      (progn (setq lst (cons a lst))
     (vlax-release-object obj))
      (setq obj nil))
    )
  (vlax-release-object cad)
  (if lst
    (progn
      (vl-file-delete "c:\\IFOTest0.txt")
      (setq f (open "c:\\IFOTest0.txt" "w"))
      (foreach a  lst
(write-line a f))
      (close f)))
  (princ (strcat "\n" (rtos (length lst) 2 0) " Interface Object Can be use , See C:\IFOTest.txt ."))
  (princ)
  )

(defun c:IFOTest0  (/ l i cad obj f)
  ;; through the interface object Test
  (setq f0 (open "C:\\InterfaceClassesBObjectName.txt" "r"))
  (repeat (* 0 1024)
    (read-line f0))
  (setq cad (vlax-get-acad-object))
  (setq f (open "c:\\IFOTest1.txt" "a")
i 0)
  (repeat 1024
    (setq a (read-line f0))
    (if (and a (vl-every (function not) (list (= a "*") (wcmatch a "`.*") (= (vl-string-trim " " a) ""))))
      (progn
(setq a (vl-string-subst "_" " " a))
(setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
(if (not (vl-catch-all-error-p obj))
  (progn (write-line a f)
(vlax-release-object obj)
(setq i (1+ i)))
  (princ (strcat "\n" a " " (vl-catch-all-error-message obj)))
  )))
    (gc)
    )
  (vlax-release-object cad)
  (close f)
  (princ (strcat "\n" (rtos i 2 0) " Interface Object Can be use , See C:\IFOTest1.txt ."))
  (princ)
  )
;;

(defun c:IFOTest1  (/ l i cad obj f)
  ;; through the interface object Test
  (setq f0 (open "C:\\InterfaceClassesBObjectName.txt" "r"))
  (repeat (* 1 1024)
    (read-line f0))
  (setq cad (vlax-get-acad-object))
  (setq f (open "c:\\IFOTest1.txt" "a")
i 0)
  (repeat 1024
    (setq a (read-line f0))
    (if (and a (vl-every (function not) (list (= a "*") (wcmatch a "`.*") (= (vl-string-trim " " a) ""))))
      (progn
(setq a (vl-string-subst "_" " " a))
(setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
(if (not (vl-catch-all-error-p obj))
  (progn (write-line a f)
(vlax-release-object obj)
(setq i (1+ i)))
  (princ (strcat "\n" a " " (vl-catch-all-error-message obj)))
  )))
    (gc)
    )
  (vlax-release-object cad)
  (close f)
  (princ (strcat "\n" (rtos i 2 0) " Interface Object Can be use , See C:\IFOTest1.txt ."))
  (princ)
  )

(defun c:IFOTest2  (/ l i cad obj f)
  ;; through the interface object Test
  (setq f0 (open "C:\\InterfaceClassesBObjectName.txt" "r"))
  (repeat (* 2 1024)
    (read-line f0))
  (setq cad (vlax-get-acad-object))
  (setq f (open "c:\\IFOTest1.txt" "a")
i 0)
  (repeat 1024
    (setq a (read-line f0))
    (if (and a (vl-every (function not) (list (= a "*") (wcmatch a "`.*") (= (vl-string-trim " " a) ""))))
      (progn
(setq a (vl-string-subst "_" " " a))
(setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
(if (not (vl-catch-all-error-p obj))
  (progn (write-line a f)
(vlax-release-object obj)
(setq i (1+ i)))
  (princ (strcat "\n" a " " (vl-catch-all-error-message obj)))
  )))
    (gc)
    )
  (vlax-release-object cad)
  (close f)
  (princ (strcat "\n" (rtos i 2 0) " Interface Object Can be use , See C:\IFOTest1.txt ."))
  (princ)
  )

(defun c:IFOTest3  (/ l i cad obj f)
  ;; through the interface object Test
  (setq f0 (open "C:\\InterfaceClassesBObjectName.txt" "r"))
  (repeat (* 3 1024)
    (read-line f0))
  (setq cad (vlax-get-acad-object))
  (setq f (open "c:\\IFOTest1.txt" "a")
i 0)
  (repeat 1024
    (setq a (read-line f0))
    (if (and a (vl-every (function not) (list (= a "*") (wcmatch a "`.*") (= (vl-string-trim " " a) ""))))
      (progn
(setq a (vl-string-subst "_" " " a))
(setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
(if (not (vl-catch-all-error-p obj))
  (progn (write-line a f)
(vlax-release-object obj)
(setq i (1+ i)))
  (princ (strcat "\n" a " " (vl-catch-all-error-message obj)))
  )))
    (gc)
    )
  (vlax-release-object cad)
  (close f)
  (princ (strcat "\n" (rtos i 2 0) " Interface Object Can be use , See C:\IFOTest1.txt ."))
  (princ)
  )

(defun c:IFOTest4  (/ l i cad obj f)
  ;; through the interface object Test
  (setq f0 (open "C:\\InterfaceClassesBObjectName.txt" "r"))
  (repeat (* 4 1024)
    (read-line f0))
  (setq cad (vlax-get-acad-object))
  (setq f (open "c:\\IFOTest1.txt" "a")
i 0)
  (repeat 1024
    (setq a (read-line f0))
    (if (and a (vl-every (function not) (list (= a "*") (wcmatch a "`.*") (= (vl-string-trim " " a) ""))))
      (progn
(setq a (vl-string-subst "_" " " a))
(setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
(if (not (vl-catch-all-error-p obj))
  (progn (write-line a f)
(vlax-release-object obj)
(setq i (1+ i)))
  (princ (strcat "\n" a " " (vl-catch-all-error-message obj)))
  )))
    (gc)
    )
  (vlax-release-object cad)
  (close f)
  (princ (strcat "\n" (rtos i 2 0) " Interface Object Can be use , See C:\IFOTest1.txt ."))
  (princ)
  )


(defun c:IFOTest5  (/ l i cad obj f)
  ;; through the interface object Test
  (setq f0 (open "C:\\InterfaceClassesBObjectName.txt" "r"))
  (repeat (* 5 1024)
    (read-line f0))
  (setq cad (vlax-get-acad-object))
  (setq f (open "c:\\IFOTest1.txt" "a")
i 0)
  (repeat 1024
    (setq a (read-line f0))
    (if (and a (vl-every (function not) (list (= a "*") (wcmatch a "`.*") (= (vl-string-trim " " a) ""))))
      (progn
(setq a (vl-string-subst "_" " " a))
(setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
(if (not (vl-catch-all-error-p obj))
  (progn (write-line a f)
(vlax-release-object obj)
(setq i (1+ i)))
  (princ (strcat "\n" a " " (vl-catch-all-error-message obj)))
  )))
    (gc)
    )
  (vlax-release-object cad)
  (close f)
  (princ (strcat "\n" (rtos i 2 0) " Interface Object Can be use , See C:\IFOTest1.txt ."))
  (princ)
  )

(defun c:IFOTest6  (/ l i cad obj f)
  ;; through the interface object Test
  (setq f0 (open "C:\\InterfaceClassesBObjectName.txt" "r"))
  (repeat (* 6 1024)
    (read-line f0))
  (setq cad (vlax-get-acad-object))
  (setq f (open "c:\\IFOTest1.txt" "a")
i 0)
  (repeat 1024
    (setq a (read-line f0))
    (if (and a (vl-every (function not) (list (= a "*") (wcmatch a "`.*") (= (vl-string-trim " " a) ""))))
      (progn
(setq a (vl-string-subst "_" " " a))
(setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
(if (not (vl-catch-all-error-p obj))
  (progn (write-line a f)
(vlax-release-object obj)
(setq i (1+ i)))
  (princ (strcat "\n" a " " (vl-catch-all-error-message obj)))
  )))
    (gc)
    )
  (vlax-release-object cad)
  (close f)
  (princ (strcat "\n" (rtos i 2 0) " Interface Object Can be use , See C:\IFOTest1.txt ."))
  (princ)
  )

(defun c:IFOTest7  (/ l i cad obj f)
  ;; through the interface object Test
  (setq f0 (open "C:\\InterfaceClassesBObjectName.txt" "r"))
  (repeat (* 7 1024)
    (read-line f0))
  (setq cad (vlax-get-acad-object))
  (setq f (open "c:\\IFOTest1.txt" "a")
i 0)
  (repeat 1024
    (setq a (read-line f0))
    (if (and a (vl-every (function not) (list (= a "*") (wcmatch a "`.*") (= (vl-string-trim " " a) ""))))
      (progn
(setq a (vl-string-subst "_" " " a))
(setq obj (vl-catch-all-apply (function vla-getInterfaceObject) (list cad a)))
(if (not (vl-catch-all-error-p obj))
  (progn (write-line a f)
(vlax-release-object obj)
(setq i (1+ i)))
  (princ (strcat "\n" a " " (vl-catch-all-error-message obj)))
  )))
    (gc)
    )
  (vlax-release-object cad)
  (close f)
  (princ (strcat "\n" (rtos i 2 0) " Interface Object Can be use , See C:\IFOTest1.txt ."))
  (princ)
  )

(defun c:IFOTestD(/ f0 lst f)
  (setq f0 (open "c:\\IFOTest1.txt" "r"))
  (while (setq a (read-line f0))
    (if (not (vl-position a lst))
      (setq lst (cons a lst))))
  (close f0)
  (setq lst (acad_strlsort lst))
  (vl-file-delete "C:\\IFOTest.txt")
  (setq f (open "C:\\IFOTest.txt" "w"))
  (foreach a lst
    (write-line a f))
  (close f)
  (princ)
  ) 

chlh_jd

  • Guest
Re: [Help]Through the interface
« Reply #4 on: October 16, 2014, 11:12:35 AM »
In C# it seems easy to do it .
Following codes copy from http://wenku.baidu.com/link?url=zGB-N6w3muQyeU7ycvW9SsJHMd4-PiuGCrUolgZzyAHcgJbmtvXOtERd5Cmi2bStu38JTcCRyFMvy20DUmLx0V0picR_RUugPzg4QcZAknm
Code - C: [Select]
  1.  
  2. public  class  Demo
  3. {
  4.         private string _local1;
  5.         private bool _local2;  
  6.         public string  public1;
  7.         public object  public2;
  8.         public void Foo()
  9.         {
  10.           int  local1 = 10;
  11. int  local2 = 100;  
  12.             Console.WriteLine(local1 + local2);
  13.         }
  14.     }
  15. class Program
  16.     {
  17. static void  Main(string[] args)
  18.         {  
  19.             Type type = typeof (Demo);  
  20.             BindingFlags flags = BindingFlags.Static |
  21.                                  BindingFlags.Instance |
  22.                                  BindingFlags.Public |
  23.                                  BindingFlags.NonPublic;          
  24.  
  25. // Get All fields
  26.         foreach (FieldInfo fieldInfo in
  27. type.GetFields(flags))
  28.             {  
  29.                 Console.WriteLine(fieldInfo.Name);
  30.             }
  31. // Get All Methods
  32. foreach
  33.  (MethodInfo methodInfo in
  34. type.GetMethods(flags))
  35.             {  
  36.                 MethodBody body = methodInfo.GetMethodBody();
  37.                
  38.  
  39. if(body == null)
  40.                 {  
  41. continue;
  42.                 }                
  43.  
  44. // All local Vriables , it seems can't get it
  45. foreach
  46.  (LocalVariableInfo variable in
  47. body.LocalVariables)
  48.                 {  
  49.                     Console.WriteLine(variable);
  50.                 }
  51.             }  
  52.             Console.ReadLine();  
  53.         }
  54.  

chlh_jd

  • Guest
Re: [Help]Through the interface
« Reply #5 on: October 16, 2014, 12:18:31 PM »
Found three objects seems can be use , can know their properties and methods from MSDN .
Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. Microsoft.JScript.COMPropertyInfo
  3. Microsoft.JScript.COMMethodInfo
  4. Microsoft.JScript.COMFieldInfo
  5. |;
  6.  
Do you know how to correct following codes , Many thanks .
Code - Auto/Visual Lisp: [Select]
  1.   (setq obj (vlax-create-object "WScript.Shell"))
  2.   (setq comp (vla-getinterfaceobject (vlax-get-acad-object) "Microsoft.JScript.COMPropertyInfo"))
  3.   (vlax-invoke comp 'GetGetMethod obj);;--> mscorlib: OleAut reported a type mismatch.
  4.