Request For and OSNAP Profile Lisp

Request For and OSNAP Profile Lisp

timothy_crouse
Collaborator Collaborator
950 Views
13 Replies
Message 1 of 14

Request For and OSNAP Profile Lisp

timothy_crouse
Collaborator
Collaborator

Hello Coders

 

I came across the script shown below which got me thinking:

 

(command "._OSNAP" "MIDPOINT,NEAREST,ENDPOINT,QUADRANT,INTERSECTION") 

 If anyone has time and willingness to help, could the script code snippet concept be turned into a Lisp?

 

The idea would be to have multiple OSNAP profiles defined then the user would pick which use case to enable.

A dialog with the profiles listed would be helpful so the user could be reminded which number profile does what.

 

Perhaps the LISP could be run with the profile number and if it is run with a question mark the profile list could pop up.

Example:  OSP1  would enable osnap profile 1,

OSP? would list all the profiles defined.

 

Thoughts / Comments

 

Thank You

Best Regards

-Tim C.,

0 Likes
951 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

[It already is an AutoLisp routine, but I know what you mean....]  Another AutoLisp way to do it is by setting the OSMODE System Variable value -- for that particular combination of modes:

(setvar 'osmode 563)

[But I suggest you not include NEArest in your running Osnap modes.  You will never be able to Osnap to a MIDpoint except by tabbing through to get to that while hovering in the vicinity, because otherwise, NEArest will always "win" over MIDpoint except when you happen to have the cursor positioned precisely at the midpoint.]

 

How many combinations would you need?  If it's not too many, and if people could be informed of what mode combination each profile represents, you could do something like this:

 

(defun C:OSP (/ osp)
  (setq OSPlist '(("1osp" 3) ("2osp" 33) ("3osp" 51) ("4osp" 163)))
  (initget "1osp 2osp 3osp 4osp")
  (setq osp (getkword "\nOffset Profile [1osp/2osp/3osp/4osp]: "))
  (setvar 'osmode (cadr (assoc osp OSPlist)))
  (prin1)
)

 

I did them with names starting with a number followed by lower-case letters because the number is then the abbreviation for the keyword.  It gives the User the option to type just the number, or more of the name if they want, or as formatted, pick the option in the prompt.  [If they were called something like OSP1, OSP2, etc., it would be necessary to type in the whole name of the one you want.]

 

It could be enhanced to offer the current setting as default, or a particular option as initial default on first use, and/or report what it set OSMODE to, or....

Kent Cooper, AIA
0 Likes
Message 3 of 14

timothy_crouse
Collaborator
Collaborator

Hello Ken

 

Here is a set of profiles I would find useful

 

-End, Mid, Perpendicular, Center, Quad

 

-End, Center, Quadrant, Mid, Perpendicular

 

-End, Mid, Intersection, App Intersection, Center, Quad, Perpendicular

 

-Nearest

 

-Nearest, End, Perpendicular

 

-Nearest, End, Tangent

 

Thoughts?

 

Is there an easy way to show the profiles with the profile number?  Maybe not all the time, but if someone was to enter OSP > H,  perhaps that could throw a text command window with the profile info. . .Thoughts?

 

Thanks in Advance

-Tim C.

 

 

 

 

 

0 Likes
Message 4 of 14

timothy_crouse
Collaborator
Collaborator

I found some of your old code on the forum and used Chat GPT to create the following, it seems to work (I guess).

 

Where / how do I generate the numeric value to generate the applicable OSNAP settings?

 

SOME OF YOUR OLD CODE MIXED WITH YOUR NEW CODE:

 

(defun C:OSP (/ osp)
(setq OSPlist '(("1osp" 3) ("2osp" 33) ("3osp" 51) ("4osp" 163) ("5osp" 563)))
(initget "1osp 2osp 3osp 4osp 5osp H")
(setq osp (getkword "\nOffset Profile [1osp/2osp/3osp/4osp/5osp/H]: "))

(if (= osp "H")
(progn
(alert
(strcat
"OSNAP PROFILES:"
"\n1 = End, Mid, Perpendicular"
"\n2 = End, Perpendicular"
"\n3 = End, Nearest"
) ; strcat
) ; alert
) ; progn
(progn
(setvar 'osmode (cadr (assoc osp OSPlist)))
(prin1)
) ; progn
) ; if

(princ)
)

0 Likes
Message 5 of 14

timothy_crouse
Collaborator
Collaborator

I found this so I figured I would add it for anyone that wishes to use this code in the future:

 

Endpoint: 1
Midpoint: 2
Center: 4
Node: 8
Quadrant: 16
Intersection: 32
Insertion: 64
Perpendicular: 128
Tangent: 256
Nearest: 512
Apparent Intersection: 1024
Extension: 2048
Parallel: 4096
From: 8192
Midway Between 2 Points: 16384

To combine OSNAP settings, add their corresponding numeric values together.
For example, to enable "Endpoint," "Midpoint," "From," and "Midway Between 2 Points" OSNAPs
you would set the osmode variable to 1 + 2 + 8192 + 16384 = 24579.

 

Best Regards

-Tim C.

0 Likes
Message 6 of 14

paullimapa
Mentor
Mentor

I think the challenge is coming up with a profile name that either makes sense or reminds you of the combination of osnaps set. There’s just so many possible combinations that in the end you may end up with just sticking with one and no more. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 14

timothy_crouse
Collaborator
Collaborator

This is what I came up with.  It displays the profiles list on startup:

 

 

(defun C:OSP (/ osp)

(progn
(alert
(strcat
"OSNAP PROFILES:"
"\n1 = End, Mid, Perp"
"\n2 = End, Mid, Perp, Center, Quad"
"\n3 = End, Near, Perp"
"\n4 = End, Node, Perp"
"\n5 = End, Near, Node, Insert, Perp"
"\n6 = End, Center, Quad"
"\n7 = End, Mid, Center, Quad, Int, App Int, Perp"
"\n8 = End, From"
"\n9 = Near, End"
) ; strcat
) ; alert
) ; progn


(setq OSPlist '(("1osp" 131) ("2osp" 151) ("3osp" 641) ("4osp" 137) ("5osp" 713) ("6osp" 1) ("7osp" 1471) ("8osp" 8193) ("9osp" 513)))
(initget "1osp 2osp 3osp 4osp 5osp 6osp 7osp 8osp 9osp H")
(setq osp (getkword "\nOffset Profile [1osp/2osp/3osp/4osp/5osp/6osp/7osp/8osp/9osp/H]: "))

(progn
(setvar 'osmode (cadr (assoc osp OSPlist)))
(prin1)
) ; progn
) ; if
(princ)

 

 

Seems useful enough, but  the value of 7 and 8 is a bit off, I need to look at the state values a little more

0 Likes
Message 8 of 14

Kent1Cooper
Consultant
Consultant

@timothy_crouse wrote:

....

Seems useful enough, but  the value of 7 and 8 is a bit off, I need to look at the state values a little more


I expect that's because APParent-intersection and FROm Osnap are not just single-pick modes, so they don't make much sense as "running" modes -- some other mode you have involved will take over on picking something.

Kent Cooper, AIA
0 Likes
Message 9 of 14

timothy_crouse
Collaborator
Collaborator

How would I modify the code below so the OSNAP mode selection variable could be provided when the lisp is initiated without display the alert box or asking the for user input?

 

 

 

(defun C:OSP (/ osp)

(progn
(alert
(strcat
"OSNAP PROFILES:"
"\n1 = END, MID, PERP, CENTER, GEO CENTER, INT, APP INT, QUAD"
"\n2 = END, NEAR, TAN, QUAD, CENTER"
"\n3 = END, MID, PERP, NODE, INSERTION"
"\n4 = END, NEAR"
"\n5 = KITCHEN SINK"
) ; strcat
) ; alert
) ; progn

;2 151
(setq OSPlist '(("1osp" 3255) ("2osp" 789) ("3osp" 203) ("4osp" 513) ("5osp" 7423))
(initget "1osp 2osp 3osp 4osp 5osp")
(setq osp (getkword "\nOffset Profile [1osp/2osp/3osp/4osp/5osp]: "))

(progn
(setvar 'osmode (cadr (assoc osp OSPlist)))
(prin1)
) ; progn
) ; if

(princ)

 

 

0 Likes
Message 10 of 14

Kent1Cooper
Consultant
Consultant

Would you want it to report just an option number, or spell out the modes involved?

Would you want it to offer an option to change the current Osnap Profile?

[You're missing a closing right parenthesis in setting OSPlist.]

Kent Cooper, AIA
0 Likes
Message 11 of 14

timothy_crouse
Collaborator
Collaborator

>>Would you want it to report just an option number, or spell out the modes involved?

An alert dialog showing the modes enabled would be nice

 

>>Would you want it to offer an option to change the current Osnap Profile?

That would be good to see which mode is enabled when it is initiated

 

[You're missing a closing right parenthesis in setting OSPlist.]

Hmmm 🙂

 

Thank You

-Tim C.

0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

Here's a start -- a simple reporting of which option number, if the setting matches any of them.  If OSMODE is set to anything else, it does the alert and asks for a choice.

(defun C:OSP (/ osp)
  (setq
    OSPlist '(("1osp" 3255) ("2osp" 789) ("3osp" 203) ("4osp" 513) ("5osp" 7423))
    OSPlist2 (mapcar 'reverse OSPlist); with numbers first in each sub-list
    osm (getvar 'osmode)
  ); setq
  (if (assoc osm OSPlist2); current value is among options
    (prompt ; then
      (strcat
        "\nOsnap Profile is "
        (substr (cadr (assoc osm OSPlist2)) 1 1); number from front of option
        "."
      ); strcat
    ); prompt
    (progn ; else
      (alert
        (strcat
          "OSNAP PROFILES:"
          "\n1 = END,MID,PER,CEN,GCE,INT,APP,QUA"
          "\n2 = END,NEA,TAN,QUA,CEN"
          "\n3 = END,MID,PER,NOD,INS"
          "\n4 = END,NEA"
          "\n5 = KITCHEN SINK"
        ) ; strcat
      ) ; alert
      (initget "1osp 2osp 3osp 4osp 5osp")
      (setq osp (getkword "\nOffset Profile [1osp/2osp/3osp/4osp/5osp]: "))
      (setvar 'osmode (cadr (assoc osp OSPlist)))
    ) ; progn
  ) ; if
  (princ)
)

BUT:  Suppose it's set to one of those combinations, but turned off [F3]?  That would trigger the alert, too, and the User wouldn't know whether it's already set to the combination they want, and they just need to turn it on.  Should the routine assume that if you invoke the command, you want to have running Osnap turned on, and turn it on if it's off, before testing for a matching option?  It could be made more sophisticated, and determine that condition, and ask whether to just turn it on.

Kent Cooper, AIA
0 Likes
Message 13 of 14

Kent1Cooper
Consultant
Consultant

Try this:

(defun C:OSP (/ OSPnew OSPlist OPSlist2 osm OSP# OSPx)
  (defun OSPnew ()
    (alert
      (strcat
        "OSNAP PROFILES:"
        "\n  1 = END,MID,PER,CEN,GCE,INT,APP,QUA"
        "\n  2 = END,NEA,TAN,QUA,CEN"
        "\n  3 = END,MID,PER,NOD,INS"
        "\n  4 = END,NEA"
        "\n  5 = KITCHEN SINK"
        "\nPick OK and choose an option."
      ) ; strcat
    ) ; alert
    (initget "1osp 2osp 3osp 4osp 5osp")
    (setq OSP# (getkword "\nOffset Profile [1osp/2osp/3osp/4osp/5osp]: "))
    (setvar 'osmode (caddr (assoc OSP# OSPlist)))
  ); defun
  (setq
    OSPlist
      '(
        ("1osp" "END,MID,PER,CEN,GCE,INT,APP,QUA" 3255)
        ("2osp" "END,NEA,TAN,QUA,CEN" 789)
        ("3osp" "END,MID,PER,NOD,INS" 203)
        ("4osp" "END,NEA" 513)
        ("5osp" "KITCHEN SINK" 7423)
      )
    OSPlist2 (mapcar 'reverse OSPlist); numbers first
    osm (getvar 'osmode)
  ); setq
  (cond
    ((assoc osm OSPlist2); current value is among options, and ON
      (initget "Accept New")
      (setq OSPx
        (getkword
          (strcat
            "\nOsnap Profile is "
            (substr (caddr (assoc osm OSPlist2)) 1 1); number from front of option
            ": " (cadr (assoc osm OSPlist2)) ". Accept or choose New? [Accept/New] <Accept>: "
          ); strcat
        ); getkword
      ); setq
      (if (= OSPx "New") (OSPnew))
    ); existing-option condition
    ((assoc (setq OSPoff (- osm 16384)) OSPlist2); current value is among options, but OFF
      (initget "On New")
      (setq OSPx
        (getkword
          (strcat
            "\nOsnap is off; Osnap Profile is "
            (substr (caddr (assoc OSPoff OSPlist2)) 1 1); number from front of option
            ": " (cadr (assoc OSPoff OSPlist2)) ". Turn On or choose New? [On/New]: "
          ); strcat
        ); getkword
      ); setq
      (if (= OSPx "New") (OSPnew) (setvar 'osmode OSPoff))
    ); existing-option but OFF condition
    ((OSPnew)); none-of-the-above
  ); cond
  (princ)
)

 

Kent Cooper, AIA
0 Likes
Message 14 of 14

timothy_crouse
Collaborator
Collaborator

I say holy cow Ken!, with a small butt of course 🙂

 

In addition to operating with user input could it be modified so one could run the command blind by passing the selected mode at runtime?

 

The user could type "osp1" and the lisp would run with no other user input , set the OSNAP mode to profile 1

then provide the simple feedback report on the command line showing which snap point are active.

 

Would also suggest adding H back to the selection to display the alert box for those of us with short term memory 🙂

 

And lastly, if the user selects "New" but then hits a key that is not an option or taps enter the lisp should terminate without showing an error but rather stating "No profile selected"

 

Thoughts?

Best Regards

-Tim C.

 

 

 

0 Likes