Jump to content
rcb007

How to create a routine in a loop?

Recommended Posts

rcb007

I have several layout tabs in drawing, and I need to go through each tab to adjust the scale and layers, then go on to the next.

I am trying to manually do it within the code, but did not know how to make it loop to the last layout tab.

(defun C:AMVP_Part3()
;;Viewport 1
(command "-layout" "set" "C3.1")
(command "-layer" "Freeze" "xMatchline*" "Thaw" "*Area1" "")
(command "_mspace")
(command "zoom" "extents")
(command "ZOOM" "Scale" "1/20xp")
(command "_pspace")




;;Viewport 2
(command "-layout" "set" "C3.2")
(command "-layer" "Freeze" "xMatchline*" "Thaw" "*Area2" "")
(command "_mspace")
(command "zoom" "extents")
(command "ZOOM" "Scale" "1/20xp")
(command "_pspace")



;;Viewport 3
(command "-layout" "set" "C3.3")
(command "-layer" "Freeze" "xMatchline*" "Thaw" "*Area3" "")
(command "_mspace")
(command "zoom" "extents")
(command "ZOOM" "Scale" "1/20xp")
(command "_pspace")



;;Viewport 4
(command "-layout" "set" "C3.4")
(command "-layer" "Freeze" "xMatchline*" "Thaw" "*Area4" "")
(command "_mspace")
(command "zoom" "extents")
(command "ZOOM" "Scale" "1/20xp")
(command "_pspace")

(princ))
this goes all the way to 30 layout tabs.

 

Share this post


Link to post
Share on other sites
ronjonp

Try something like this:

(foreach name (layoutlist)
  (setvar 'ctab name)
  (command "-layer" "Freeze" "xMatchline*" "Thaw" "*Area2" "")
  (command "_mspace")
  (command "zoom" "extents")
  (command "ZOOM" "Scale" "1/20xp")
  (command "_pspace")
)

 

Share this post


Link to post
Share on other sites
rcb007
Posted (edited)

Thanks man!. That piece helps out a lot! Saves a lot of extra anticipating code.

 

I forgot to mention this piece. I apologize.

 

with the  (command "-layer" "Freeze" "xMatchline*" "Thaw" "*Area1" "")

 

So how would this work if I needed the first tab be to turn on "*Area1"

Then the next time would be "*Area2" and so forth?

 

If it cant, I its not the end of the world.

 

Edited by rcb007

Share this post


Link to post
Share on other sites
ronjonp
Posted (edited)

Here is one way untested:

(defun c:foo (/ n)
  (setvar 'cmdecho 0)
  (foreach name	(layoutlist)
    (setvar 'ctab name)
    (setq n (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout"))))
    (command "-layer"
	     "Freeze"
	     "xMatchline*"
	     "Thaw"
	     (strcat "*Area" (itoa (cdr (assoc 71 (dictsearch n name)))))
	     ""
    )
    (command "_mspace")
    (command "zoom" "extents")
    (command "ZOOM" "Scale" "1/20xp")
    (command "_pspace")
  )
  (setvar 'cmdecho 1)
  (princ)
)

Here's a VL version for your edumacation:

(defun c:foo nil
  (setvar 'cmdecho 0)
  (vlax-for lyt	(vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (if	(= 0 (vlax-get lyt 'modeltype))
      (progn (setvar 'ctab (vla-get-name lyt))
	     (command "-layer"
		      "Freeze"
		      "xMatchline*"
		      "Thaw"
		      (strcat "*Area" (itoa (vla-get-taborder lyt)))
		      ""
	     )
	     (command "_mspace")
	     (command "zoom" "extents")
	     (command "ZOOM" "Scale" "1/20xp")
	     (command "_pspace")
      )
    )
  )
  (setvar 'cmdecho 1)
  (princ)
)
(vl-load-com)

 

Edited by ronjonp

Share this post


Link to post
Share on other sites
rcb007

It works great! Thank you again. Saves so much time!

Share this post


Link to post
Share on other sites
ronjonp
2 minutes ago, rcb007 said:

It works great! Thank you again. Saves so much time!

Glad to help out 🍻

Share this post


Link to post
Share on other sites
rcb007

Gotta a question. I am trying to configure the same code not to use the xref.

 

I thought all I had to do was remove the "Matchline" part of the code, but does it need to be there or replaced with a (*)?

 

(defun c:foo (/ n)
  (setvar 'cmdecho 0)
  (foreach name	(layoutlist)
    (setvar 'ctab name)
    (setq n (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout"))))
    (command "-layer"
	     "Freeze"
	     "*" <--- How to remove the Xref Name and just use the layers within the drawing?
	     "Thaw"
	     (strcat "*Area" (itoa (cdr (assoc 71 (dictsearch n name)))))
	     ""
    )
    (command "_mspace")
    (command "zoom" "extents")
    (command "ZOOM" "Scale" "1/20xp")
    (command "_pspace")
  )
  (setvar 'cmdecho 1)
  (princ)
)

 

Share this post


Link to post
Share on other sites
ronjonp

You want to freeze all xref layers ( "*|*" ) or exclude xref layers ( "~*|*" ) ?

Share this post


Link to post
Share on other sites
rcb007

Currently when I run the routine it works like it should with the matchline xref attached in the sheet.

 

If I were to bind the xref into  the sheet dwg (as a block) and run the routine, it does not seem to work as it does if it was an xref.

Share this post


Link to post
Share on other sites
ronjonp

Post a sample drawing .. I'm not following what you're trying to do. If you bind a drawing the layer names change based on your BINDTYPE system variable.

 

Just Guessing use:  "*xMatchline*"

 

Share this post


Link to post
Share on other sites
rcb007

Ronjonp,

 

I don't know what I did, but I got it working. I guess I had to reboot my pc, but its working.

 

 

Edited by rcb007

Share this post


Link to post
Share on other sites
ronjonp
On 7/29/2020 at 12:15 PM, rcb007 said:

Ronjonp,

 

I don't know what I did, but I got it working. I guess I had to reboot my pc, but its working.

 

 

🍻

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...