Lisp to viewport freeze layers based on layout tab name

Lisp to viewport freeze layers based on layout tab name

Anonymous
Not applicable
3,277 Views
12 Replies
Message 1 of 13

Lisp to viewport freeze layers based on layout tab name

Anonymous
Not applicable

Hi all,

 

I currently work in a practice which works with individual dwg files as opposed to multitab layouts. We use scripts relating to sheet names to control layers for text on overlapping sheets. I am now faced with using a system using multitab layouts and therefor using viewport overrides to freeze layers of overlapping sheets. Problem is if we have 50-100 sheets that is a lot of manual work I was once able to avoid. 

 

Currently the the script works on a generic naming convention and the use of wildcards to freeze the layers across different xrefs. For example: Sheet_01.scr freezes off all layers in all xrefs with the layer naming convention Sheet_xx and thaws layers with Sheet_01 so that objects only pertaining to sheet one are displayed. 

 

What I need is a lisp which does the same but viewport freezes layers relating to a tab layout name. So in layout tab GA_31 it VP freezes all layers with Sheet_* in them and thaws layers with Sheet_31 in them. It would need to work generically for all existing layouts so if extra layouts are added later and the lisp run again it picks up the new tab and freezes/thaws the relevant layers in that tab. It also need to work across multiple viewports in these tabs. 

 

I was thinking it wouldn't be too hard and was going to try searching myself and bluffing my way through it but couldn't find anything specific enough and am afraid I am a little out of my depth. 

 

Would apprecite any help. 

0 Likes
Accepted solutions (2)
3,278 Views
12 Replies
Replies (12)
Message 2 of 13

hmsilva
Mentor
Mentor
Accepted solution

Hi Fatrobo,

 

perhaps something like this

(Untested)

 

