Author Topic: lisp to vlx  (Read 1517 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
lisp to vlx
« on: February 16, 2023, 02:57:41 AM »
Hi, I have this code to convert lisp files to fas

Code - Auto/Visual Lisp: [Select]
  1. (defun c:LSP2FAS ( / a )
  2.  (if (wcmatch (strcase (setq a (getfiled "Convert LSP File to FAS" (getvar "DWGPREFIX") "" 16))) "*.LSP")
  3.   (progn
  4.    (c:vlide)(vlisp-compile 'st a)
  5.    (princ (strcat "\n File " (vl-string-subst ".fas" ".lsp" a) " created. "))
  6.   );progn
  7.   (alert "File extension must be \".LSP\"   ")
  8.  );if
  9.  (princ)
  10. );end LSP2FAS
  11.  

I try to convert it to LSP2VLX

Code - Auto/Visual Lisp: [Select]
  1. (defun c:LSP2VLX ( / a )
  2.  (if (wcmatch (strcase (setq a (getfiled "Convert LSP File to VLX" (getvar "DWGPREFIX") "" 16))) "*.LSP")
  3.   (progn
  4.    (c:vlide)(vlisp-compile 'st a)
  5.    (princ (strcat "\n File " (vl-string-subst ".vlx" ".lsp" a) " created. "))
  6.   );progn
  7.   (alert "File extension must be \".LSP\"   ")
  8.  );if
  9.  (princ)
  10. );end LSP2VLX
  11.  

but is not working. Can any one help ?

Thanks

dexus

  • Bull Frog
  • Posts: 207
Re: lisp to vlx
« Reply #1 on: February 16, 2023, 04:43:31 AM »
I ran into this problem as well. It has to do with which window is activated.
Code below should do the trick. There might be an easier way, but this hacky way works for me.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:LSP2FAS ( / a )
  2.  (if (wcmatch (strcase (setq a (getfiled "Convert LSP File to FAS" (getvar "DWGPREFIX") "" 16))) "*.LSP")
  3.   (progn
  4.     (c:vlide T) ; Start vlide and return to autocad
  5.     (vla-activate (vla-get-ActiveDocument (vlax-get-acad-object))) ; Activate current drawing
  6.     (vlisp-compile 'st a) ; Compile
  7.     (vla-activate (vla-get-ActiveDocument (vlax-get-acad-object))) ; these two lines are optional, it activates current drawing again
  8.     (c:vlide) ; And than activate vlide so you can close it easily
  9.     (princ (strcat "\n File " (vl-string-subst ".fas" ".lsp" a) " created. "))
  10.   );progn
  11.   (alert "File extension must be \".LSP\"   ")
  12.  );if
  13.  (princ)
  14. );end

PM

  • Guest
Re: lisp to vlx
« Reply #2 on: February 16, 2023, 11:01:13 AM »
Hi dexus. The lisp LSP2FAS working well. I want to convert it to LSP2VLX. Any options?

Thanks

baitang36

  • Bull Frog
  • Posts: 213
Re: lisp to vlx
« Reply #3 on: February 23, 2023, 07:41:04 PM »
Hi dexus. The lisp LSP2FAS working well. I want to convert it to LSP2VLX. Any options?

Thanks
try it
Code - Auto/Visual Lisp: [Select]
  1. (defun try-fas2vlx (datas vlx / 4zijie data data_len files name name_len name16 names newd nlen16 tem vdata vlen vlen16 vlx1 vlx2 vlx2_len vlx2_len16 vlx3 zlen zlen16)
  2.         (setq
  3.                 files(mapcar 'car datas)
  4.                 names(try-strcat files "\") (:fas \"")
  5.                 names(strcat names "\")))")
  6.                 vlx2(string->str16 names)
  7.                 vlx2_len(/(strlen vlx2)2)
  8.                 vlx2_len16(try-str-bu0(try-10-to-16 (+ vlx2_len 91))8)
  9.                 vlx2_len16(apply 'strcat(mapcar '(lambda(x)(strcat (car x)(cadr x)))(reverse(try-lst-div(try-StringSplit vlx2_len16 "")2))))
  10.                 vlx2(strcat vlx2_len16 "D804044C4F414428283A70726F746563746564202E20542920283A6163746976652D78202E20542920283A73657061726174652D6E616D6573706163652920283A6C6F61642D66696C652D6C69737420283A6661732022"vlx2);LOAD((:protected . T) (:active-x . T) (:separate-namespace) (:load-file-list (:fas "
  11.                 tem(rem (/(strlen vlx2)2) 4)
  12.                 vlx3 ""
  13.         )
  14.         (repeat (rem(- 4 tem)4) (setq vlx3(strcat vlx3 "00")))
  15.         (setq vdata(strcat  vlx2 vlx3))
  16.         (foreach n datas
  17.                 (setq name (car n);文件名
  18.                         name16 (string->str16 (strcase name))
  19.                         name_len(/(strlen name16)2)
  20.                         nlen16(try-str-bu0(try-10-to-16 name_len)2)
  21.                         data(cadr n)
  22.                         data_len(/(strlen data)2)
  23.                         zlen(+ name_len data_len 7)
  24.                         zlen16(try-str-bu0(try-10-to-16 zlen)8)
  25.                         zlen16(apply 'strcat(mapcar '(lambda(x)(strcat (car x)(cadr x)))(reverse(try-lst-div(try-StringSplit zlen16 "")2))))
  26.                 )
  27.                 (setq newd(strcat zlen16 "3205" nlen16 name16 data "")
  28.                         tem(rem (/(strlen newd)2) 4)
  29.                         4zijie ""
  30.                 )
  31.                 (repeat (rem(- 4 tem)4) (setq 4zijie(strcat 4zijie "00")))
  32.                 (setq vdata(strcat vdata newd 4zijie))
  33.         )
  34.         (setq vdata (strcat vdata "000000005652544C49422D31"))
  35.         (setq vlen(/(strlen vdata)2)
  36.                 vlen16(try-str-bu0(try-10-to-16 vlen)8)
  37.                 vlen16(apply 'strcat(mapcar '(lambda(x)(strcat (car x)(cadr x)))(reverse(try-lst-div(try-StringSplit vlen16 "")2))))
  38.                 vdata (strcat "5652544C49422D31"vlen16 vdata "00000000")
  39.         )
  40.         (try-file-WriteBinary vlx vdata)
  41. )
  42. (defun try-file-ReadBinary (FileName / node size str stream xmldom)
  43.         (setq xmldom (vlax-create-object "Microsoft.XMLDOM"))
  44.         (setq node (vlax-invoke-method xmldom 'CreateElement "binary"))
  45.         (vlax-put-Property node 'DataType "bin.hex")
  46.         (setq stream (vlax-create-object "ADODB.Stream"))
  47.         (vlax-put-Property stream 'type 1)
  48.         (Vlax-Invoke stream 'open)
  49.         (vlax-invoke-method
  50.                 stream
  51.                 'LoadFromFile
  52.                 FileName
  53.         )
  54.         (setq size(vlax-get-Property stream 'size))
  55.         (vlax-put-Property node 'NodeTypedValue (Vlax-Invoke-Method stream 'Read size))
  56.         (Vlax-Invoke-Method stream 'close)
  57.         (setq str (vlax-get-Property node 'text))
  58.         (vlax-release-object xmldom)
  59.         str
  60. )
  61. (defun try-file-WriteBinary (file str / node stream xmldom)
  62.         (setq xmldom (vlax-create-object "Microsoft.XMLDOM"))
  63.         (setq node (vlax-invoke-method xmldom 'CreateElement "binary"))
  64.         (vlax-put-Property node 'DataType "bin.hex")
  65.         (vlax-put-Property node 'Text str)
  66.         (setq stream (vlax-create-object "ADODB.Stream"))
  67.         (vlax-put-Property stream 'type 1)
  68.         (Vlax-Invoke stream 'open)
  69.         (vlax-invoke-method stream 'write
  70.                 (vlax-get-Property node 'NodeTypedValue)
  71.         )
  72.         (vlax-invoke-method stream 'saveToFile file 2)
  73.         (Vlax-Invoke-Method stream 'close)
  74.         (vlax-release-object xmldom)
  75.         (vlax-release-object stream)
  76. )

PM

  • Guest
Re: lisp to vlx
« Reply #4 on: February 24, 2023, 02:25:06 AM »
Hi baitang36 . I don't know how your code works. I see fas2vlx  but I am searching lsp2vlx. I can not find a "defun c: " any ware . Is not working.

Thanks for the reply.

dexus

  • Bull Frog
  • Posts: 207
Re: lisp to vlx
« Reply #5 on: February 24, 2023, 03:37:27 AM »
Hi dexus. The lisp LSP2FAS working well. I want to convert it to LSP2VLX. Any options?

Thanks
try it
Code - Auto/Visual Lisp: [Select]
  1. [...]

Wow, this looks complicated and therefore interesting.
But I'm not able to test it, there are some missing global functions:
Code: [Select]
string->str16
try-strcat
try-str-bu0
try-10-to-16
try-lst-div
try-StringSplit

baitang36

  • Bull Frog
  • Posts: 213
Re: lisp to vlx
« Reply #6 on: February 26, 2023, 09:30:19 PM »
Hi dexus. The lisp LSP2FAS working well. I want to convert it to LSP2VLX. Any options?

Thanks
try it
Code - Auto/Visual Lisp: [Select]
  1. [...]

Wow, this looks complicated and therefore interesting.
But I'm not able to test it, there are some missing global functions:
Code: [Select]
string->str16
try-strcat
try-str-bu0
try-10-to-16
try-lst-div
try-StringSplit

The program author in the attachment is a friend of mine. The code is only used for learning and communication, not for commercial purposes
« Last Edit: March 05, 2023, 07:47:58 PM by baitang36 »

mhy3sx

  • Newt
  • Posts: 120
Re: lisp to vlx
« Reply #7 on: March 04, 2023, 05:36:06 PM »
Hi baitang36.Can you translate the text in the lisp file you upload to English because I can not read them.
Thanks