Jump to content
tmelancon

Need assistance figuring OSNAP for my LISP! THANKS!

Recommended Posts

tmelancon

Hello all. I have a LISP routine that I have been using forever now so excuse me if it is written sorta outdated to what it could look like if it were updated.

 

It is a balloon(bubble) routine to insert letters or numbers inside a sized bubble with a line and an arrow. The problem I am having is that when running the command after selecting my first point i have to physically turn off OSNAP then after I enter the numbers and finish the command turn OSNAP back on because if I do not it distorts the arrow...

 

I have a mouse with extra programmed buttons that allows me to speed up the process as if it never happens, but still thats not the point. It would be nice to just keep all my snaps on all the time and let the code and just continue to breeze through my drawings. I have tried a few things and I am finished with trying for now. Besides I have others in my cad department that have regular mice and we all believe it could be made better.

 

Figured I would take it to the CAD community, because after all I know this is what some of you live for also.

 

So to sum it up I am basically looking for the code to be revised so that when I start the command it will change OSMODE properly to allow for everything to be entered with no problems. Whether SNAP is turned off/on of OSMODE is altered I do not really care just as long as SNAP IS ON DURING FIRST USER POINT so that my leader is on my pipe and SNAP IS BACK TO ALL ON after the command.

 

THANKS THANKS THANKS IN ADVANCE! Sorry if I am missing it guys, I have tried. Here is the code:

 

************************ DATAPOINT BUBBLE INSERTION **************************
(defun c:BALLOON (/ oldlayr oldos)
(setq oldlayr (getvar "clayer"))
(command "._-layer" "s" TEXT "")
(initget (+ 1))
(setq pt1 (getpoint "\nDatapoint location on pipe: "))  ; Get 1st loc
(initget (+ 1 32))
(command "OSNAP" "NONE")
(setq pt2 (getpoint pt1 "\nDatapoint bubble location: "))  ; Get 2nd loc
(initget (+ 1 2 4))
(if (= etype "G")
 (progn
  (setq dps (strcase (getstring "\nEnter datapoint ID (A1 - A999) or (A1 - AZ99): ")))    ; Get DP#
  (if (< (strlen dps) 3)
   (setq csize (* (getvar "userr1") 1.2))         ; balloon for A1
   (progn
    (if (< (strlen dps) 4)
     (setq csize (* (getvar "userr1") 1.9))    ; balloon for A22
     (setq csize (* (getvar "userr1") 2.3))    ; balloon for A333
    )
   )
  )
 )
 (progn
  (setq dpnum (getreal "\nEnter datapoint number (1.0-999.9): "))    ; Get DP#
  (setq dps (rtos dpnum 2 1))
  (if (< (strlen dps) 4)
   (setq csize (* (getvar "userr1") 1.6))     ; balloon for 9.9
   (progn
    (if (< (strlen dps) 5)
     (setq csize (* (getvar "userr1") 2.0))   ; balloon for 99.9
     (setq csize (* (getvar "userr1") 2.4))   ; balloon for 999.9
    )
   )
  )
 )
)
(command "._circle" pt2 csize)
(setq a (angle pt2 pt1))
(setq OLDOS (getvar "OSMODE"))
(setvar "OSMODE" 0)
(command "._line" pt1 (osnap (polar pt2 a csize) "nearest") "" )
(setvar "OSMODE" OLDOS)  
(command "._solid" pt1 (polar pt1 (- a 85) (getvar "userr1"))
                     (polar pt1 (+ a 85) (getvar "userr1")) "" "")
(command "._text" "m" pt2 (GETVAR "USERR1") 0 dps)
(command "._-layer" "s" oldlayr "")
(prin1))

Share this post


Link to post
Share on other sites
marko_ribar

Here, I've modified your code just a little and added better formatting of code...

 