(defun c:demo (/ _ctab num ss)
  (setq _ctab (getvar 'CTAB))
  (foreach x (layoutlist)
    (setvar 'CTAB x)
    (if (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x) (cons -4 "!=") (cons 69 1))))
      (progn
        (if (not (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2)))
          (command "_.mspace")
        )
        (setq num (substr x (+ (vl-string-position (ascii "_") x) 2)))
        (command "_.vplayer" "_F" "*|*Sheet_*" "_S" ss "" "_T" (strcat "*|*Sheet_" num "*") "_S" ss "" "")
        (command "_.pspace")
      )
    )
  )
  (setvar 'CTAB _ctab)
  (command "_.qsave")
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 13

Anonymous
Not applicable

I have only run it on a quick test setup but it looks to do what I was after.

 

U git a "autocad lisp malformed list on input" but fixed it with an addition ")" at the end.

(defun c:Sheettext (/ _ctab num ss)
  (setq _ctab (getvar 'CTAB))
  (foreach x (layoutlist)
    (setvar 'CTAB x)
    (if (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x) (cons -4 "!=") (cons 69 1))))
      (progn
        (if (not (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2)))
          (command "_.mspace")
        )
        (setq num (substr x (+ (vl-string-position (ascii "_") x) 2)))
        (command "_.vplayer" "_F" "*|*Sheet_*" "_S" ss "" "_T" (strcat "*|*Sheet_" num "*") "_S" ss "" "")
        (command "_.pspace")
      )
    )
  )
  (setvar 'CTAB _ctab)
  (command "_.qsave")
  (princ))

Thank you very much for your help. 

0 Likes
Message 4 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

I have only run it on a quick test setup but it looks to do what I was after.

 

U git a "autocad lisp malformed list on input" but fixed it with an addition ")" at the end.

Thank you very much for your help. 


You're welcome, Fatrobo!


The "autocad lisp malformed list on input" error, was because you did not copy the last parenthesis/brackets at my code, if you look closely you'll see the last bracket after the (princ)...

 

Such mistakes would be easily preventable with the introduction of a 'select code' button, to select all code...

Let us hope that functionality to be added at the forums.

Henrique

EESignature

0 Likes
Message 5 of 13

Anonymous
Not applicable

Hi Henrique,

 

I just realised the tab naming convention this client wants us to us is actually a "-" not a "_". So the tab names would be GA-01 or RL-01. I thought I should be able to make these changes myself but can't seem to get it working.

 

Any ideas?

0 Likes
Message 6 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

Hi Henrique,

 

I just realised the tab naming convention this client wants us to us is actually a "-" not a "_". So the tab names would be GA-01 or RL-01. I thought I should be able to make these changes myself but can't seem to get it working.

 

Any ideas?


Hi Fatrobo

change

(setq num (substr x (+ (vl-string-position (ascii "_") x) 2)))

to

 

(setq num (substr x (+ (vl-string-position (ascii "-") x) 2)))

Hope this helps,
Henrique

 

EESignature

0 Likes
Message 7 of 13

Anonymous
Not applicable

Henrique,

 

This has been a hit so far! I have a modification i would like to make but am keen to understand it a little better myself. I am trying to get the code to look at the final two numbers only. So a user could have a tab name GA-02 or GA-DI-02 and it still returns the variable num as "02".

 

I have done some investigating into the code below using this:

 

http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-2B0BF48B-FA26-431B-8EC3-DD0BD9F147A0

 

My code still doesn't seem to work.

 

(setq num (substr x (+ ((vl-string-position (ascii "-") nill T) x) 2)))
0 Likes
Message 8 of 13

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Henrique,

 

This has been a hit so far! I have a modification i would like to make but am keen to understand it a little better myself. I am trying to get the code to look at the final two numbers only. So a user could have a tab name GA-02 or GA-DI-02 and it still returns the variable num as "02".

 

I have done some investigating into the code below using this:

 

http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-2B0BF48B-FA26-431B-8EC3-DD0BD9F147A0

 

My code still doesn't seem to work.

 

(setq num (substr x (+ ((vl-string-position (ascii "-") nill T) x) 2)))

Hi

try,

(vl-string-position (ascii "-") x 0 T)
;x => the string
;0 => the start position
;T => from the end argument
(setq num (substr x (+ (vl-string-position (ascii "-") x 0 T) 2)))

Hope this helps,
Henrique

 

EESignature

0 Likes
Message 9 of 13

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

 

My code still doesn't seem to work.

 

(setq num (substr x (+ ((vl-string-position (ascii "-") nill T) x) 2)))

In addition of Henrique's syntaxe correction... Be careful of typos: it's nil, not nill. (yet, syntaxe is wrong, see Henrique's)

0 Likes
Message 10 of 13

Anonymous
Not applicable

Works a treat, thank you all!

0 Likes
Message 11 of 13

Anonymous
Not applicable

It seems when I am compiling a .fas file in autocad's visual lisp editor, i get "Error: bad argument value: non-negative: -1".

 

(defun c:Sheettextb (/ _ctab num ss)
(setq     timez (rtos (getvar "CDATE") 2 8)      ;Get the date and converts from Real to String
                timez (ATOI (substr timez 1 4))  ;Get first 4 characters (year) and convert to integer
);Setq

(Cond    ((<= timez 2016)   ;Set Conditional if date is less than or equal to 2018

  (setq _ctab (getvar 'CTAB))
  (foreach x (layoutlist)
    (setvar 'CTAB x)
    (if (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x) (cons -4 "!=") (cons 69 1))))
      (progn
        (if (not (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2)))
          (command "_.mspace")
        )
       	(vl-string-position (ascii "-") x 0 T)
	;x => the string
	;0 => the start position
	;T => from the end argument
	(setq num (substr x (+ (vl-string-position (ascii "-") x 0 T) 2)))
        (command "_.vplayer" "_F" "*|*Sheet_*" "_S" ss "" "_T" (strcat "*|*Sheet_" num "*") "_S" ss "" "")
        (command "_.pspace")
      )
    )
  )
  (setvar 'CTAB _ctab)
  (command "_.qsave")
  (princ))
)                        ;Close current conditional
);Cond                   ;Close main conditional
0 Likes
Message 12 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

It seems when I am compiling a .fas file in autocad's visual lisp editor, i get "Error: bad argument value: non-negative: -1".

 


Tested in VLIDE without error...

 _fatrobo_fas.PNG

 

Henrique

EESignature

0 Likes
Message 13 of 13

Anonymous
Not applicable

This LISP looks like it would achieve what I'm hoping, but I'm struggling to get it going. I'd like to have the routine freeze a certain amount of layers bar one (for conveyancing), however I'm not sure I understand the code enough to make changes myself. One way I thought this could be done is to freeze all the layers I'd like frozen initially and then get the LISP to thaw the one layer needed in relation to the layout name.

 

Is this possible?

 

0 Likes