importing layout tabs and keeping the order they are in

importing layout tabs and keeping the order they are in

Anonymous
Not applicable
2,575 Views
12 Replies
Message 1 of 13

importing layout tabs and keeping the order they are in

Anonymous
Not applicable

;;;================================================
;;; Modified version of Bland.lsp Hot Tip Hartry Tip 3938
;;;=================================================
(defun c:Bland ()
(setq loc (getfiled "C:\Program Files\Autodesk\ACADM 2011\Acadm\acad\NEW TEMPLATE.DWG" "NEW
TEMPLATE.DWG" "*" 8))
(command"layout" "t" loc "*")
(alert "New Layout been inserted")
(princ)
);end defun

 

Hello, I like to use this small script to import my layout tabs. But I have a problem with the order that the tabs are inserted.  How can I keep the same layout that is in the dwg file after importing?

0 Likes
Accepted solutions (1)
2,576 Views
12 Replies
Replies (12)
Message 2 of 13

pbejse
Mentor
Mentor

@Anonymous wrote:

 

...I have a problem with the order that the tabs are inserted.  How can I keep the same layout that is in the dwg file after importing?


Does that mean keep the order of layout how it was from the source ?

 

Layout tabs from source file

 

actie drawing.JPG

 

Active draw

 

actie drawing 2.JPG

 

Result

 

after import.JPG

 

Correct?

 

 

 

0 Likes
Message 3 of 13

Anonymous
Not applicable

yes import the layout and keep the order.

0 Likes
Message 4 of 13

pbejse
Mentor
Mentor

@Anonymous wrote:

yes import the layout and keep the order.


From a quick test using your posted code. It is a known "bug" that by importing a layout via Layout command the layouts are sorted alphabetically. So we may have to write a different code that reads the source file to "see" the order as it was  on the source file. then invoke Bland command to import the layout then re-order the layout tab afterwards.

 

Or you can try this first -->  GetLayouts - CAD Studio 

 

Steal from Drawing by Lee Mac   <-- link

 

0 Likes
Message 5 of 13

Anonymous
Not applicable

Hello, Yes I tried his steal lisp file. For some reason when I make it part of my routine I get an error when looking through the tabs. I like the KISS lisp files .. that keep it simple.

 

Well thanks for looking into it anyways. 🙂

0 Likes
Message 6 of 13

pbejse
Mentor
Mentor

@Anonymous wrote:

Hello, Yes I tried his steal lisp file. For some reason when I make it part of my routine I get an error when looking through the tabs. I like the KISS lisp files .. that keep it simple.

 

Well thanks for looking into it anyways. 🙂


KISS lisp files.. 😄 , anyways i can write a code for you but not today though, maybe tomorrow. 🙂 hang in there.

 

EDIT: I assume you don't need a dialog for layout selection on i will not add an option for that

 

Cheers

 

0 Likes
Message 7 of 13

pbejse
Mentor
Mentor
Accepted solution

Okay here, keeping it as simple as possible.

 

Using ODBX to read the source file [ Robert Bell ]

Bland to insert the layout [ your posted code ]

Code to re-order the layout 

 

 

;;;		Robert Bell		;;;
(vl-load-com)
(defun i:IsReadOnly  (fileName / fileH)
      (cond ((setq fileH (open filename "a"))
             (close fileH))
            ((not fileH))))

(defun i:CloseDBXDoc  (dbxDoc)
      (vl-catch-all-apply 'vlax-Release-Object (list dbxDoc))
      (setq dbdDoc nil)
      )

(defun i:OpenDBXDoc (fileName / newFile dbxDoc chkOpen)
  (cond	((or (i:IsReadOnly fileName)
	     (=	(strcase (vl-filename-extension filename))
		".DWT"
	     )
	 )
	 (setq newFile (vl-filename-mktemp "Temp .dwg"))
	 (vl-file-copy fileName newFile)
	)
  )

  (if (< (atoi (substr (getvar "ACADVER") 1 2)) 16)
    (setq dbxDoc (vlax-create-object "ObjectDBX.AxDbDocument"))
    (setq dbxDoc (vlax-create-object
		   (strcat "ObjectDBX.AxDbDocument."
			   (substr (getvar "ACADVER") 1 2)
		   )
		 )
	    )
	  )
  (setq	chkOpen
	 (vl-catch-all-apply
	   'vla-Open (list dbxDoc
			 (cond (newFile)
			       (fileName)))))
  (cond	((vl-catch-all-error-p chkOpen) (vlax-Release-Object dbxDoc)
	 nil
	) (dbxDoc)
  )
)

;;;					;;;

;;;=======================================================;;;
;;; Modified version of Bland.lsp Hot Tip Hartry Tip 3938 ;;;
;;;=======================================================;;;
(defun c:Bland ( / aDoc L&Os loc source adlayout) (if (setq L&Os nil loc (getfiled "C:\Program Files\Autodesk\ACADM 2011\Acadm\acad\NEW TEMPLATE.DWG" "NEW TEMPLATE.DWG" "dwg;dwt" 16 )) (progn (setq source (i:openDBXDoc loc)) (vlax-for itm (vla-get-layouts source) (if (/= (setq ln (vla-get-name itm)) "Model") (setq L&Os (cons (list (vla-get-TabOrder itm) ln) L&Os) ) ) ) (i:CloseDBXDoc loc) (command "layout" "t" loc "*") (setq adlayout (Vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)) ) ) (foreach itm (mapcar 'cadr (vl-sort L&Os '(lambda (a b) (> (Car a) (car b)))) ) (vla-put-TabOrder (vla-item adlayout itm) 1 ) ) (alert "New Layout been inserted") ) )(princ) )

