Author Topic: Layers frozen in viewports ...  (Read 13102 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Layers frozen in viewports ...
« on: February 11, 2005, 02:11:14 PM »
In the past, like AutoCAD versions < 2000, I relied on the fact that layers frozen in a viewport were embedded in the viewport's extended data, in dxf group 1003 ...

Code: [Select]
(
   (-1 . <Entity name: 7ef55eb8>)
   (0 . "VIEWPORT")

   ...

   (-3
      (
         "ACAD"
         (1000 . "MVIEW")
         (1002 . "{")

         ...

         (1002 . "{")  
         (1003 . "LAY1") ;; layers
         (1003 . "LAY2") ;; frozen
         (1003 . "LAY3") ;; in
         (1003 . "LAY4") ;; this
         (1003 . "LAY5") ;; viewport
         (1002 . "}")
         
         ...
         
         (1002 . "}")
      )
   )
)

Since 2000, the frozen layers also appear as enames in dxf group 331 ...

Code: [Select]
(
   (-1 . <Entity name: 7ef55eb8>)
   (0 . "VIEWPORT")

   ...

   (331 . <Entity name: 7ef55ec8>) <--+
   (331 . <Entity name: 7ef55ed8>)    |
   (331 . <Entity name: 7ef55ee8>)    |
   (331 . <Entity name: 7ef55ef8>)    |
   (331 . <Entity name: 7ef55f08>) <--+--+
                                      |  |
   ...                                |  |
                                      |  |
   (-3                                |  |
      (                               |  |
         "ACAD"                       |  |
         (1000 . "MVIEW")             |  |
         (1002 . "{")                 |  |
                                      |  |
         ...                          |  |
                                      |  |
         (1002 . "{")                 |  |
         (1003 . "LAY1") <------------+  |
         (1003 . "LAY2")                 |
         (1003 . "LAY3")                 |
         (1003 . "LAY4")                 |
         (1003 . "LAY5") <---------------+
         (1002 . "}")

         ...

         (1002 . "}")
      )
   )
)

As a result, one can yank out the frozen layer names by examining the 331 groups ...

Code: [Select]
(defun GetLayersFrozenInViewport ( viewportEname )
    (   (lambda ( data / pair data2 result )
            (while (setq pair (assoc 331 data))
                (if
                    (member
                       '(0 . "LAYER")
                        (setq data2
                            (entget
                                (setq ename
                                    (cdr pair)
                                )
                            )
                        )
                    )
                    (setq result
                        (cons
                            (cdr (assoc 2 data2))
                            result
                        )
                    )
                )
                (setq data
                    (cdr
                        (member pair data)
                    )
                )
            )
            result
        )
        (entget viewportEname)
    )
)

Can anyone see a flaw in this technique (as opposed to the examination of the 1003 group codes)?

Know a better way? Please share.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Layers frozen in viewports ...
« Reply #1 on: February 11, 2005, 02:38:13 PM »
MP,
Here is a routine I started yesterday. Did not get far as play time is short
for me these next few weeks. It is VERY rough, but the forzen layers seems to work
well.

Code: [Select]
(defun c:get_frozen (/ ent)
  (setq ent (vp_sel))
  (setq vp_frz_lst (vpfrzlays ent))
  (princ)
)

(defun c:put_frozen (/ ent)
  (setq ent (car (entsel "\nselect a viewport to updte:")))
  ;;  not here yet.
)

;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=
;; CAB modified code from Jason Piercey
;; Argument: Ename, viewport ename
;; Return: list frozen layer name or nil
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=
(defun vpfrzlays (ename) ; by Jason Piercey
  (mapcar '(lambda (y) (cdr (assoc 2 (entget y))))
          (massoc 341 (entget ename))
  )
)


(defun massoc (key alist / x nlist) ; by Jaysen Long
  (foreach x alist
    (if (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
    )
  )
  (reverse nlist)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=

;;  CAB select VP routine
;;  will work on VP made from other entities
(defun vp_sel (/ vpflag sel-vport entvport vptest)
  (if (= (getvar "TileMode") 1) ; in model space
    ;;------------------------------------------------
    (progn
      (alert "****  You must be in Paper Space to run this routine.  ****")
    )
    ;;------------------------------------------------
    (progn ;else in a layout
      (if (/= (getvar "cvport") 1)
        (command "_pspace") ; close the view port
      )
      (setq vpflag (getvar "cvport")) ; get viewport #
      (while (= vpflag 1) ; No active viewport, Loop until one is picked
        (setq sel-vport (car (entsel "\nSelect view port: ")))
        (if (= sel-vport nil)
          (alert
            "You must select a viewport\r\n    --=<  Try again!  >=--"
          )
          (progn
            (setq entvport (entget sel-vport))
            (if (and ;; not all vp objects are LWPolylines
                     ;;(= (cdr (assoc 0 entvport)) "LWPOLYLINE")
                     (setq vptest (member '(102 . "{ACAD_REACTORS") entvport))
                     (setq vptest (member '(102 . "}") (reverse vptest)))
                     (assoc 330 vptest)
                )
              (setq entvport (entget (cdr (assoc 330 vptest))))
            )

            ;;  Make VP active
            (if (= (cdr (assoc 0 entvport)) "VIEWPORT")
              (progn
                (setq vpflag (cdr (assoc 69 entvport)))
            ;;    (command "mspace") ; activate the last vp active
            ;;    (setvar "cvport" vpflag) ; switch to this vp
              )    
            );  endif  viewport
          )
        ) ;  endif cond  sel-vport
      ) ;endwhile (= vpFlag 1)
    )
  )
  ;;  return the ename of vp or nil
  (cond (entvport (cdr(assoc -1 entvport))))
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Layers frozen in viewports ...
« Reply #2 on: February 11, 2005, 02:48:53 PM »
Thank you CAB, I'll look at that.

Just a heads up, but I believe Jaysen Long wrote massoc. Credit is a good thing.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Layers frozen in viewports ...
« Reply #3 on: February 11, 2005, 03:04:26 PM »
I may have jumped to conclusion as to the author.
link
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Layers frozen in viewports ...
« Reply #4 on: February 11, 2005, 03:11:10 PM »
Jason wrote VpFrzLays; Jaysen wrote Massoc. :)

I was going to say Jason's doesn't work, but then I checked ... dumb stuff Autodesk ... AutoCAD 2002 uses dxf group 341, AutoCAD 2004 uses dxf group 331.

That's as brainiac as needing to check an instance of an xref to find the xref's path (if using the object model).

</rant>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Layers frozen in viewports ...
« Reply #5 on: February 11, 2005, 03:15:50 PM »
You have quite a memory, I'm sure it serves you well.
Just envious.  :)
I updated the credits.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Layers frozen in viewports ...
« Reply #6 on: February 11, 2005, 03:17:17 PM »
Remind me what a memory is 'kay?

:)

(Good on ya btw).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Layers frozen in viewports ...
« Reply #7 on: February 11, 2005, 08:57:40 PM »
Screw it, I'm reverting back to my old way (slight mod) as it works back several releases and performs well enough.

Code: [Select]
(defun GetLayersFrozenInViewport ( viewportEname )
    ;;  © 1999-2005 Michael Puckett
    (   (lambda ( data / pair result )
            (while (setq pair (assoc 1003 data))
                (setq
                    data (cdr (member pair data))
                    result (cons (cdr pair) result)
                )
            )
        )
        (cdadr
            (assoc -3
                (entget
                    viewportEname
                   '("acad")
                )
            )
        )
    )    
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Layers frozen in viewports ...
« Reply #8 on: February 11, 2005, 09:03:52 PM »
How the heck do you do that. :D
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Layers frozen in viewports ...
« Reply #9 on: February 11, 2005, 09:04:34 PM »
Eh?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Layers frozen in viewports ...
« Reply #10 on: February 11, 2005, 09:07:54 PM »
Your code, it's like reading a book from the middle out. :D

it inspires me!!
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Layers frozen in viewports ...
« Reply #11 on: February 11, 2005, 09:09:01 PM »
Neat-o  thanks for sharing. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Layers frozen in viewports ...
« Reply #12 on: February 11, 2005, 09:18:41 PM »
I don't know what to say besides thanks! :)

<Shrugging.mpg>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Layers frozen in viewports ...
« Reply #13 on: February 11, 2005, 09:20:22 PM »
Hey, thanks CAB. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Layers frozen in viewports ...
« Reply #14 on: February 11, 2005, 11:26:28 PM »
MP
In an effort to understand the function I need some explanation of some of the parts.
First it appears as though you left out the MapCar. The parentheses are there.
Is it understood somehow?
Code: [Select]
(   (lambda ( data / pair result )
 ............... ^^^  Mapcar??
 
  Then the list used in the lambda is generated by this
 
Code: [Select]
      (cdadr
            (assoc -3
                (entget  
                    viewportEname
                   '("acad")
                )
            )
        )


Second question, Why is this required
Code: [Select]
'("acad")
and what does it do?

PS I like the new emoticons Mark. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.