how to restore snap setting

how to restore snap setting

Anonymous
Not applicable
1,991 Views
13 Replies
Message 1 of 14

how to restore snap setting

Anonymous
Not applicable

Hello guys,

The lisp below erases my snap settings,

After I set my snap settings to be all selected:

like this

I run this lisp and it deselect all the object snap.

Can you update this code so it will keep the settings that I made?

the code:

(defun c:LD  (/ f curlayer curosmode ent exit a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z)
  (while (setq vlaObj1   (vlax-ename->vla-object (setq ent (car (entsel))))
               vlaObj2   (vlax-ename->vla-object (car (entsel)))
               curlayer  (getvar 'clayer)
               curosmode (getvar 'osmode)
               spaces1   (getreal "\nEnter number of spaces: "))
    (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")
          (T
           (setvar 'clayer (cdr (assoc 8 (entget ent))))
           (setvar 'osmode 16384)
           (setq spaces  (test spaces1 ())
                 testlst (vl-sort
                           (apply
                             'append
                             (mapcar
                               '(lambda (y)
                                  (mapcar '(lambda (x) (append (append (list (distance x y)) (list x)) (list y)))
                                          (list (vlax-curve-getStartPoint vlaObj1)
                                                (vlax-curve-getEndPoint vlaObj1))))
                               (list (vlax-curve-getStartPoint vlaObj2)
                                     (vlax-curve-getEndPoint vlaObj2))))
                           '(lambda (x y) (< (car x) (car y))))
                 a       (cdar testlst)
                 b       (cdr (apply 'append
                                     (car (mapcar '(lambda (y)
                                                     (mapcar '(lambda (x)
                                                                (if (not (or (equal (cadar testlst) (cadr x) y)
                                                                             (equal (caddar testlst) (caddr x) y)
                                                                             (equal (cadar testlst) (caddr x) y)
                                                                             (equal (caddar testlst) (cadr x) y)))
                                                                  x))
                                                             testlst))
                                                  (list 1e-15))))))
           (command "._undo" "_begin")
           (test2 a b spaces1 spaces)
           (command "._undo" "_end")
           (initget "Yes No")
           (setq f (cond ((getkword "\nFLip lines [Yes/No] <No>: "))
                         ("No")))
           (cond ((wcmatch f "Yes,Y")
                  (command "._undo" 1)
                  (setq z (last a))
                  (setq a (cons (car a) (cdr b)))
                  (setq b (cons (car b) (list z)))
                  (test2 a b spaces1 spaces))
                 (T ())))))
  (setvar 'clayer curlayer)
  (setvar 'osmode curosmode))

(defun test  (x y)
  (cond ((< x 1) y)
        (T (test (fix (- x 1)) (cons (fix x) y)))))

(defun test2  (a b c d)
  (mapcar '(lambda (x y) (command-s "._pline" x y ""))
          (mapcar '(lambda (x) (polar (car a) (angle (car a) (cadr a)) (* (/ (distance (car a) (cadr a)) c) x)))
                  (if (not (zerop (rem c (fix c))))
                    d
                    (cdr (reverse d))))
          (mapcar '(lambda (x) (polar (car b) (angle (car b) (cadr b)) (* (/ (distance (car b) (cadr b)) c) x)))
                  (if (not (zerop (rem c (fix c))))
                    d
                    (cdr (reverse d))))))

Thank you,

Eyal

0 Likes
Accepted solutions (1)
1,992 Views
13 Replies
Replies (13)
Message 2 of 14

dbhunia
Advisor
Advisor

Hi

 

Try this

 

(defun c:LD  (/ f curlayer curosmode ent exit a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z)
(setq osm (getvar 'osmode))
  (while (setq vlaObj1   (vlax-ename->vla-object (setq ent (car (entsel))))
               vlaObj2   (vlax-ename->vla-object (car (entsel)))
               curlayer  (getvar 'clayer)
               curosmode (getvar 'osmode)
               spaces1   (getreal "\nEnter number of spaces: "))
    (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")
          (T
           (setvar 'clayer (cdr (assoc 8 (entget ent))))
           (setvar 'osmode 16384)
           (setq spaces  (test spaces1 ())
                 testlst (vl-sort
                           (apply
                             'append
                             (mapcar
                               '(lambda (y)
                                  (mapcar '(lambda (x) (append (append (list (distance x y)) (list x)) (list y)))
                                          (list (vlax-curve-getStartPoint vlaObj1)
                                                (vlax-curve-getEndPoint vlaObj1))))
                               (list (vlax-curve-getStartPoint vlaObj2)
                                     (vlax-curve-getEndPoint vlaObj2))))
                           '(lambda (x y) (< (car x) (car y))))
                 a       (cdar testlst)
                 b       (cdr (apply 'append
                                     (car (mapcar '(lambda (y)
                                                     (mapcar '(lambda (x)
                                                                (if (not (or (equal (cadar testlst) (cadr x) y)
                                                                             (equal (caddar testlst) (caddr x) y)
                                                                             (equal (cadar testlst) (caddr x) y)
                                                                             (equal (caddar testlst) (cadr x) y)))
                                                                  x))
                                                             testlst))
                                                  (list 1e-15))))))
           (command "._undo" "_begin")
           (test2 a b spaces1 spaces)
           (command "._undo" "_end")
           (initget "Yes No")
           (setq f (cond ((getkword "\nFLip lines [Yes/No] <No>: "))
                         ("No")))
           (cond ((wcmatch f "Yes,Y")
                  (command "._undo" 1)
                  (setq z (last a))
                  (setq a (cons (car a) (cdr b)))
                  (setq b (cons (car b) (list z)))
                  (test2 a b spaces1 spaces))
                 (T ())))))
  (setvar 'clayer curlayer)
  ;(setvar 'osmode curosmode))
  (setvar 'osmode osm))
(defun test  (x y)
  (cond ((< x 1) y)
        (T (test (fix (- x 1)) (cons (fix x) y)))))

(defun test2  (a b c d)
  (mapcar '(lambda (x y) (command-s "._pline" x y ""))
          (mapcar '(lambda (x) (polar (car a) (angle (car a) (cadr a)) (* (/ (distance (car a) (cadr a)) c) x)))
                  (if (not (zerop (rem c (fix c))))
                    d
                    (cdr (reverse d))))
          (mapcar '(lambda (x) (polar (car b) (angle (car b) (cadr b)) (* (/ (distance (car b) (cadr b)) c) x)))
                  (if (not (zerop (rem c (fix c))))
                    d
                    (cdr (reverse d))))))

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 14

Anonymous
Not applicable

Hi @dbhunia ,

 

I run your lisp and it didn't work, I still get This,

Do you have another idea how to select all like This,

Usually I work with object snap all selected.

 

Thank you,

Eyal

 

0 Likes
Message 4 of 14

dbhunia
Advisor
Advisor

Can you send me a sample drawing in AutoCAD 2007 format...... to test

 

Another thing state briefly what lisp do......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 14

dlanorh
Advisor
Advisor

@Anonymous wrote:

Hello guys,

The lisp below erases my snap settings,

After I set my snap settings to be all selected:

like this

I run this lisp and it deselect all the object snap.

Can you update this code so it will keep the settings that I made?

the code:

(defun c:LD  (/ f curlayer curosmode ent exit a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z)
  (while (setq vlaObj1   (vlax-ename->vla-object (setq ent (car (entsel))))
               vlaObj2   (vlax-ename->vla-object (car (entsel)))
               curlayer  (getvar 'clayer)
               ;curosmode (getvar 'osmode)
               spaces1   (getreal "\nEnter number of spaces: "))
    (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")
          (T
           (setvar 'clayer (cdr (assoc 8 (entget ent))))
           (setvar 'osmode 16384)
           (setq spaces  (test spaces1 ())
                 testlst (vl-sort
                           (apply
                             'append
                             (mapcar
                               '(lambda (y)
                                  (mapcar '(lambda (x) (append (append (list (distance x y)) (list x)) (list y)))
                                          (list (vlax-curve-getStartPoint vlaObj1)
                                                (vlax-curve-getEndPoint vlaObj1))))
                               (list (vlax-curve-getStartPoint vlaObj2)
                                     (vlax-curve-getEndPoint vlaObj2))))
                           '(lambda (x y) (< (car x) (car y))))
                 a       (cdar testlst)
                 b       (cdr (apply 'append
                                     (car (mapcar '(lambda (y)
                                                     (mapcar '(lambda (x)
                                                                (if (not (or (equal (cadar testlst) (cadr x) y)
                                                                             (equal (caddar testlst) (caddr x) y)
                                                                             (equal (cadar testlst) (caddr x) y)
                                                                             (equal (caddar testlst) (cadr x) y)))
                                                                  x))
                                                             testlst))
                                                  (list 1e-15))))))
           (command "._undo" "_begin")
           (test2 a b spaces1 spaces)
           (command "._undo" "_end")
           (initget "Yes No")
           (setq f (cond ((getkword "\nFLip lines [Yes/No] <No>: "))
                         ("No")))
           (cond ((wcmatch f "Yes,Y")
                  (command "._undo" 1)
                  (setq z (last a))
                  (setq a (cons (car a) (cdr b)))
                  (setq b (cons (car b) (list z)))
                  (test2 a b spaces1 spaces))
                 (T ())))))
  (setvar 'clayer curlayer)
  ;(setvar 'osmode curosmode)
)
(defun test (x y) (cond ((< x 1) y) (T (test (fix (- x 1)) (cons (fix x) y))))) (defun test2 (a b c d) (mapcar '(lambda (x y) (command-s "._pline" x y "")) (mapcar '(lambda (x) (polar (car a) (angle (car a) (cadr a)) (* (/ (distance (car a) (cadr a)) c) x))) (if (not (zerop (rem c (fix c)))) d (cdr (reverse d)))) (mapcar '(lambda (x) (polar (car b) (angle (car b) (cadr b)) (* (/ (distance (car b) (cadr b)) c) x))) (if (not (zerop (rem c (fix c)))) d (cdr (reverse d))))))

Thank you,

Eyal


You are saving the entry state, changing to all on, then restoring the entry state. So comment out the two red lines as indicated should preserve the "all on state"

I am not one of the robots you're looking for

0 Likes
Message 6 of 14

Anonymous
Not applicable

hello @dbhunia,

I have no drawing to send because it happens even with new drawing:

these are my steps:

1. I draw 2 lines.

2. I make sure that the object snap settings are like: this.

3. I run the lisp. ( entering LD in the command prompt)

4. I check again the object snap settings and it is like:this.

I hope I'm clear enough.

Eyal.

 

 

 

0 Likes
Message 7 of 14

dlanorh
Advisor
Advisor

Try this

 

(defun c:LD  (/ f curlayer curosmode ent exit a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z)
  (setvar curosmode (getvar 'osmode))
  (setvar curlayer  (getvar 'clayer))
  
  (while (setq vlaObj1   (vlax-ename->vla-object (setq ent (car (entsel))))
               vlaObj2   (vlax-ename->vla-object (car (entsel)))              
               spaces1   (getreal "\nEnter number of spaces: "))
    (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")
          (T
           (setvar 'clayer (cdr (assoc 8 (entget ent))))
           (setvar 'osmode 16384)
           (setq spaces  (test spaces1 ())
                 testlst (vl-sort
                           (apply
                             'append
                             (mapcar
                               '(lambda (y)
                                  (mapcar '(lambda (x) (append (append (list (distance x y)) (list x)) (list y)))
                                          (list (vlax-curve-getStartPoint vlaObj1)
                                                (vlax-curve-getEndPoint vlaObj1))))
                               (list (vlax-curve-getStartPoint vlaObj2)
                                     (vlax-curve-getEndPoint vlaObj2))))
                           '(lambda (x y) (< (car x) (car y))))
                 a       (cdar testlst)
                 b       (cdr (apply 'append
                                     (car (mapcar '(lambda (y)
                                                     (mapcar '(lambda (x)
                                                                (if (not (or (equal (cadar testlst) (cadr x) y)
                                                                             (equal (caddar testlst) (caddr x) y)
                                                                             (equal (cadar testlst) (caddr x) y)
                                                                             (equal (caddar testlst) (cadr x) y)))
                                                                  x))
                                                             testlst))
                                                  (list 1e-15))))))
           (command "._undo" "_begin")
           (test2 a b spaces1 spaces)
           (command "._undo" "_end")
           (initget "Yes No")
           (setq f (cond ((getkword "\nFLip lines [Yes/No] <No>: "))
                         ("No")))
           (cond ((wcmatch f "Yes,Y")
                  (command "._undo" 1)
                  (setq z (last a))
                  (setq a (cons (car a) (cdr b)))
                  (setq b (cons (car b) (list z)))
                  (test2 a b spaces1 spaces))
                 (T ())))))
  (setvar 'clayer curlayer)
  (setvar 'osmode curosmode)
)

(defun test  (x y)
  (cond ((< x 1) y)
        (T (test (fix (- x 1)) (cons (fix x) y)))))

(defun test2  (a b c d)
  (mapcar '(lambda (x y) (command-s "._pline" x y ""))
          (mapcar '(lambda (x) (polar (car a) (angle (car a) (cadr a)) (* (/ (distance (car a) (cadr a)) c) x)))
                  (if (not (zerop (rem c (fix c))))
                    d
                    (cdr (reverse d))))
          (mapcar '(lambda (x) (polar (car b) (angle (car b) (cadr b)) (* (/ (distance (car b) (cadr b)) c) x)))
                  (if (not (zerop (rem c (fix c))))
                    d
                    (cdr (reverse d))))))

You were continually saving 'clayer and 'osmode within a while loop which may have been the problem. Re your post for this to work everything must be "ON" before running the lisp.

I am not one of the robots you're looking for

0 Likes
Message 8 of 14

phanaem
Collaborator
Collaborator

You have to get the settings outside the loop, as dbhunia suggested. Also, your while condition will generate an error if nothing is selected, so the lisp will exit without restoring the initial settings.

Replace this

(defun c:LD  (/ f curlayer curosmode ent exit a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z)
  (while (setq vlaObj1   (vlax-ename->vla-object (setq ent (car (entsel))))
               vlaObj2   (vlax-ename->vla-object (car (entsel)))
               curlayer  (getvar 'clayer)
               curosmode (getvar 'osmode)
               spaces1   (getreal "\nEnter number of spaces: "))
    (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")

with this

(defun c:LD  (/ f curlayer curosmode ent ent2 a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z)
  (setq
    curlayer  (getvar 'clayer)
    curosmode (getvar 'osmode)
  )
  
  (while (and
           (setq ent (car (entsel)))
           (setq ent2 (car (entsel)))
           (setq spaces1 (getreal "\nEnter number of spaces: "))
         )
    (setq vlaObj1  (vlax-ename->vla-object ent)
          vlaObj2  (vlax-ename->vla-object ent2)
    )
               
    (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")
Message 9 of 14

cadffm
Consultant
Consultant

To set osmode to 16384 is stupid like set to 0.

If osmode is lower then 16384 (=on) you have ADD 16384 to the current osmode.

and later, if osmode was lower then 16384 before, you should remove 16384.

 

Thats how osnap disableing works, on/off, osmode/osmode+16384.

 

---

 

But this (command) statement doesn't  interactive with users, so the best way is to ignore osnaps totally.

Remove all setvar-getvar-osmode and handle the object-snap in your command by using explicit the _NON option.

 

Or simply makr sure your osnapcoord is set to 1.

 

Both ways don't touch osmode, so haven't never  trouble with it.

 

---

And at last.

@Anonymous

All object snaps on, really?

I would have trouble with running osnap

Geometric CEnter always on,

and running osnap would me slowing down if need to draw accurately.

Interesting setting.

Sebastian

Message 10 of 14

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

Try with this.....

 

(defun c:LD  (/ f curlayer curosmode ent exit a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z)
  (while (setq vlaObj1   (vlax-ename->vla-object (setq ent (car (entsel))))
               vlaObj2   (vlax-ename->vla-object (car (entsel)))
               curlayer  (getvar 'clayer)
               curosmode (getvar 'osmode)
               spaces1   (getreal "\nEnter number of spaces: "))
    (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")
          (T
           (setvar 'clayer (cdr (assoc 8 (entget ent))))
           (setvar 'osmode 16384)
           (setq spaces  (test spaces1 ())
                 testlst (vl-sort
                           (apply
                             'append
                             (mapcar
                               '(lambda (y)
                                  (mapcar '(lambda (x) (append (append (list (distance x y)) (list x)) (list y)))
                                          (list (vlax-curve-getStartPoint vlaObj1)
                                                (vlax-curve-getEndPoint vlaObj1))))
                               (list (vlax-curve-getStartPoint vlaObj2)
                                     (vlax-curve-getEndPoint vlaObj2))))
                           '(lambda (x y) (< (car x) (car y))))
                 a       (cdar testlst)
                 b       (cdr (apply 'append
                                     (car (mapcar '(lambda (y)
                                                     (mapcar '(lambda (x)
                                                                (if (not (or (equal (cadar testlst) (cadr x) y)
                                                                             (equal (caddar testlst) (caddr x) y)
                                                                             (equal (cadar testlst) (caddr x) y)
                                                                             (equal (caddar testlst) (cadr x) y)))
                                                                  x))
                                                             testlst))
                                                  (list 1e-15))))))
           (command "._undo" "_begin")
           (test2 a b spaces1 spaces)
           (command "._undo" "_end")
           (initget "Yes No")
           (setq f (cond ((getkword "\nFLip lines [Yes/No] <No>: "))
                         ("No")))
           (cond ((wcmatch f "Yes,Y")
                  (command "._undo" 1)
                  (setq z (last a))
                  (setq a (cons (car a) (cdr b)))
                  (setq b (cons (car b) (list z)))
                  (test2 a b spaces1 spaces))
                 (T ()))))
  )
;(setvar 'clayer curlayer)
;(setvar 'osmode curosmode)
)
(defun test  (x y)
  (cond ((< x 1) y)
        (T (test (fix (- x 1)) (cons (fix x) y)))
  )
)
(defun test2  (a b c d)
  (mapcar '(lambda (x y) (command-s "._pline" x y ""))
          (mapcar '(lambda (x) (polar (car a) (angle (car a) (cadr a)) (* (/ (distance (car a) (cadr a)) c) x)))
                  (if (not (zerop (rem c (fix c))))
                    d
                    (cdr (reverse d))))
          (mapcar '(lambda (x) (polar (car b) (angle (car b) (cadr b)) (* (/ (distance (car b) (cadr b)) c) x)))
                  (if (not (zerop (rem c (fix c))))
                    d
                    (cdr (reverse d))))
  )
(setvar 'clayer curlayer)
(setvar 'osmode curosmode)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 11 of 14

Anonymous
Not applicable

Great!!! @dbhunia thank you , it works great.

Thank you all for your help!!

 

0 Likes
Message 12 of 14

ВeekeeCZ
Consultant
Consultant

Hmm, this thread is a sad story to read. Good suggestions are ignored, poor solution is accepted. 😞

And @dlanorh had a bad moment.

0 Likes
Message 13 of 14

dlanorh
Advisor
Advisor

I'm sure I typed (setq...), but then I'm old. These "senior" moments will increase in frequency until they merge all together. Robot Sad Robot tongue

I am not one of the robots you're looking for

0 Likes
Message 14 of 14

Anonymous
Not applicable

Hi @ВeekeeCZ , I'm sorry you feel this.

maybe @dlanorh has good ideas too , but the suggestion @dbhunia gave me , worked exactly for what I needed.

So please don't be upset about accepting other ideas. YOU ARE ALL VERY HELPFULL!!

GOOD DAY!

Eyal.

 

0 Likes