Locking objects

Locking objects

Anonymous
Not applicable
29,374 Views
9 Replies
Message 1 of 10

Locking objects

Anonymous
Not applicable

Is there a way to lock an object in AutoCAD 2016?  Just an object or objects, not whole layers.

 

0 Likes
Accepted solutions (2)
29,375 Views
9 Replies
Replies (9)
Message 2 of 10

Guillaume.Desmedt
Collaborator
Collaborator
Accepted solution

No you can't...

 

You can just move your objects in a layer that you 'll lock after, but that's not what you want...

 

Rgds

Guillaume DESMEDT | BIM Infra Guy
0 Likes
Message 3 of 10

Anonymous
Not applicable
that would be a super nice feature.
Message 4 of 10

Guillaume.Desmedt
Collaborator
Collaborator

If any Autocad developper can hear you...Smiley Wink

Guillaume DESMEDT | BIM Infra Guy
0 Likes
Message 5 of 10

cadwomen
Collaborator
Collaborator
Accepted solution

sorry fok´s but you are the one they are all day thinking about .. a wheel woud be a nice Thing ... bt what can i do with ?

 

  1. ;;---------------------=={ Object Lock }==--------------------;;
  2. ;;                                                            ;;
  3. ;;  Purely academic code demonstrating the ability to use     ;;
  4. ;;  reactors to prevent modification of a selection of        ;;
  5. ;;  objects, and furthermore retain such security between     ;;
  6. ;;  drawing sessions.                                         ;;
  7. ;;                                                            ;;
  8. ;;  The code is written for demonstration only since it quite ;;
  9. ;;  clearly isn't practical. The functionality can be         ;;
  10. ;;  matched by simply using a Locked Layer; and moreover      ;;
  11. ;;  don't get your hopes up in thinking that you can use this ;;
  12. ;;  code to prevent third party modification of your drawings ;;
  13. ;;  since the reactors need to be loaded before the lock is   ;;
  14. ;;  effective. And who's going to fall for that one... 😉     ;;
  15. ;;                                                            ;;
  16. ;;  The program uses two reactors: an Editor Reactor - to     ;;
  17. ;;  undo any modification of a selection of objects following ;;
  18. ;;  the completion of a command or LISP program; and a        ;;
  19. ;;  Drawing Reactor - to save the handles of the locked       ;;
  20. ;;  Objects in a dictionary so that the reactors may be       ;;
  21. ;;  rebuilt when the drawing is next opened.                  ;;
  22. ;;                                                            ;;
  23. ;;  The concept of 'undeleting' entities following a command  ;;
  24. ;;  was first proposed (to my knowledge) by Luis Esquivel in  ;;
  25. ;;  the following thread at TheSwamp:                         ;;
  26. ;;                                                            ;;
  27. ;;  http://www.theswamp.org/index.php?topic=6455.0            ;;
  28. ;;                                                            ;;
  29. ;;  I have expanded on this idea to undo, not only a deletion ;;
  30. ;;  but all changes made to an object by storing the DXF data ;;
  31. ;;  of the entity upon locking, and continuously reverting    ;;
  32. ;;  back to this data following modification.                 ;;
  33. ;;                                                            ;;
  34. ;;  I would also like to thank Gilles Chanteau, since with    ;;
  35. ;;  aid of his 'True Rectangle' program, I learnt a great     ;;
  36. ;;  deal with regard to saving data in Drawing Dictionaries.  ;;
  37. ;;  Merci!                                                    ;;
  38. ;;------------------------------------------------------------;;
  39. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  40. ;;------------------------------------------------------------;;
  41. ;;  Version 1.0    -    08-05-2011                            ;;
  42. ;;------------------------------------------------------------;;
  43.  
  44. ;;------------------------------------------------------------;;
  45. ;;  Lock Objects  -  Locks Selected Unlocked Objects          ;;
  46. ;;------------------------------------------------------------;;
  47.  
  48. (defun c:LockObjects ( / ss i j h e )  
  49.   (if (setq ss (ssget))
  50.     (progn
  51.       (repeat (setq j 0 i (sslength ss))
  52.         (if
  53.           (not
  54.             (member
  55.               (setq h
  56.                 (cdr
  57.                   (assoc 5
  58.                     (setq e
  59.                       (entget
  60.                         (ssname ss (setq i (1- i)))
  61.                       )
  62.                     )
  63.                   )
  64.                 )
  65.               )
  66.               *handle*
  67.             )
  68.           )
  69.           (setq *handle* (cons h *handle*) *elist* (cons e *elist*) j (1+ j))
  70.         )
  71.       )
  72.       (if
  73.         (not
  74.           (vl-some
  75.             (function
  76.               (lambda ( r )
  77.                 (eq "ObjectLock" (vlr-data r))
  78.               )
  79.             )
  80.             (cdar (vlr-reactors :vlr-editor-reactor))
  81.           )
  82.         )
  83.         (vlr-editor-reactor "ObjectLock"
  84.           (list
  85.             (cons :vlr-commandended 'ObjectLockCallBack)
  86.             (cons :vlr-lispended    'ObjectLockCallBack)
  87.           )
  88.         )
  89.       )
  90.       (if
  91.         (not
  92.           (vl-some
  93.             (function
  94.               (lambda ( r )
  95.                 (eq "ObjectLock" (vlr-data r))
  96.               )
  97.             )
  98.             (cdar (vlr-reactors :vlr-dwg-reactor))
  99.           )
  100.         )
  101.         (vlr-dwg-reactor "ObjectLock"
  102.           (list
  103.             (cons :vlr-beginsave 'ObjectLockSave)
  104.           )
  105.         )
  106.       )          
  107.       (princ
  108.         (strcat "\n"
  109.           (itoa j) " Object(s) Locked, Total: " (itoa (length *handle*)) " Locked."
  110.         )
  111.       )
  112.     )
  113.   )
  114.   (princ)
  115. )
  116.  
  117. ;;------------------------------------------------------------;;
  118. ;;  Unlock Objects  -  Unlocks Selected Locked Objects        ;;
  119. ;;------------------------------------------------------------;;
  120.  
  121. (defun c:UnLockObjects ( / ss i j r )
  122.   (if *handle*
  123.     (if (setq ss (ssget))
  124.       (progn
  125.         (repeat (setq j 0 i (sslength ss))
  126.           (if
  127.             (member
  128.               (setq h
  129.                 (cdr
  130.                   (assoc 5
  131.                     (setq e
  132.                       (entget
  133.                         (ssname ss (setq i (1- i)))
  134.                       )
  135.                     )
  136.                   )
  137.                 )
  138.               )
  139.               *handle*
  140.             )
  141.             (setq *handle* (vl-remove h *handle*) *elist* (vl-remove e *elist*) j (1+ j))
  142.           )
  143.         )
  144.         (princ
  145.           (strcat "\n"
  146.             (itoa j) " Object(s) Unlocked, Total: " (itoa (length *handle*)) " Locked."
  147.           )
  148.         )
  149.       )
  150.     )
  151.     (princ "\n--> No Objects Locked.")
  152.   )
  153.   (if (null *handle*)
  154.     (mapcar
  155.       (function
  156.         (lambda ( r )
  157.           (if (eq "ObjectLock" (vlr-data r)) (vlr-remove r))
  158.         )
  159.       )
  160.       (apply 'append (mapcar 'cdr (vlr-reactors)))
  161.     )
  162.   )
  163.   (princ)
  164. )
  165.  
  166. ;;------------------------------------------------------------;;
  167. ;;  Disable Lock  -  Unlocks Everything                       ;;
  168. ;;------------------------------------------------------------;;
  169.  
  170. (defun c:DisableLock ( / acdic dic )
  171.   (mapcar
  172.     (function
  173.       (lambda ( r )
  174.         (if (eq "ObjectLock" (vlr-data r)) (vlr-remove r))
  175.       )
  176.     )
  177.     (apply 'append (mapcar 'cdr (vlr-reactors)))
  178.   )
  179.   (setq acdic
  180.     (vla-get-dictionaries
  181.       (vla-get-activedocument (vlax-get-acad-object))
  182.     )
  183.   )
  184.   (if (setq dic (ObjectLockGetItem acdic "ObjectLock"))
  185.     (vla-delete dic)
  186.   )
  187.   (setq *handle* nil *elist* nil)
  188.   (princ)
  189. )
  190.  
  191. ;;------------------------------------------------------------;;
  192.  
  193. (defun ObjectLockCallBack ( a b )
  194.   (mapcar
  195.     (function
  196.       (lambda ( h )
  197.         (or (entget (handent h)) (entdel (handent h)))
  198.       )
  199.     )
  200.     *handle*
  201.   )
  202.   (mapcar 'entmod *elist*)
  203.   (princ)
  204. )
  205.  
  206. ;;------------------------------------------------------------;;
  207.  
  208. (defun ObjectLockGetItem ( collection item )
  209.   (if
  210.     (not
  211.       (vl-catch-all-error-p
  212.         (setq item
  213.           (vl-catch-all-apply 'vla-item (list collection item))
  214.         )
  215.       )
  216.     )
  217.     item
  218.   )
  219. )
  220.  
  221. ;;------------------------------------------------------------;;
  222. ;;                           Saving                           ;;
  223. ;;------------------------------------------------------------;;
  224.  
  225. (defun ObjectLockSave ( a b / acdic dic xrec l )
  226.   (if *handle*
  227.     (progn
  228.       (setq acdic
  229.         (vla-get-dictionaries
  230.           (vla-get-activedocument (vlax-get-acad-object))
  231.         )
  232.       )
  233.       (if (not (setq dic (ObjectLockGetItem acdic "ObjectLock")))
  234.         (setq dic (vla-add acdic "ObjectLock"))
  235.       )
  236.       (if (not (setq xrec (ObjectLockGetItem dic "Handles")))
  237.         (setq xrec (vla-addxrecord dic "Handles"))
  238.       )
  239.       (vla-setxrecorddata xrec
  240.         (vlax-safearray-fill
  241.           (vlax-make-safearray vlax-vbinteger (cons 0 (1- (length *handle*))))
  242.           (repeat (length *handle*) (setq l (cons 1 l)))
  243.         )
  244.         (vlax-safearray-fill
  245.           (vlax-make-safearray vlax-vbvariant (cons 0 (1- (length *handle*))))
  246.           (mapcar '(lambda ( h ) (vlax-make-variant h vlax-vbstring)) *handle*)
  247.         )
  248.       )
  249.     )
  250.   )
  251.   (princ)
  252. )
  253.  
  254. ;;------------------------------------------------------------;;
  255. ;;                          Loading                           ;;
  256. ;;------------------------------------------------------------;;
  257.  
  258. (
  259.   (lambda ( / dic xrec typ val ) (vl-load-com)
  260.     (mapcar
  261.       (function
  262.         (lambda ( r )
  263.           (if (eq "ObjectLock" (vlr-data r)) (vlr-remove r))
  264.         )
  265.       )
  266.       (apply 'append (mapcar 'cdr (vlr-reactors)))
  267.     )
  268.     (if
  269.       (and
  270.         (setq dic
  271.           (ObjectLockGetItem
  272.             (vla-get-dictionaries
  273.               (vla-get-activedocument (vlax-get-acad-object))
  274.             )
  275.             "ObjectLock"
  276.           )
  277.         )
  278.         (setq xrec (ObjectLockGetItem dic "Handles"))
  279.         (progn (vla-getxrecorddata xrec 'typ 'val) val)
  280.       )
  281.       (if
  282.         (and
  283.           (setq *handle*
  284.             (vl-remove-if-not
  285.               (function
  286.                 (lambda ( h ) (entget (handent h)))
  287.               )
  288.               (mapcar 'vlax-variant-value (vlax-safearray->list val))
  289.             )
  290.           )
  291.           (setq *elist* (mapcar '(lambda ( h ) (entget (handent h))) *handle*))
  292.         )
  293.         (progn
  294.           (vlr-editor-reactor "ObjectLock"
  295.             (list
  296.               (cons :vlr-commandended 'ObjectLockCallBack)
  297.               (cons :vlr-lispended    'ObjectLockCallBack)
  298.             )
  299.           )
  300.           (vlr-dwg-reactor "ObjectLock"
  301.             (list
  302.               (cons :vlr-beginsave 'ObjectLockSave)
  303.             )
  304.           )
  305.         )
  306.       )
  307.     )
  308.   )
  309. )
  310.  
  311. (princ)
  312.  
  313. ;;------------------------------------------------------------;;
  314. ;;                         End of File                        ;;
  315. ;;------------------------------------------------------------;;

 

 

http://www.lee-mac.com/objectlock.html

 

 

 

 

cu cw

If my post answers your question, please mark it as an Accepted Solution, so that others can find answers quickly!
Message 6 of 10

Guillaume.Desmedt
Collaborator
Collaborator

Great, I should check on this website before saying No...

 

But how do you unlock after...Smiley Frustrated (sorry too fast, it's on website...)

Guillaume DESMEDT | BIM Infra Guy
0 Likes
Message 7 of 10

cadwomen
Collaborator
Collaborator

check the Line 121 😉

 

cw

If my post answers your question, please mark it as an Accepted Solution, so that others can find answers quickly!
0 Likes
Message 8 of 10

Anonymous
Not applicable
Fantastic! Works beautifully!
Thank you so much!
0 Likes
Message 9 of 10

Guillaume.Desmedt
Collaborator
Collaborator

It's just missing a annotation of this parameter on objects in case of share CAD file to other users...

Guillaume DESMEDT | BIM Infra Guy
0 Likes
Message 10 of 10

cadwomen
Collaborator
Collaborator

so contact

 

Lee Mac, may he help you with this question

 

cu cw

If my post answers your question, please mark it as an Accepted Solution, so that others can find answers quickly!
0 Likes