HTH

 

0 Likes
Message 8 of 13

Anonymous
Not applicable

wow, it looks good. I need to try it out a home. I'm at work, working on this mess right now.. 🙂

 

Thanks I will give it a go. mate..

 

Regards Nick mess.jpg

0 Likes
Message 9 of 13

Anonymous
Not applicable

dear autocad. I think that I have the answer to my question. But I do not have the time to test the lisp.

 

Thanks for the help from all of you fella's. I feel like I owe you a few bucks , or beers. 

 

Regards Nick

0 Likes
Message 10 of 13

Anonymous
Not applicable

Thanks , the script works well. It would me nice to have an option so that it will automatically select the dwg file to import from. Instead of a prompt.

 

I like this lisp better than bland or steal ..

 

Nick

 

 

0 Likes
Message 11 of 13

pbejse
Mentor
Mentor

@Anonymous wrote:
......It would me nice to have an option so that it will automatically select the dwg file to import from. Instead of a prompt. 

Nick


 

If the source file is constant, does that mean the name of the layout(s) are constant as well?

 

Then i guess we don't need to read the source file and just go ahead and hard-code the name on the lisp routine

 

 

(defun c:Bland (/ loc)
  (if
    (findfile (setq
      loc  "C:\Program Files\Autodesk\ACADM 2011\Acadm\acad\NEW TEMPLATE.DWG"
      )
    )
     (progn
       (command "layout" "t" loc "*")
	 (foreach itm '("Second Sheet" "First Sheet");<-- the name of the layout(s) in reverse order
	   (if (member itm (layoutlist))
	     (vla-put-TabOrder
	       (vla-item
		 (Vla-get-layouts
		   (vla-get-ActiveDocument (vlax-get-acad-object))
		 )
		 itm
	       )
	       1
	     )
	   )
	 )
	 (alert "New Layout been inserted")
       )
     )
  (princ)
)

 

Besides, you can always drag the layout(s) to the first position after layout  import and it does not require a lisp code at all.

 

HTH

 

 

0 Likes
Message 12 of 13

Anonymous
Not applicable

Hello , I can't thank you guys enough for helping me. I hope that Karma scratches your back in return for helping people learn. Peace.


Nick

0 Likes
Message 13 of 13

Anonymous
Not applicable

I tried adding this to the lisp file and it didn't work for me. Also when the prompt comes up the directory is my documents. I'm not sure why it would do that. You have the right search path in the lisp file. 

 

 

0 Likes