************************ DATAPOINT BUBBLE INSERTION **************************
(defun c:BALLOON (/ *error* a csize dpnum dps etype oldlayr oldos pt1 pt2 text user)

 (defun *error* (msg)
   (if oldlayr (setvar "clayer" oldlayr))
   (if oldos (setvar "osmode" oldos))
   (if msg (prompt msg))
   (princ)
 )

 (setq oldlayr (getvar "clayer"))
 (setq oldos (getvar "osmode"))
 (while (and 
          (not (initget (+ 2 4)))
          (eq (setq user (getreal (strcat "\nInput value of \"USERR1\" variable <" (rtos (getvar "userr1")) ">: "))) nil) 
          (= (getvar "userr1") 0.0)
        )
        (prompt "\nInvalid value of \"USERR1\" variable - must be different than 0.0!!! Try again...")
 )
 (setvar "userr1" (if (eq user nil) (getvar "userr1") user))
 (setq text (getstring T (strcat "\nEnter name of BALLOON Layer <" oldlayr ">: ")))
 (if (eq text "") (setq text oldlayr))
 (if (tblsearch "LAYER" text)
   (command "_.-layer" "s" text "")
   (command "_.-layer" "m" text "")
 )
 (initget (+ 1))
 (setq pt1 (getpoint "\nDatapoint location on pipe: ")) ; Get 1st loc
 (initget (+ 1 32))
 (setvar "osmode" 0)
 (setq pt2 (getpoint pt1 "\nDatapoint bubble location: "))
                                       ; Get 2nd loc
 (setq etype
        (strcase
          (getstring
            "\nEnter \"G\" for coded balloon or ENTER for numbered balloon: "
          )
        )
 )
 (initget (+ 1 2 4))
 (if (= etype "G")
   (progn
     (setq
       dps (strcase
             (getstring
               "\nEnter datapoint ID (A1 - A999) or (A1 - AZ99): "
             )
           )
     )                                 ; Get DP#
     (if (< (strlen dps) 3)
       (setq csize (* (getvar "userr1") 1.2)) ; balloon for A1
       (progn
         (if (< (strlen dps) 4)
           (setq csize (* (getvar "userr1") 1.9)) ; balloon for A22
           (setq csize (* (getvar "userr1") 2.3)) ; balloon for A333
         )
       )
     )
   )
   (progn
     (setq dpnum (getreal "\nEnter datapoint number (1.0-999.9): "))
                                       ; Get DP#
     (setq dps (rtos dpnum 2 1))
     (if (< (strlen dps) 4)
       (setq csize (* (getvar "userr1") 1.6)) ; balloon for 9.9
       (progn
         (if (< (strlen dps) 5)
           (setq csize (* (getvar "userr1") 2.0)) ; balloon for 99.9
           (setq csize (* (getvar "userr1") 2.4)) ; balloon for 999.9
         )
       )
     )
   )
 )
 (command "_.circle" pt2 csize)
 (setq a (angle pt2 pt1))
 (command "_.line"
          pt1
          (osnap (polar pt2 a csize) "nearest")
          ""
 )
 (command "_.solid"
          pt1
          (polar pt1 (- a 85) (getvar "userr1"))
          (polar pt1 (+ a 85) (getvar "userr1"))
          ""
          ""
 )
 (command "_.text" "m" pt2 (getvar "userr1") 0 dps)
 (*error* nil)
 (princ)
)

Edited by marko_ribar
fixed error "userr1"

Share this post


Link to post
Share on other sites
tmelancon

Getting an error..

 

Input value of "USERR1" variable :

AutoCAD variable setting rejected: "userr1" nil

 

Maybe some clarification would help. Thanks Marko! :shock:

Share this post


Link to post
Share on other sites
marko_ribar
Getting an error..

 

Input value of "USERR1" variable :

AutoCAD variable setting rejected: "userr1" nil

 

Maybe some clarification would help. Thanks Marko! :shock:

 

Try now, tmelancon...

Mistake is fixed now...

Share this post


Link to post
Share on other sites
tmelancon

Its still prompting me to specify value for userr1. Then "G" or enter.. I also noticed that there were two more pieces of code right under the balloon code, they coincide. I was in a rush yesterday sorry for the miscommunication of the code. Check it out when you have time. God bless.

 

************************ DATAPOINT BUBBLE INSERTION **************************
(defun c:BALLOON (/ oldlayr oldos)
(setq oldlayr (getvar "clayer"))
(command "._-layer" "s" TEXT "")
(initget (+ 1))
(setq pt1 (getpoint "\nDatapoint location on pipe: "))  ; Get 1st loc
(initget (+ 1 32))
(setq pt2 (getpoint pt1 "\nDatapoint bubble location: "))  ; Get 2nd loc
(initget (+ 1 2 4))
(if (= etype "G")
 (progn
  (setq dps (strcase (getstring "\nEnter datapoint ID (A1 - A999) or (A1 - AZ99): ")))    ; Get DP#
  (if (< (strlen dps) 3)
   (setq csize (* (getvar "userr1") 1.2))         ; balloon for A1
   (progn
    (if (< (strlen dps) 4)
     (setq csize (* (getvar "userr1") 1.9))    ; balloon for A22
     (setq csize (* (getvar "userr1") 2.3))    ; balloon for A333
    )
   )
  )
 )
 (progn
  (setq dpnum (getreal "\nEnter datapoint number (1.0-999.9): "))    ; Get DP#
  (setq dps (rtos dpnum 2 1))
  (if (< (strlen dps) 4)
   (setq csize (* (getvar "userr1") 1.6))     ; balloon for 9.9
   (progn
    (if (< (strlen dps) 5)
     (setq csize (* (getvar "userr1") 2.0))   ; balloon for 99.9
     (setq csize (* (getvar "userr1") 2.4))   ; balloon for 999.9
    )
   )
  )
 )
)
(command "._circle" pt2 csize)
(setq a (angle pt2 pt1))
(setq OLDOS (getvar "OSMODE"))
(setvar "OSMODE" 0)
(command "._line" pt1 (osnap (polar pt2 a csize) "nearest") "" )
(setvar "OSMODE" OLDOS)  
(command "._solid" pt1 (polar pt1 (- a 85) (getvar "userr1"))
                     (polar pt1 (+ a 85) (getvar "userr1")) "" "")
(command "._text" "m" pt2 (GETVAR "USERR1") 0 dps)
(command "._-layer" "s" oldlayr "")
(prin1))

