Jump to content

New Version - problems executing lisp


drafting1768

Recommended Posts

Hi. Thanks in advance for any help that anyone can provide! I just got a new version of AutoCAD (2015). Upgrading from 2007. The problem I'm having is that I can't import my CUI from my old version as the computer it's on died. I'm trying to customize my new version from scratch and have run into a serious problem with my lisp routines. I try to load them using APPLOAD and it tells me the lsp file loaded. I then try to get it to execute in the drawing and I get:

 

Command: APPLOAD

Distance.lsp successfully loaded.

DISTBEAR.LSP successfully loaded.

Command:

Command:

Command:

Command: DISTBEAR

Unknown command "DISTBEAR". Press F1 for help.

 

What am I missing???

 

This is getting critical as I'm severely hamstrung without my trusty lisp routines!

 

Thanks!

Link to comment
Share on other sites

Can you show the source code?

 

Here's one of them:

 

(defun get_endpts (/ a b)
    (COMMAND "OSNAP" "ENDP")
    (setq a (getpoint "\nEnter first point: "))
    (setq b (getpoint "\nEnter second point: "))
    (COMMAND "OSNAP" "NONE")
    (list a b)
)

(defun c:setdim ()
  ;(initget (+ 1 2 4))
  ;(setq scalefactor (getreal "\nEnter scale factor: "))
  (if (not setmap)
      (load "setmap")
  )
  (setmap)
  (setq scalefactor #mapsc)
  ;(initget 1 "Y y N n")
  ;(setq angflg (question "Do you want azimuths printed?"))
  (setq angflg "Y" angmessage "WILL")
  ;(cond (angflg
  ;      (if (not (setq dimrotation (getangle "\nEnter angular rotation: ")))
  ;          ;(setq dimrotation #mapang )
  ;    (setq DIMROTATION 0)
  ;      )
  ;      (initget 1 "1 5")
  ;      (setq secprec (atoi (getkword "\nRound off seconds to nearest <1 or 5> ")))
  ;   )
  
  (setq dimrotation 0 secprec 5 secsmessage "5")
  (alert (strcat "DIMLINE SETTINGS: \n\nScale Factor set to: " (rtos scalefactor 2 6) "\nAzimuths " angmessage " print." "\nSeconds rounded off to " secsmessage "\""
          "\n\n\nTo change the Scale Factor use MAP SETTINGS CSF \+ ROTATION \non the LISP pulldown.\n\nTo change other settings type SETDIM2."))
  (setq dimset T)
  (princ)
  ;(chgsize (* (/ scalex 1000) 1.95))
);defun setdim

(defun c:setdim2 ()
  (initget (+ 1 2 4))
  ;(setq scalefactor (getreal "\nEnter scale factor: "))
  (if (not setmap)
         (load "setmap")
  )
  (setq scalefactor #mapsc)
  (initget 1 "Y y N n")
  (setq angflg (question "Do you want azimuths printed?"))
  (if angflg
      (progn         
        (setq DIMROTATION 0 angMessage "WILL")    
            (initget 1 "1 5")
            (setq secsMessage (getkword "\nRound off seconds to nearest <1 or 5> "))
            (setq secprec (atoi secsmessage))
        )
        (setq angMessage "WON'T" )
  )
  (alert (strcat "DIMLINE SETTINGS: \n\nScale Factor set to: " (rtos scalefactor 2 6) "\nAzimuths " angmessage " print." "\nSeconds rounded off to " secsmessage "\""
          "\n\n\nTo change the Scale Factor use MAP SETTINGS CSF \+ ROTATION \non the LISP pulldown."))
  (setq dimset T)
  ;(chgsize (* (/ scalex 1000) 1.95))
)


(defun c:dimline (/ L A B ucsflg)
    (load "F1")
    (cond ((not dimset) (c:setdim)))
    (if (/=(getvar "WORLDUCS") 1)
            (progn
                (command "UCS" "W")
                (setq UCSflg T)
            );progn
    );if
    (setq L (getline))
    (dimfunc (getassoc 10 L) (getassoc 11 L)
             (placetxt (getassoc 10 L) (getassoc 11 L))
    )
    (if UCSflg
          (COMMAND "UCS" "P")
    )
)

(defun c:dimpts (/ ENDPTS ucsflg)
    (load "F1")
    (cond ((not dimset) (c:setdim)))
    (if (/=(getvar "WORLDUCS") 1)
             (progn
                 (command "UCS" "W")
                 (setq UCSflg T)
             );progn
    );if
    (dimfunc (car(setq ENDPTS(get_endpts))) (cadr ENDPTS)
             (placetxt (car ENDPTS)(cadr ENDPTS))
    )
    (if UCSflg
               (COMMAND "UCS" "P")
    )
)
(defun dimfunc (a b below / angab distab ctrpt d)
    (setq angab (angle a b))
    (setq distab (distance a b))
    (setq ctrpt (polar a angab (/ distab 2)))
    (setq d  (/ distab scalefactor))
    (cond
      (below
         (cond
            ((and (> angab (+ NORTH 0.1744)) (<= angab (+ SOUTH 0.1744)))
               (writedim d angab ctrpt (+ angab A90) (- angab PI) 1.20 2.85)
            )
            (T (writedim d angab ctrpt (+ angab A270) angab 1.20 2.85))
         )
      )
      (T (cond
            ((and (> angab (+ NORTH 0.1744)) (<= angab (+ SOUTH 0.1744)))
               (writedim d angab ctrpt (+ angab A270) (- angab PI) 1.20 2.85)
            )
            (T (writedim d angab ctrpt (+ angab A90) angab 1.20 2.85))
         )
      )
    )
)
(defun writedim (d azimuth ctrpt perpang orientation sp1 sp2 / textpt scalept)
    ;(switchl "DIMENSION")
    (setq textpt (polar ctrpt perpang (* (getxtht) sp1)))
    (setq scalePt ctrpt)
    (COMMAND "TEXT" "M" textpt  (angtos orientation)  (rtos d 2 2))
    (cond (angflg
       (setq textpt (polar ctrpt perpang (* (getxtht) sp2)))
       (COMMAND "TEXT" "M" textpt (angtos orientation)
                     (writeang (+ angab (dtr dimrotation)))
        )
    ))
    (if (= (substr (getvar "CLAYER") 1 2) "34")
        (progn
            (findDetailScale)
            (if (and (/= nil detTxtScl)(/= 0.0 detTxtScl))           
                (command "SCALE" (lastn 2) "" scalept detTxtscl)
                (command "SCALE" (lastn 2) "" scalept theRatio) 
            )
        )
    )
            
         
   ; (switchl nil)
)


(defun findDetailScale ( / detLayer detLen det7thLast undScr)
   (if (not c:lastn)
       (load "LASTN")
   )
   (if (null theRatio)
       (progn
           (load "labelling")
           (c:detail)
       )
   )
   (setq detLayer (getvar "CLAYER"))
   (setq detlen (strlen detLayer))
   (setq det7thLast (substr detLayer (- detLen 6)))
   (setq undScr (st_scan "_" det7thlast))
   (setq detTxtScl  (/ (* 0.001 (atoi (substr det7thLast (+ 1 undScr)))) plscale))
)
   
   

(defun writeang (azimuth)
 (setq azimuth (angtos azimuth 1 4))
 (if (= "d" (substr azimuth 3 1))
     (strcat (deg_format azimuth 3))
     (if (= "d" (substr azimuth 4 1))
         (strcat (deg_format azimuth 4))
         (strcat (deg_format azimuth 2))
     )
 )
 (cond ((= 5 secprec)
          (cond
             ((< 7 (last_digit seconds))
                (setq seconds (additostr seconds (- 10 (last_digit seconds))))
             )
             ((< 2 (last_digit seconds))
                (setq seconds (additostr seconds (- 5 (last_digit seconds))))
             )
             (T (setq seconds (additostr seconds (- 0 (last_digit seconds)))))
          )
          (if (= (strlen seconds) 1) (setq seconds (strcat "0" seconds)))
          (if (= "60" seconds) (progn
              (setq seconds "00")
              (setq minutes (additostr minutes 1))
              (if (= (strlen minutes) 1) (setq minutes (strcat "0" minutes)))
              (if (= "60" minutes) (progn
                  (setq minutes "00")
                  (setq degrees (additostr degrees 1))
              ))
          ))
 ))
 (if (/= (strcase (getvar "LOGINNAME")) "Pam.hvizdos")
     (strcat degrees "%%d " minutes "' " seconds "\"")
     (strcat degrees "%%d" minutes "'" seconds "\"")
 )
     
)


(defun deg_format ( str pos)
   (setq degrees (substr str 1 (- pos 1)))
   (min_format (substr str (+ pos 1)))
)
(defun min_format (str)
   (setq minutes (cond ((= "'" (substr str 2 1))
                        (sec_format (substr str 3))
                        (strcat"0" (substr str 1 1))
                       )
                       (T (sec_format (substr str 4))
                          (substr str 1 2)
                       )
                 )
   )
)


(defun sec_format (str)
   (setq seconds (substr (if ( = 2 (strlen str))
                             (strcat "0" str)
                             str
                         )
                         1 2
   ))
)
(defun last_digit(str)
  (atoi (substr str (strlen str)))
)
(defun additostr(str no)
      (itoa (+ (atoi str) no))
)

Edited by Cad64
Added code tags
Link to comment
Share on other sites

There is no DISTBEAR in the code submitted what you are looking for is C:distbear have a look at the code submitted a C:something means you can type it as a command on the Keyboard.

Link to comment
Share on other sites

Thanks for your help, BIGAL. I have another one, if you wouldn't mind taking a look? This is the lisp I'd prefer to use over DISTBEAR (old habits die hard). I've solved the issue of it not loading properly but now it's not performing correctly. Maybe something has changed since it was written and it won't execute the same way? Thanks in advance again! :) This one is called DIMLINE and the C:DIMLINE is present.

 

(defun get_endpts (/ a b)
    (COMMAND "OSNAP" "ENDP")
    (setq a (getpoint "\nEnter first point: "))
    (setq b (getpoint "\nEnter second point: "))
    (COMMAND "OSNAP" "NONE")
    (list a b)
)

(defun c:setdim ()
  ;(initget (+ 1 2 4))
  ;(setq scalefactor (getreal "\nEnter scale factor: "))
  (if (not setmap)
      (load "setmap")
  )
  (setmap)
  (setq scalefactor #mapsc)
  ;(initget 1 "Y y N n")
  ;(setq angflg (question "Do you want azimuths printed?"))
  (setq angflg "Y" angmessage "WILL")
  ;(cond (angflg
  ;      (if (not (setq dimrotation (getangle "\nEnter angular rotation: ")))
  ;          ;(setq dimrotation #mapang )
  ;    (setq DIMROTATION 0)
  ;      )
  ;      (initget 1 "1 5")
  ;      (setq secprec (atoi (getkword "\nRound off seconds to nearest <1 or 5> ")))
  ;   )
  
  (setq dimrotation 0 secprec 5 secsmessage "5")
  (alert (strcat "DIMLINE SETTINGS: \n\nScale Factor set to: " (rtos scalefactor 2 6) "\nAzimuths " angmessage " print." "\nSeconds rounded off to " secsmessage "\""
          "\n\n\nTo change the Scale Factor use MAP SETTINGS CSF \+ ROTATION \non the LISP pulldown.\n\nTo change other settings type SETDIM2."))
  (setq dimset T)
  (princ)
  ;(chgsize (* (/ scalex 1000) 1.95))
);defun setdim

(defun c:setdim2 ()
  (initget (+ 1 2 4))
  ;(setq scalefactor (getreal "\nEnter scale factor: "))
  (if (not setmap)
         (load "setmap")
  )
  (setq scalefactor #mapsc)
  (initget 1 "Y y N n")
  (setq angflg (question "Do you want azimuths printed?"))
  (if angflg
      (progn         
        (setq DIMROTATION 0 angMessage "WILL")    
            (initget 1 "1 5")
            (setq secsMessage (getkword "\nRound off seconds to nearest <1 or 5> "))
            (setq secprec (atoi secsmessage))
        )
        (setq angMessage "WON'T" )
  )
  (alert (strcat "DIMLINE SETTINGS: \n\nScale Factor set to: " (rtos scalefactor 2 6) "\nAzimuths " angmessage " print." "\nSeconds rounded off to " secsmessage "\""
          "\n\n\nTo change the Scale Factor use MAP SETTINGS CSF \+ ROTATION \non the LISP pulldown."))
  (setq dimset T)
  ;(chgsize (* (/ scalex 1000) 1.95))
)


(defun c:dimline (/ L A B ucsflg)
    (load "F1")
    (cond ((not dimset) (c:setdim)))
    (if (/=(getvar "WORLDUCS") 1)
            (progn
                (command "UCS" "W")
                (setq UCSflg T)
            );progn
    );if
    (setq L (getline))
    (dimfunc (getassoc 10 L) (getassoc 11 L)
             (placetxt (getassoc 10 L) (getassoc 11 L))
    )
    (if UCSflg
          (COMMAND "UCS" "P")
    )
)

(defun c:dimpts (/ ENDPTS ucsflg)
    (load "F1")
    (cond ((not dimset) (c:setdim)))
    (if (/=(getvar "WORLDUCS") 1)
             (progn
                 (command "UCS" "W")
                 (setq UCSflg T)
             );progn
    );if
    (dimfunc (car(setq ENDPTS(get_endpts))) (cadr ENDPTS)
             (placetxt (car ENDPTS)(cadr ENDPTS))
    )
    (if UCSflg
               (COMMAND "UCS" "P")
    )
)
(defun dimfunc (a b below / angab distab ctrpt d)
    (setq angab (angle a b))
    (setq distab (distance a b))
    (setq ctrpt (polar a angab (/ distab 2)))
    (setq d  (/ distab scalefactor))
    (cond
      (below
         (cond
            ((and (> angab (+ NORTH 0.1744)) (<= angab (+ SOUTH 0.1744)))
               (writedim d angab ctrpt (+ angab A90) (- angab PI) 1.20 2.85)
            )
            (T (writedim d angab ctrpt (+ angab A270) angab 1.20 2.85))
         )
      )
      (T (cond
            ((and (> angab (+ NORTH 0.1744)) (<= angab (+ SOUTH 0.1744)))
               (writedim d angab ctrpt (+ angab A270) (- angab PI) 1.20 2.85)
            )
            (T (writedim d angab ctrpt (+ angab A90) angab 1.20 2.85))
         )
      )
    )
)
(defun writedim (d azimuth ctrpt perpang orientation sp1 sp2 / textpt scalept)
    ;(switchl "DIMENSION")
    (setq textpt (polar ctrpt perpang (* (getxtht) sp1)))
    (setq scalePt ctrpt)
    (COMMAND "TEXT" "M" textpt  (angtos orientation)  (rtos d 2 2))
    (cond (angflg
       (setq textpt (polar ctrpt perpang (* (getxtht) sp2)))
       (COMMAND "TEXT" "M" textpt (angtos orientation)
                     (writeang (+ angab (dtr dimrotation)))
        )
    ))
    (if (= (substr (getvar "CLAYER") 1 2) "34")
        (progn
            (findDetailScale)
            (if (and (/= nil detTxtScl)(/= 0.0 detTxtScl))           
                (command "SCALE" (lastn 2) "" scalept detTxtscl)
                (command "SCALE" (lastn 2) "" scalept theRatio) 
            )
        )
    )
            
         
   ; (switchl nil)
)


(defun findDetailScale ( / detLayer detLen det7thLast undScr)
   (if (not c:lastn)
       (load "LASTN")
   )
   (if (null theRatio)
       (progn
           (load "labelling")
           (c:detail)
       )
   )
   (setq detLayer (getvar "CLAYER"))
   (setq detlen (strlen detLayer))
   (setq det7thLast (substr detLayer (- detLen 6)))
   (setq undScr (st_scan "_" det7thlast))
   (setq detTxtScl  (/ (* 0.001 (atoi (substr det7thLast (+ 1 undScr)))) plscale))
)
   
   

(defun writeang (azimuth)
 (setq azimuth (angtos azimuth 1 4))
 (if (= "d" (substr azimuth 3 1))
     (strcat (deg_format azimuth 3))
     (if (= "d" (substr azimuth 4 1))
         (strcat (deg_format azimuth 4))
         (strcat (deg_format azimuth 2))
     )
 )
 (cond ((= 5 secprec)
          (cond
             ((< 7 (last_digit seconds))
                (setq seconds (additostr seconds (- 10 (last_digit seconds))))
             )
             ((< 2 (last_digit seconds))
                (setq seconds (additostr seconds (- 5 (last_digit seconds))))
             )
             (T (setq seconds (additostr seconds (- 0 (last_digit seconds)))))
          )
          (if (= (strlen seconds) 1) (setq seconds (strcat "0" seconds)))
          (if (= "60" seconds) (progn
              (setq seconds "00")
              (setq minutes (additostr minutes 1))
              (if (= (strlen minutes) 1) (setq minutes (strcat "0" minutes)))
              (if (= "60" minutes) (progn
                  (setq minutes "00")
                  (setq degrees (additostr degrees 1))
              ))
          ))
 ))
 (if (/= (strcase (getvar "LOGINNAME")) "Pam.hvizdos")
     (strcat degrees "%%d " minutes "' " seconds "\"")
     (strcat degrees "%%d" minutes "'" seconds "\"")
 )
     
)


(defun deg_format ( str pos)
   (setq degrees (substr str 1 (- pos 1)))
   (min_format (substr str (+ pos 1)))
)
(defun min_format (str)
   (setq minutes (cond ((= "'" (substr str 2 1))
                        (sec_format (substr str 3))
                        (strcat"0" (substr str 1 1))
                       )
                       (T (sec_format (substr str 4))
                          (substr str 1 2)
                       )
                 )
   )
)


(defun sec_format (str)
   (setq seconds (substr (if ( = 2 (strlen str))
                             (strcat "0" str)
                             str
                         )
                         1 2
   ))
)
(defun last_digit(str)
  (atoi (substr str (strlen str)))
)
(defun additostr(str no)
      (itoa (+ (atoi str) no))
)

Edited by Cad64
Added code tags
Link to comment
Share on other sites

You need to put your code inside code brackets use [c o d e] at start [/c o d e] at end with no spaces, the administrator will be on your back about this.

 

Ok still missing bits (load "F1"). (load "setmap") (placetxt (getassoc 10 L) (getassoc 11 L)) no placetext code

 

Maybe fix this 1st in your code is smileys just look at the post remove this line in your code don't know if it makes any difference. because it does use so many defuns need to really work out where its stopping and inside which one.

 

I would do each step manually look at DIMLINE and follow the steps, if you use VLIDE pretty sure you can line by line step through it this way it will stop and you can see where. http://www.lee-mac.com for a vlide tutorial.

 

To really have some one debug it do as I first suggested make a new lisp by pasting all the defuns that get used in dimline, setdim, F1, getassoc

Link to comment
Share on other sites

Great, thanks! This is ancient code that I inherited with my first job and never gave it much thought as it worked just fine until this latest upgrade. Looks like it needs some serious work. Thanks for you assistance, greatly appreciated!

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...