variable in paperspace - what am i doing wrong??

variable in paperspace - what am i doing wrong??

Anonymous
Not applicable
1,007 Views
8 Replies
Message 1 of 9

variable in paperspace - what am i doing wrong??

Anonymous
Not applicable

Please someone put me out of my misery and tell me what I am doing wrong:

 

		(foreach tab (layoutlist)
			(setvar "ctab" tab)
			(COMMAND "pspace")
			(if sr (list (cons 8 lay)(cons 410 (getvar "ctab")))											;fix this. (if exists in paper space / current tab))
				(command "_CHANGE" sr "" "P" "LA" "XREF" "")
			);end if
		);foreach tab

sr is a variable for xrefs. When I take away the 'if' lines it works perfectly.
I've tried many different ways of writing it with different filters and can not for the life of me get it working. 

Many many thanks in advance. 

0 Likes
Accepted solutions (1)
1,008 Views
8 Replies
Replies (8)
Message 2 of 9

Sea-Haven
Mentor
Mentor

(if sr so what are you comparing = < > /= to mention a few. What is Sr ((8 . "0") (410 . "Model"))

0 Likes
Message 3 of 9

cadffm
Consultant
Consultant

We don't know want you try exactly.

 

Sample:

1. For each Layout,

2. select ALL OBJECTS on Layer <LAY variable>,

3. if one or more objects are there, start command change..

 

EDIT - Copy&Paste is a troll

 (setq CURTAB (getvar 'CTAB))

(foreach TAB (layoutlist)
(if (setq SR (ssget "_X" (list (cons 8 lay)(cons 410 TAB))))
(command "_.CTAB" TAB "_.PSPACE" "_.CHANGE" SR "" "_p" "_la" "XREF" "")
);end if
)
(setvar 'CTAB CURTAB)

(nothing to do with xrefs and no speacials about paperspace, except your CTAB/ Command PSPACE

Sebastian

0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

You don't have to activate each tab for that thereby making it slow...

 

(defun c:LayerToXref (/ lay sel i edl)
  (if (and (setq lay (getstring T "\nLayer name: "))
	   (setq sel (ssget "_X" (list (cons 8 lay))))
	   (or (tblsearch "LAYER" "XREF")
	       (vl-cmdf "_.LAYER" "_N" "XREF" ""))
	   )
    (repeat (setq i (sslength sel))
      (setq edl (entget (ssname sel (setq i (1- i)))))
      (entmod (subst '(8 . "XREF") (cons 8 lay) edl))))
  (princ)
  )
0 Likes
Message 5 of 9

pbejse
Mentor
Mentor

Not sure but I believe the OP is searching for XREF(s) on multiple tabs and changing its layer to "XREF", AND because the code is invoking the "Change" in the command prompt, it had to to use (layoulist).

 

The entmod approach works without iterating thru the  layoutlist similar to what 

  

BTW: you dont need to create the layer "XREF" if not existing, it will be created within this line of the code

(entmod (subst '(8 . "XREF") (assoc 8 edl) edl))

HTH

 

 

 

 

Message 6 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

Thx @pbejse I wasn't sure and never tried 🙂

 

Anyway, just thought that the general task "All Xrefs to Layer" must be solved 100 times so I googled it. Just needed two clicks to find THIS routine 🙂 👍 

Guess, it worst to clean off those unsupported tags.

 

0 Likes
Message 7 of 9

Anonymous
Not applicable

Sorry, I should clarify:

 

The purpose of this is to put all xrefs (in Model AND Paper space) on a layer called "XREF".

If XREF layer doesn't exist, then one is created.

 

What I was finding was, if no xref existed in model space but did in paper space (a TitleBlock for example), it would trip out. Or if no xrefs existed at all, it would trip out.
So I thought I had to make it go to each layout individually to look "if sr (selection of xrefs) exists" then do. 

I'm going through the replies now to try to fix it - looks like i just have the wrong idea of how to do it. 
Thought I would just clarify first. Cheers.

 

0 Likes
Message 8 of 9

ronjonp
Advisor
Advisor

Did not read this thread closely but here's my quick take at it.

(defun c:foo (/ e i s)
  ;; Filter blocks that are NOT on the XREF layer
  (if (setq s (ssget "_X" '((0 . "insert") (8 . "~XREF"))))
    (repeat (setq i (sslength s))
      (setq e (entget (ssname s (setq i (1- i)))))
      ;; Check if there is a path
      (if (assoc 1 (tblsearch "block" (cdr (assoc 2 e))))
	;; Note if the entity layer is locked this will not error and it will not be changed...
	(entmod (subst '(8 . "XREF") (assoc 8 e) e))
      )
    )
  )
  (princ)
)

 

0 Likes
Message 9 of 9

Anonymous
Not applicable

Ok I've got it! 

BeekKeeCZ I followed your link and found the answer there (posted by pBe).

 

 

	(setq objs (ssget "_X" '((0 . "INSERT")(8 . "~XREF"))))
	(repeat (setq i (sslength objs))
		(setq ent (entget (ssname objs (setq i (1- i)))))
		(if (and (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent)))))))
				(= (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 ent)))))) 0)
			);AND
			(entmod (subst (cons 8 "XREF")(assoc 8 ent) ent))
		);IF
	);REPEAT

 

 

It turns out like some of you said, going to each tab wasn't necessary at all, and the endmod covered generating the layer if it didn't exist. So a lot of my code was cut out because of those factors. 

 

Thank you thank you thank you for the guidance and assistance. 🍻🍻🍻

0 Likes