Jump to content

How to create a routine in a loop?


rcb007

Recommended Posts

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.

 

Link to comment
Share on other sites

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")
)

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 1 month later...

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)
)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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*"

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

 

 

🍻

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...