<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Vla-open and execute command fails in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7824699#M107969</link>
    <description>&lt;P&gt;This is not the way to add &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;vla-sendcommand&lt;/FONT&gt;&lt;/STRONG&gt; function. Can you post your code &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;c:mycommand&lt;/FONT&gt;&lt;/STRONG&gt;?&lt;/P&gt;</description>
    <pubDate>Sat, 03 Mar 2018 15:35:05 GMT</pubDate>
    <dc:creator>Satish_Rajdev</dc:creator>
    <dc:date>2018-03-03T15:35:05Z</dc:date>
    <item>
      <title>Vla-open and execute command fails</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7819049#M107964</link>
      <description>&lt;P&gt;Dear coders,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I open dwg's using the vla-open like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  (foreach &amp;amp; Files	
  (setq File (vla-open (vla-get-documents (vlax-get-acad-object)) &amp;amp;))
	(c:mycommand)	
	;(vla-save File)
	;(vla-close File)
	(vlax-release-object File)
  )&lt;/PRE&gt;&lt;P&gt;All is working fine except the (c:mycommand)&lt;BR /&gt;it is not even loaded on the dwg's that are being opened while the vla-save is working&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to execute external lsp while using vla-open??&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 11:55:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7819049#M107964</guid>
      <dc:creator>DGRL</dc:creator>
      <dc:date>2018-03-01T11:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Vla-open and execute command fails</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7819121#M107965</link>
      <description>&lt;P&gt;I think there are 2 options do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Use&amp;nbsp;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;vla-sendcommand&lt;/STRONG&gt;&lt;/FONT&gt; function in your current code.&amp;nbsp;&lt;A href="https://www.afralisp.net/archive/methods/list/sendcommand_method.htm" target="_blank"&gt;More details&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Perform functions in current drawing and then send results to other drawing using&amp;nbsp;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;vla-copyobjects&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Example : I'm using this for 1 of my program&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;(&lt;FONT color="#0000FF"&gt;defun&lt;/FONT&gt; &lt;FONT color="#000000"&gt;copy:object&lt;/FONT&gt; (&lt;FONT color="#000000"&gt;sourcedocument targetdocument object&lt;/FONT&gt; &lt;FONT color="#0000FF"&gt;/&lt;/FONT&gt; a)
  (&lt;FONT color="#0000FF"&gt;if&lt;/FONT&gt; (&lt;FONT color="#0000FF"&gt;setq&lt;/FONT&gt; &lt;FONT color="#000000"&gt;a&lt;/FONT&gt; (&lt;FONT color="#0000FF"&gt;vla-copyobjects&lt;/FONT&gt;
		&lt;FONT color="#000000"&gt;sourcedocument&lt;/FONT&gt;
		(&lt;FONT color="#0000FF"&gt;vlax-safearray-fill&lt;/FONT&gt;
		  (&lt;FONT color="#0000FF"&gt;vlax-make-safearray vlax-vbobject&lt;/FONT&gt; '(&lt;FONT color="#008000"&gt;0 &lt;FONT color="#800000"&gt;.&lt;/FONT&gt; 0&lt;/FONT&gt;))
		  (&lt;FONT color="#0000FF"&gt;list&lt;/FONT&gt; &lt;FONT color="#000000"&gt;object&lt;/FONT&gt;)
		)
		(&lt;FONT color="#0000FF"&gt;vla-get-modelspace&lt;/FONT&gt; &lt;FONT color="#000000"&gt;targetdocument&lt;/FONT&gt;)
	      )
      )
    (&lt;FONT color="#0000FF"&gt;car&lt;/FONT&gt; (&lt;FONT color="#0000FF"&gt;vlax-safearray-&amp;gt;list&lt;/FONT&gt; (&lt;FONT color="#0000FF"&gt;vlax-variant-value&lt;/FONT&gt; &lt;FONT color="#000000"&gt;a&lt;/FONT&gt;)))
  )
)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Mar 2018 12:21:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7819121#M107965</guid>
      <dc:creator>Satish_Rajdev</dc:creator>
      <dc:date>2018-03-01T12:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Vla-open and execute command fails</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7819620#M107966</link>
      <description>&lt;P&gt;HI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply&lt;/P&gt;&lt;P&gt;I will try option 1 because I fill in data that is not present in the current dwg&amp;nbsp; (like Attributes)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 14:44:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7819620#M107966</guid>
      <dc:creator>DGRL</dc:creator>
      <dc:date>2018-03-01T14:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Vla-open and execute command fails</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7819638#M107967</link>
      <description>Can you please post that code here? So that we can get idea of it</description>
      <pubDate>Thu, 01 Mar 2018 14:49:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7819638#M107967</guid>
      <dc:creator>Satish_Rajdev</dc:creator>
      <dc:date>2018-03-01T14:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Vla-open and execute command fails</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7820486#M107968</link>
      <description>&lt;P&gt;The red bols line is giving back parameter not optional&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;;;;CADALYST 03/05 Tip2023: PurgeFiles.lsp	Directory Clean Up	(c) Andrzej Gumula


