Author Topic: (challenge) A Little Math Question  (Read 2375 times)

0 Members and 1 Guest are viewing this topic.

tcdan

  • Guest
(challenge) A Little Math Question
« on: August 01, 2005, 02:00:07 AM »
Newbies will be able to do this as well as advanced LISPers.

Write a line of code (or more) that will set the NEArest object snap without modifying any of the other object snap settings.

It's a fun little math excercise :)

Crank

  • Water Moccasin
  • Posts: 1503
(challenge) A Little Math Question
« Reply #1 on: August 01, 2005, 02:40:12 AM »
(SETVAR "OSMODE" (BOOLE 6 (GETVAR "OSMODE") 512)); on/off

(SETVAR "OSMODE" (- (GETVAR "OSMODE") -512 (LOGAND (GETVAR "OSMODE") 512))); on

or:

(SETVAR "OSMODE" (+ (LOGAND (GETVAR "OSMODE") 31231) 512)); on
Vault Professional 2023     +     AEC Collection

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(challenge) A Little Math Question
« Reply #2 on: August 01, 2005, 07:27:52 AM »
Quote from: tcdan
... Write a line of code that will set the NEArest object snap without modifying any of the other object snap settings ...

Code: [Select]
(setvar "osmode"
    (logior 512
        (getvar "osmode")
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

tcdan

  • Guest
(challenge) A Little Math Question
« Reply #3 on: August 01, 2005, 11:11:36 AM »
Wow that's great!  I knew you guys could come up with a faster way than this:
Code: [Select]
    (setq snaps (getvar "osmode"))
  (if ( = (rem (/ snaps 512) 2) 0) (setvar "osmode" (+ 512 snaps)))  ;; set 'nearest' snap

daron

  • Guest
(challenge) A Little Math Question
« Reply #4 on: August 01, 2005, 12:19:18 PM »
Crank's first one's my personal favorite. It sets and unsets it. Boole is Coole.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(challenge) A Little Math Question
« Reply #5 on: August 01, 2005, 01:27:39 PM »
Here is a neat little trick that doesn't require setting osnaps ... you can override it in lisp to the one you require.
Code: [Select]

(setq pt (osnap (getpoint "\nSelect point") "_nearest"))
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Crank

  • Water Moccasin
  • Posts: 1503
(challenge) A Little Math Question
« Reply #6 on: August 04, 2005, 08:29:27 AM »
Quote from: Keith
Here is a neat little trick that doesn't require setting osnaps ... you can override it in lisp to the one you require.
Code: [Select]

(setq pt (osnap (getpoint "\nSelect point") "_nearest"))

That's probably the best solution. You don't have to restore the osnap when you finish the function.

But if you do want to change the OSMODE then it's just an OR-operation, so this should also work:
Code: [Select]
(SETVAR "OSMODE" (BOOLE 7 (GETVAR "OSMODE") 512)); on
Vault Professional 2023     +     AEC Collection

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
(challenge) A Little Math Question
« Reply #7 on: August 04, 2005, 08:39:52 AM »
(osnap pnt "_nea") fails on some objects. Therefore I use this solution:
Code: [Select]
(defun MeEntSel ( / CurEnt CurObj NeaPnt)
 (if (setq CurEnt (entsel "\nSelect object: "))
  (progn
   (setq CurObj (vlax-ename->vla-object (car CurEnt))
         NeaPnt (if (vl-position
                     (vla-get-ObjectName CurObj)
                    '("AcDbArc" "AcDbCircle" "AcDb2dPolyline")
                    )
                 (vlax-curve-getClosestPointToProjection
                  CurObj
                  (trans (cadr CurEnt) 1 0)
                  (trans (getvar "VIEWDIR") 1 0 1)
                 )
                 (osnap (cadr CurEnt) "_NEA")
                )
   )
   (list (car CurEnt) (trans NeaPnt 0 1))
  )
 )
)
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18