****************************** DATAPOINT SIZE ********************************
(defun dpsize_main ()
(if (not (new_dialog "dpsize" dcl_id)) (exit))
(set_tile "curr_size" (rtos (getvar "userr1") 2 4))
(action_tile "dp_size" "(setq sizenum $value)")
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 1)")
(start_dialog)
(command "._userr1" sizenum)
(prin1))

(defun c:dpsize () (setvar "CMDECHO" 0) (command "._undo" "M")
(cond ((not (ai_trans)))
      ((not (ai_acadapp)))
      ((not (setq dcl_id (ai_dcl "kbupdate"))))
      (T (if (/= 1 (logand (getvar "CMDACTIVE") 1)) (ai_undo_push))
         (dpsize_main)
         (if (/= 1 (logand (getvar "CMDACTIVE") 1)) (ai_undo_pop))))
(princ))

****************************** SYMBOL SIZE ********************************
(defun symbsize_main ()
(if (not (new_dialog "symbsize" dcl_id)) (exit))
(set_tile "curr_size" (rtos (getvar "userr2") 2 4))
(action_tile "symb_size" "(setq sizenum $value)")
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 1)")
(start_dialog)
(command "._userr2" sizenum)
(prin1))

(defun c:symbsize () (setvar "CMDECHO" 0) (command "._undo" "M")
(cond ((not (ai_trans)))
      ((not (ai_acadapp)))
      ((not (setq dcl_id (ai_dcl "kbupdate"))))
      (T (if (/= 1 (logand (getvar "CMDACTIVE") 1)) (ai_undo_push))
         (symbsize_main)
         (if (/= 1 (logand (getvar "CMDACTIVE") 1)) (ai_undo_pop))))
(princ))

Share this post


Link to post
Share on other sites
marko_ribar

My version works without dialog box... If you want to share your version, you have to provide code for kbupdate.dcl also...

 

Check my version, it should work...

 

M.R.

Share this post


Link to post
Share on other sites
tmelancon

Hey Marko,

 

With the code I provided, it works flawlessly with no user input but the bubble number. I simply enter my shortcut for the balloon command, pick my first point on pipe, pick second point for bubble then number for that point and then move on to the next bubble. I enter thousands of these bubbles a day and the problem with my current code is that the OSNAP messes up the leader so we have to manually turn OSNAP off after picking the first point(which has to be snapped to pipe because I hate when it doesnt touch the pipe)... The code works with a text layer that we have being created for new drawings so that may be why it isnt working on your end because its looking for our specified "TEXT" layer that is being created with other pieces if code from a program we wrote.

 

So I really just need to figure out how to throw that in there to allow snap to stay on while i pick my first point then go off after that until I finish executing the command THEN come back on and return to ALL ON after that.

Share this post


Link to post
Share on other sites
marko_ribar

What is the problem to hit 3x enter once upon first creation settings have been made if you want numbered balloon... If you wanted coded one, you have to specify that option - there is no other quicker way...

Share this post


Link to post
Share on other sites
tmelancon

I really thank you for your efforts but I was really just looking to correct the OSNAP error. I see in your updated code where you specify OSMODE to 0 after the first click but I cannot find where you have OSNAP returning to normal after the command. I am looking for that to work in my code.

Share this post


Link to post
Share on other sites
marko_ribar

My code has error handler...

 

When command starts, currently set OSNAP is active, until you provide first point, after that OSMODE is set to 0, not to mess with second point input and proceeding (command) calls... If you look closer, in my error handler, I specified that if variables where old sysvars exist, then when unexpected function termination happen, these old settings are restored... Further more, if you look in my last statement just before (princ) - quiet exit routine, you'll see that I called error handler with nil msg argument provided so that at the end of routine old settings are restored (among witch is oldos - OSMODE)... If you search www for managing error handlers, you'll see also that this definition has to be made with one argument that represent error message, so in the end of my code - if everything is passed correct that argument is nil - witch means no message should be prompted :

(*error* nil)

 

As for my statement that you have to hit 3x enter after first balloon is made, that's true but you must change your current layer after making balloon to match that one of balloon, because error handler will restore current layer after routine execution, so if before making second and next balloons if you don't change current layer, default layer before making first balloon will be default - prompted in to hit enter for proceeding... So if you make this change after first balloon, you have to tap 2x enter, pick 2 new points for next balloon and again hit enter to specify numbered option after witch you have to enter number and hit enter to accept... And opposite, you must specify option that you want coded balloon with pressing "G" key and enter after witch you have to specify letter code and hit enter to accept...

 

So, you actually have 4x enter, 2 point inputs and code specification...

 

If wanted next balloon, you'll have in CAD history last command witch was executed, so you just hit another enter, and you'll start over with current OSNAPS active, because error handler restored them at the end of previous balloon creation...

 

M.R.

Share this post


Link to post
Share on other sites
tmelancon

MARKO! THANK YOU THANK YOU! The error handling piece is what i needed!!!!!! AHHHH!!!! YES! After doing some editing and rearranging of my code that is EXACTLY what I needed! Thank you so much for your collaboration! It is greatly appreciated! God bless you brother! :all hail thee:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...