Author Topic: unlock a selected viewport.  (Read 3099 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
unlock a selected viewport.
« on: December 22, 2005, 03:23:08 PM »
Hi all,,

Just a last question before to leave....for 2006

I have wrote this little routine..
this is supposed to select a VIEWPORT, detect if it locked
if yes, unlock the viewport and change the color..

but this is working only for simple square VIEWPORT...
so if someone can give me a hand to this...

thanks.

Code: [Select]
(defun c:as ()
 (setq vname (ssget))
  (if (not vname)
    (progn
      (alert " No selection.")
      (exit)
    )
 (progn
 (setq sscount (sslength vname))
 (setq val1 (- sscount 1))
(repeat sscount
   (setq a1 (entget (ssname vname val1)));;détail de l'entité
   (setq ent1 (cdr (assoc 0 a1)));;check si c'est un VIEWPORT
 (if (= ent1 "VIEWPORT")
(progn 
  (setq MVLock (cdr (assoc 90 a1)));;32864 = Non Verouillé   49248 = Verouillé
   (if (or (= MVLock 98368)(= MVLock 32864));;Non verouuillé
     (progn         
     (vl-cmdf "_MVIEW" "_L" "_ON" (cdar a1) "" )
     (vl-cmdf "_chprop" (cdar a1) "" "_co" MVdiaB "")
))))   
 (setq val1 (- val1 1))
))))
Keep smile...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: unlock a selected viewport.
« Reply #1 on: December 22, 2005, 03:34:07 PM »
I would use ActiveX for this.  Filter your selection set selection for just viewports.  Convert them to objects (instead of entities), and check the DisplayLocked property.  If you need more help let me know.

Tim
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unlock a selected viewport.
« Reply #2 on: December 22, 2005, 03:37:05 PM »
I would use ActiveX for this.  Filter your selection set selection for just viewports.  Convert them to objects (instead of entities), and check the DisplayLocked property.  If you need more help let me know.

Tim

Thanks....but I don't have problem to lock....this is work greate..
the proble is the color.....that routine change only the simple square VIEWPORT...
any idea why ?
Keep smile...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: unlock a selected viewport.
« Reply #3 on: December 22, 2005, 03:45:26 PM »
When the viewport was created from other objects (polyline, circle or ellipse) it is associated to those other objects with reactors.  You may be changing the color of the viewport, but from my experiences, the other object is always shown on top.  If you use code like this to select the viewport, then it will give all the information for all objects under the selection box.
Code: [Select]
(setq ss (ssget "+.:E:s" '((0 . "VIEWPORT,*POLYLINE,CIRCLE,ELLIPSE"))))
Then you can test to make sure the the other objects beside the viewport has a viewport associated with it, and change that color also.

Here is the code for a polyline that was converted into a viewport.
Quote from: Acad command prompt
(-1 . <Entity name: 7ef6fda0>)
(0 . "LWPOLYLINE")
(5 . "34")
(102 . "{ACAD_REACTORS")
(330 . <Entity name: 7ef6fdb0>)
(102 . "}")
(330 . <Entity name: 7ef6fce8>)
(100 . "AcDbEntity")
(67 . 1)
(410 . "Layout1")
(8 . "0")
(100 . "AcDbPolyline")
(90 . 4)
(70 . 1)
(43 . 0.0)
(38 . 0.0)
(39 . 0.0)
(10 8.91346 8.29392)
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(10 3.04838 8.68737)
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(10 2.48881 2.22642)
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(10 9.32796 2.16429)
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(210 0.0 0.0 1.0)
Notice that code 102 has a reactor.  That is the viewport itself, code 330.  This way you know that you selected the polyline that is associated witha a viewport.  Now you would change the color of that object also.

Hope that helps.
Tim
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
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.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: unlock a selected viewport.
« Reply #5 on: December 22, 2005, 05:05:21 PM »
Take a look at this code. CAB changed it so it will change the color of any type of Viewport.

Code: [Select]
;UNLOCK OR LOCK ALL VPORTS

(defun c:vplockall ( / X lck prmpt ent clr clr2)
(vl-load-com)
(initget 0 "Lock Unlock")
(if (not *default*)
  (setq *default* "Lock")
)
(setq X
       (cond
((getkword
    (strcat "\n (L)ock or (U)nlock all viewports?  <<Hit Enter for "
    *default*
    ">>: "
    )
  )
)
(*default*)
       )
)
(setq *default* X)
(cond ((= X "Lock")
       (setq lck :vlax-true
             prmpt "locked..."
             clr 5
             clr2 acBlue)
      )
      ((= X "Unlock")
       (setq lck :vlax-false
             prmpt "unlocked..."
             clr 1
             clr2 acRed)
      )
)

(vlax-for lay
      (vla-get-layouts
(vla-get-activedocument
  (vlax-get-acad-object)
)
      )
  (if (eq :vlax-false (vla-get-modeltype lay))
    (vlax-for ent (vla-get-block lay) ; for each ent in layout
      (if (= (vla-get-objectname ent) "AcDbViewport")
(progn
  (vla-put-displaylocked ent lck)
  (vla-put-color ent clr)
            (if (setq obj (assoc 340  (entget (vlax-vla-object->ename ent))))
              (vla-put-color (vlax-ename->vla-object (cdr obj)) clr2))
)
      )
    )
  )
)
(princ (strcat "\n All viewports have been " prmpt))
(princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: unlock a selected viewport.
« Reply #6 on: December 23, 2005, 04:04:42 AM »
Hi Andrea

This prog should do what you want.
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18