PDA

View Full Version : AutoCAD New command from Vlisp


gjadams
2006-06-28, 02:07 AM
Why can I not use the AutoCAD "new" command from within vlisp to begin a new drawing.
(command "new") returns nil. Yet on the command line within AutoCAD "new" opens the dialogue box

rkmcswain
2006-06-28, 05:44 AM
Try this. Tested on R2007


(vl-load-com)
(vla-add
(vla-get-documents
(vlax-get-acad-object)
)
)

gjadams
2006-06-28, 10:40 PM
Thanks that was great. Now I need to make that drawing the active one. How can I modify the code to remain in the document or call it back?

Terry Cadd
2006-06-29, 01:15 AM
There may be several ways of accomplishing this. I've included the function GetDwgsList for you to test out, and see if it also works on your system.
After loading GetDwgsList, run the previous code submitted by R.K. McSwain, then include the line referring to GetDwgsList below:

(vl-load-com)(vla-add (vla-get-documents (vlax-get-acad-object)))
(command "vbastmt" (strcat "Application.Documents.Item(" (itoa (1- (length (GetDwgsList)))) ").Activate"))

; GetDwgsList.lsp - Returns a list of open drawings
; Use (length (GetDwgsList)) for the number of open drawings.
(defun GetDwgsList (/ AcadOBJ DocsOBJ DwgsList@)
(vl-load-com)
(setq AcadOBJ (vlax-get-acad-object)
DocsOBJ (vlax-get-property AcadOBJ "Documents")
DwgsList@ nil
);setq
(vlax-for ForItem DocsOBJ
(setq DwgsList@ (cons (strcat (vlax-get-property ForItem "Path") "\\"
(vlax-get-property ForItem "Name")) DwgsList@))
);vlax-for
(setq DwgsList@ (reverse DwgsList@))
DwgsList@
);defun GetDwgsList

Terry Cadd

[ Moderator Action = ON ] How to use [ CODE ] tags? (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]

gjadams
2006-06-29, 04:10 AM
Thanks for your help. I will try this and get back to you.