;;; [c]2004 Andrzej Gumula, Katowice, Poland
;;; e-mail: a.gumula@wp.pl
;;; This routine purge dwg files from selected folder
&lt;BR /&gt;&lt;BR /&gt;

(vl-load-com)

(defun c:PurgeAuditFiles (/ FilesList DwgPath SubDir Files File)

(defun GetFolder (/ Dir Item Path)
 (cond
  ((setq Dir (vlax-invoke (vlax-get-or-create-object "Shell.Application") 'browseforfolder 0 "Select folder with DWG files:" 1 ""))
   (cond
    ((not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke-method (list Dir 'Items))))
     (setq Item (vlax-invoke-method (vlax-invoke-method Dir 'Items) 'Item))
     (setq Path (vla-get-path Item))
     (if (not (member (substr Path (strlen Path) 1) (list "/" "\\")))
      (setq Path (strcat Path "\\"))
     );end if
    )
   );end cond
  )
 );end cond
 Path
);end GetFolder


(defun vl-findfile (Location / DirList Path AllPath)
 (MakeDirList Location)
 (setq DirList (cons Location DirList))
 (foreach Elem DirList 
  (if (setq Path (vl-directory-files Elem "*.dwg"))
   (foreach Item Path (setq AllPath (cons (strcat Elem "/" Item)  AllPath)))
  );end if
 )
 (reverse AllPath)
);end vl-findfile

(defun MakeDirList (Arg / TmpList)
 (setq TmpList (cddr (vl-directory-files Arg nil -1)))
 (cond
  (TmpList
   (setq DirList (append DirList (mapcar '(lambda (z) (strcat Arg "/" z)) TmpList)))
   (foreach Item TmpList (MakeDirList (strcat Arg "/" Item)))
  )
 );end cond
);end MakeDirList

(if (not FileSystemObject)
  (setq FileSystemObject (vla-getInterfaceObject (vlax-get-acad-object) "Scripting.FileSystemObject"))
);end if

(cond
((= (getvar "SDI") 0)
(cond
 ((setq DwgPath (GetFolder))
  (initget "Yes No")
  (setq Subdir (cond ((getkword "\nLooking for subfolders? No,[Yes]: "))
		     (T "Yes")))
  (if (equal SubDir "Yes")
   (setq Files (vl-findfile (substr DwgPath 1 (1- (strlen DwgPath)))))
   (setq Files (mapcar '(lambda (x) (strcat dwgpath x))(vl-directory-files DwgPath "*.dwg" 1)))
  );end if
  (setq Files (mapcar 'strcase Files))
  (cond
    (Files
     (vlax-for &amp;amp; (vla-get-documents (vlax-get-acad-object )) (setq FilesList (cons (strcase (vla-get-fullname &amp;amp;)) FilesList)))
     (foreach &amp;amp; Files
      (cond
	((not (member &amp;amp; FilesList ))
         (cond
	  ((/= (logand (vlax-get-property (vlax-invoke-method FileSystemObject 'getfile &amp;amp;) 'Attributes) 1) 1)
	   (cond
	     ((setq File (vla-open (vla-get-documents (vlax-get-acad-object)) &amp;amp;))
	      (prompt (strcat "\nPurge " &amp;amp; ". Please wait..."))
		  
		  
		  
&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;		  (vla-SendCommand File (c:MYCOMMAND))	&amp;lt;-- gives back ActiveX Server returned an error: Parameter not optional 
            &lt;/STRONG&gt; &lt;/FONT&gt; ;(vla-purgeall File)
             ; (vla-AuditInfo File T)
			  
			  
			  
			  
	      (prompt (strcat "\nSave and close " &amp;amp;))
	      (vla-save File)
	      (vla-close File)
	      (vlax-release-object File)
	     )
	     (T (prompt (strcat "\nCannot open " &amp;amp; "\nDrawing file was created by an incompatible version. ")))
	   );end cond
	  )
	  (T (prompt (strcat &amp;amp; " is read-only. Purge canceled. ")))
	 );end cond
	)
	(T (prompt (strcat &amp;amp; " is open now. Purge canceled. ")))
      );end cond

     );end foreach
    )
    (T (prompt "\nNothing files found to purge. "))
  );end cond
 )
 (T (prompt "\nNothing selected. "))
);end cond
)
(T (prompt "\nThe routine is not available in SDI mode. "))
);end cond
(princ)
);end c:PurgeFile

(prompt "\nLoaded new command PurgeFiles. ")
(prompt "\n[c]2004 Andrzej Gumula. ")
(princ)




&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Mar 2018 18:41:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7820486#M107968</guid>
      <dc:creator>DGRL</dc:creator>
      <dc:date>2018-03-01T18:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Vla-open and execute command fails</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7824699#M107969</link>
      <description>&lt;P&gt;This is not the way to add &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;vla-sendcommand&lt;/FONT&gt;&lt;/STRONG&gt; function. Can you post your code &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;c:mycommand&lt;/FONT&gt;&lt;/STRONG&gt;?&lt;/P&gt;</description>
      <pubDate>Sat, 03 Mar 2018 15:35:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7824699#M107969</guid>
      <dc:creator>Satish_Rajdev</dc:creator>
      <dc:date>2018-03-03T15:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Vla-open and execute command fails</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7824822#M107970</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind LISP execution only work in document context.&lt;/P&gt;
&lt;P&gt;IOW, a LISP expression/function started in Drawing1 can not continue in another drawing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, Drawing1 is the active document in which you execute:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(setq doc (vla-Open (vla-get-documents (vlax-get-acad-object)) "C:\\Temp\\Test.dwg"))
(vla-SendCommand doc "_circle 0,0 10 ")&lt;/PRE&gt;
&lt;P&gt;It will open Test.dwg (if found) but it draws the circle in Drawing1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's to say you cannot use (command ...) or (vla-SendCommand ...) in another drawing,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can use other vla* functions to access to the newly opened document.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(setq doc (vla-Open (vla-get-documents (vlax-get-acad-object)) "C:\\Temp\\Test.dwg"))
(vla-AddCircle (vla-get-ModelSpace doc) (vlax-3d-point '(0. 0. 0.)) 10.)&lt;/PRE&gt;
&lt;P&gt;This way, the circle will be drawn in Test.dwg.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if you can build a new function with the behavior of 'c:mycommand ' which accepts a document (vla-object) as argument and which only uses vla functions to edit the document (or its properties), you should be able to run it in a newly opened document.&lt;/P&gt;
&lt;P&gt;You could even do better; open the drawing "in memory" only (that's to say not in the editor) with ObjectDBX, this runs much more faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always with the same example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun gc:GetAxDbDoc (filename / majVer progId axdbdoc)
  (vl-load-com)
  (setq progId
         (if (&amp;lt; (setq majVer (substr (getvar 'acadver) 1 2)) "16")
           "ObjectDBX.AxDbDocument"
           (strcat "ObjectDBX.AxDbDocument." majVer)
         )
  )
  (if (setq axdbdoc (vlax-create-object progId))
    (if (vl-catch-all-apply
          'vla-open
          (list axdbdoc filename)
        )
      (not (vlax-release-object axdbdoc))
      axdbdoc
    )
  )
)

(if (setq doc (gc:GetAxDbDoc "C:\\Temp\\Test.dwg"))
  (progn
    (vla-AddCircle (vla-get-ModelSpace doc) (vlax-3d-point '(0. 0. 0.)) 10.)
    (vla-SaveAs doc "C:\\Temp\\Test.dwg")
    (vlax-release-object doc)
  )
)&lt;/PRE&gt;
&lt;P&gt;This way the circle is drawn in Test.dwg even the file heven't been open in the AutoCAD editor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Mar 2018 18:00:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7824822#M107970</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-03-03T18:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Vla-open and execute command fails</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7826595#M107971</link>
      <description>&lt;P&gt;Have a look on this as well&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/48794935/batch-run-autolisp-with-python/48798152#48798152" target="_blank"&gt;Click here&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 07:06:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-open-and-execute-command-fails/m-p/7826595#M107971</guid>
      <dc:creator>Satish_Rajdev</dc:creator>
      <dc:date>2018-03-05T07:06:14Z</dc:date>
    </item>
  </channel>
</rss>

