Activate last drawing tab created?

Activate last drawing tab created?

DC-MWA
Collaborator Collaborator
1,003 Views
6 Replies
Message 1 of 7

Activate last drawing tab created?

DC-MWA
Collaborator
Collaborator

Hi all,

I have a little routine I'm working on. It uses a specific template to create a new detail drawing. 

It works well, but do to the nature of autolisp it ends back in the original drawing where initiated.

I need to activate the drawing created as the last thing the program does. Is this even possible?

So, it creates a drawing and it's automatically named Drawing10.dwg. I need to return to that new drawing tab as the last part of the lisp.

See attached lisp...

0 Likes
Accepted solutions (1)
1,004 Views
6 Replies
Replies (6)
Message 2 of 7

ronjonp
Mentor
Mentor

Maybe add this to the end?

(vlax-for x (vla-get-documents (vlax-get-acad-object))
  (if (= "DRAWING10.DWG" (strcase (vla-get-name x)))
    (vla-activate x)
  )
)
0 Likes
Message 3 of 7

DC-MWA
Collaborator
Collaborator

That works, but only if I know it's Drawing10.dwg

Problem I never know what the name will be. All I know is that it's the last created or opened drawing tab.

0 Likes
Message 4 of 7

ronjonp
Mentor
Mentor
Accepted solution

Maybe something like this 🙂

;; Get current docs open
(vlax-for x (vla-get-documents (vlax-get-acad-object)) (setq chk (cons (vla-get-name x) chk)))
;; Add a doc
(vla-add (vla-get-documents (vlax-get-acad-object)) "test")
;; Activate the doc not in our list
(vlax-for x (vla-get-documents (vlax-get-acad-object))
  (or (vl-position (vla-get-name x) chk) (vla-activate x))
)
0 Likes
Message 5 of 7

DC-MWA
Collaborator
Collaborator

Dude.... You are the man!!

That worked perfect.

Thank you very much!!!

0 Likes
Message 6 of 7

ronjonp
Mentor
Mentor

You're welcome .. although there is a simpler way 😉

 

What does this return?

(vlax-dump-Object (setq o (vla-add (vla-get-documents (vlax-get-acad-object)) "test")))

 If you remove the (princ) from your 'newtemplate' function it will return an object which then can be set current. So your code could be reduced to:

(defun c:det1 (/ o tn)			;path
  (setq tn "F:\\MWA\\templates\\DETAIL_TEMPLATE.dwt") ;start a dwg based on template
  (defun newtemplate (tempname)
    (vla-add (vla-get-documents (vlax-get-acad-object)) tempname)
    ;; RJP removed princ so an object is returned
    ;; (princ)
  )
  (if (setq o (newtemplate tn))
    (vla-activate o)
  )
  (princ)
)

Or even further:

(defun c:det1 (/ o)			;path
  (if (setq o (vla-add (vla-get-documents (vlax-get-acad-object))
		       "F:\\MWA\\templates\\DETAIL_TEMPLATE.dwt"
	      )
      )
    (vla-activate o)
  )
  (princ)
)(vl-load-com)
0 Likes
Message 7 of 7

DC-MWA
Collaborator
Collaborator

Wow.. Even better.

It seems to go real slow on several of our machines.... any ideas why? (works great on mine...) All very simiar workstations purchased from dell.

 

0 Likes