Author Topic: lisp loading problem  (Read 6787 times)

0 Members and 1 Guest are viewing this topic.

diarmuid

  • Bull Frog
  • Posts: 417
lisp loading problem
« on: March 29, 2004, 06:26:17 AM »
lisp loading query

when i "appload" a lisp that i may not use very often it, on occasion, doesn't work.  acad tells me that "chgelev.lsp has loaded succesfully", but when i type chgelev the command to activate the lisp nothing happens.  if type (load "chgelev") it says load failed but then it works.  this is puzzeling, could anybody  explain what could be the problem?

thanks in advance

Diarmuid
If you want to win something run the 100m, if you want to experience something run a marathon

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
lisp loading problem
« Reply #1 on: March 29, 2004, 06:34:04 AM »
What happens if you drag-n-drop the 'chgelev.lsp' from Windows explorer into acad?
TheSwamp.org  (serving the CAD community since 2003)

hyposmurf

  • Guest
lisp loading problem
« Reply #2 on: March 29, 2004, 06:55:50 AM »
Is it possible that the defun part has been called something else or is just slightly different than the actual lisp file name?

hyposmurf

  • Guest
lisp loading problem
« Reply #3 on: March 29, 2004, 06:56:13 AM »
Is it possible that the defun part has been called something else or is just slightly different than the actual lisp file name?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
lisp loading problem
« Reply #4 on: March 29, 2004, 08:06:07 AM »
It might be that you have more than one version of the program on your system and as a result AutoCAD loads the FIRST one it finds when you load it by the command line, but when you browse for the file you load the one you see, which could be a different version.

As far as telling you one thing and doing another, unless we see some code, we won't know for sure. I think that what you are describing is probably related to the multiple files issue though.
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

CADaver

  • Guest
lisp loading problem
« Reply #5 on: March 29, 2004, 08:06:14 AM »
Yo hypo  you're stuttering again... switch to Bourbon.

diarmuid

  • Bull Frog
  • Posts: 417
heres the routine
« Reply #6 on: March 29, 2004, 08:19:39 AM »
;; change elevation - chgelev.lsp
(defun newelev (elv)
   (princ "\rWorking \\")
   (if (assoc 10 ei)
      (progn
         (setq pt (cdr (assoc 10 ei)))
         (setq xc (car pt))
         (setq yc (cadr pt))
         (setq zc elv)
         (setq coord (list xc yc zc))
         (setq ei (subst (cons 10 coord) (assoc 10 ei) ei))
         (princ "\rWorking |")
         (entmod ei)
      )
   )
   (princ "\rWorking /")
   (if (assoc 11 ei)
      (progn
         (setq pt (cdr (assoc 11 ei)))
         (setq xc (car pt))
         (setq yc (cadr pt))
         (setq zc elv)
         (setq coord (list xc yc zc))
         (setq ei (subst (cons 11 coord) (assoc 11 ei) ei))
         (princ "\rWorking -")
         (entmod ei)
      )
   )
)

(defun c:chgelev ()
   (setvar "cmdecho" 0)
   (princ "\nChange Entities Elevation. ")
   (setq ss (ssget))
   (setq ssl (sslength ss))
   (setq elv (getreal "\nEnter new elevation: "))
   (setq loop 0)
   (while (< loop ssl)
      (setq e (ssname ss loop))
      (setq ei (entget e))
      (if (= (cdr (assoc 66 ei)) 1)
         ;; THEN
         (while (/= (cdr (assoc 0 ei)) "SEQEND")
            (setq zi ei z e)
            (newelev elv)
            (setq e (entnext z))
            (setq ei (entget e))
         )
         ;; ELSE
         (newelev elv)
      )
      (entupd e)
      (setq loop (1+ loop))
   )
   (princ "\rDone!!! All entities Z coordinate at ")
   (princ (rtos elv 2 2))
   (setvar "cmdecho" 1)
   (setvar "highlight" 1)
   (princ) (terpri)
)
If you want to win something run the 100m, if you want to experience something run a marathon

hyposmurf

  • Guest
lisp loading problem
« Reply #7 on: March 29, 2004, 10:45:11 AM »
Quote from: CADaver
Yo hypo  you're stuttering again... switch to Bourbon.

Its my company inter..ter..ter..ternet,going ti..ti..ti..tits up again,you think youve posted then it crashes,so you resubmit!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
lisp loading problem
« Reply #8 on: March 29, 2004, 11:20:38 AM »
Quote from: diarmuid
but when i type chgelev the command to activate the lisp nothing happens.


You mean you don't get an error message???


My thought was that you switched drawings after loading and the routine will not be available in another drawing.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

t-bear

  • Guest
lisp loading problem
« Reply #9 on: March 29, 2004, 11:21:00 AM »
Dar....
The defun looks like it matches the lisps name so....
Don't know if it matters but, is the lsp in your startup suite?  If not, try loading it into there and see if that helps......
Like I said, just a thought.

hyposmurf

  • Guest
lisp loading problem
« Reply #10 on: March 29, 2004, 02:32:51 PM »
Even try loading it on another PC thjen youll know if its specific to your PC alone,or its the lisp that is causing you problems.Or in a rather crap less likely situation the fault occurs on a number PC's.  :crazy:

diarmuid

  • Bull Frog
  • Posts: 417
lisp loading problem
« Reply #11 on: March 30, 2004, 02:22:28 AM »
its really wierd, the lisp works well on a machine, and for no apparent reason it just doesn't excecute on a given day.  it tells me that it has loaded successfully, then when i type chgelev at the command prompt, nothing , and i mean nothing happens, no error, exlamation marks nothing, even the word "command:" that appears on every line doesn't appear

Thanks in advance

Diarmuid
If you want to win something run the 100m, if you want to experience something run a marathon

hyposmurf

  • Guest
lisp loading problem
« Reply #12 on: March 30, 2004, 06:52:47 AM »
Does it not like Monday mornings? :)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
lisp loading problem
« Reply #13 on: March 30, 2004, 08:04:31 AM »
I am beginning to wonder if you might have a lisp that has assigned a value to a protected symbol...if you do, then it might prevent the lisp from working, and from displaying the command prompt. It might in fact be stuck in some sort of loop.
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

diarmuid

  • Bull Frog
  • Posts: 417
lisp loading problem
« Reply #14 on: March 30, 2004, 08:45:06 AM »
its an irish lisp routine, it doesn't like mornings, work, effort.

lol

Diarmuid
If you want to win something run the 100m, if you want to experience something run a marathon

t-bear

  • Guest
lisp loading problem
« Reply #15 on: March 30, 2004, 10:28:44 AM »
Watch it, buster!  I'm Irish and I resemble that remark!!  

LOL

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
lisp loading problem
« Reply #16 on: March 30, 2004, 11:00:18 AM »
You are aware that this routine does not work with lwpoly lines?

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

diarmuid

  • Bull Frog
  • Posts: 417
lisp loading problem
« Reply #17 on: March 30, 2004, 11:13:18 AM »
yes i am aware, we use it because we get, on occasion work from a third party which is on all different "z" levels.  it works, for the most part, on the drawings, we do (not me, the peasant junior drafter do) have to move som information "by hand"

i've used this lisp as an example.

i like the reply about the possible loop though. hmmmmm........


is there a command that would reset all third party variables (non acad ones i mean)?

next time it happens i could run the command and see.

thanks in advance

Diarmuid

btw

bieng irish i decided i was going to put myself on a self motivation course..but i couldn't be bothered going...badum tish

thank you , i'm here all week....
lol
If you want to win something run the 100m, if you want to experience something run a marathon

SMadsen

  • Guest
lisp loading problem
« Reply #18 on: March 30, 2004, 11:18:08 AM »
Sure, just do this:

(foreach n (atoms-family 0)(setq n nil))

NO NO! Don't do that!!!  Just kidding :)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
lisp loading problem
« Reply #19 on: March 30, 2004, 11:20:40 AM »
This works well for setting to Z=0

Code: [Select]
;;; FLATTEN.LSP version 2k.01f, 14-Jul-2000
;;;
;;; FLATTEN sets the Z-coordinates of these types of objects to 0
;;; in the World Coordinate System:
;;;  "3DFACE" "ARC" "ATTDEF" "CIRCLE" "DIMENSION"
;;;  "ELLIPSE" "HATCH" "INSERT" "LINE" "LWPOLYLINE"
;;;  "MTEXT" "POINT" "POLYLINE" "SOLID" "TEXT"
;;;
;;;-----------------------------------------------------------------------
;;; copyright 1990-2000 by Mark Middlebrook
;;;   Daedalus Consulting
;;;   e-mail: mark@markcad.com
;;;
;;; Before you e-mail me with support questions, please make sure that
;;; you're using the current version. You can download it from
;;; http://markcad.com.
;;;
;;; This program is free software. You can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation: http://www.gnu.org/copyleft/gpl.html.
;;;
;;; Thanks to Vladimir Livshiz for improvements in polyline handling
;;; and the addition of several other object types.
;;;
;;;-----------------------------------------------------------------------
;;; Revision history
;;;  v. 2k.0   25-May-1999  First release for AutoCAD 2000.
;;;  v. 2k.01  25-Jun-1999  Fixed two globalization bugs ("_World" & "_X")
;;;                         and revised error handler.
;;;  v. 2k.01f 14-Jul-1999  Added GNU GPL and download info to header.
;;;
;;;-----------------------------------------------------------------------
;;;*Why Use FLATTEN?
;;;
;;; FLATTENing is useful in at least two situations:
;;;  1) You receive a DXF file created by another CAD program and discover
;;;     that all the Z coordinates contain small round-off errors. These
;;;     round-off errors can prevent you from object snapping to
;;;     intersections and make your life difficult in other ways as well.
;;;  2) In a supposedly 2D drawing, you accidentally create one object with
;;;     a Z elevation and end up with a drawing containing objects partly
;;;     in and partly outside the Z=0 X-Y plane. As with the round-off
;;;     problem, this situation can make object snaps and other procedures
;;;     difficult.
;;;
;;; Warning: FLATTEN is not for flattening the custom objects created by
;;; applications such as Autodesk's Architectural Desktop. ADT and similar
;;; programs create "application-defined objects" that only the
;;; application really knows what to do with. FLATTEN has no idea how
;;; to handle application-defined objects, so it leaves them alone.
;;;
;;;-----------------------------------------------------------------------
;;;*How to Use FLATTEN
;;;
;;; This version of FLATTEN works with AutoCAD R12 through 2000.
;;;
;;; To run FLATTEN, load it using AutoCAD's APPLOAD command, or type:
;;;   (load "FLATTEN")
;;; at the AutoCAD command prompt. Once you've loaded FLATTEN.LSP, type:
;;;   FLATTEN
;;; to run it. FLATTEN will tell you what it's about to do and ask you
;;; to confirm that you really want to flatten objects in the current
;;; drawing. If you choose to proceed, FLATTEN prompts you to select objects
;;; to be flattened (press ENTER to flatten all objects in the drawing).
;;; After you've selected objects and pressed ENTER, FLATTEN goes to work.
;;; It reports the number of objects it flattens and the number left
;;; unflattenened (because they were objects not recognized by FLATTEN; see
;;; the list of supported objects above).
;;;
;;; If you don't like the results, just type U to undo FLATTEN's work.
;;;
;;;-----------------------------------------------------------------------
;;;*Known limitations
;;;  1) FLATTEN doesn't support all of AutoCAD's object types. See above
;;;     for a list of the object types that it does work on.
;;;  2) FLATTEN doesn't flatten objects nested inside of blocks.
;;;     (You can explode blocks before flattening. Alternatively, you can
;;;     WBLOCK block definitions to separate DWG files, run FLATTEN in
;;;     each of them, and then use INSERT in the parent drawing to update
;;;     the block definitions. Neither of these methods will flatten
;;;     existing attributes, though.
;;;  3) FLATTEN flattens objects onto the Z=0 X-Y plane in AutoCAD's
;;;     World Coordinate System (WCS). It doesn't currently support
;;;     flattening onto other UCS planes.
;;;
;;;=======================================================================

(defun C:FLAT (/       tmpucs  olderr  oldcmd  zeroz   ss1     ss1len
                  i       numchg  numnot  numno0  ssno0   ename   elist
                  etype   yorn    vrt     crz
                 )
  (setq tmpucs "$FLATTEN-TEMP$")        ;temporary UCS

  ;;Error handler
  (setq olderr *error*)
  (defun *error* (msg)
    (if (or
          (= msg "Function cancelled")
          (= msg "quit / exit abort")
        )
      ;;if user cancelled or program aborted, exit quietly
      (princ)
      ;;otherwise report error message
      (princ (strcat "\nError: " msg))
    )
    (setq *error* olderr)
    (if (tblsearch "UCS" tmpucs)
      (command "._UCS" "_Restore" tmpucs "._UCS" "_Delete" tmpucs)
    )
    (command "._UNDO" "_End")
    (setvar "CMDECHO" oldcmd)
    (princ)
  )

  ;;Function to change Z coordinate to 0

  (defun zeroz (key zelist / oplist nplist)
    (setq oplist (assoc key zelist)
          nplist (reverse (append '(0.0) (cdr (reverse oplist))))
          zelist (subst nplist oplist zelist)
    )
    (entmod zelist)
  )
  ;;Setup
  (setq oldcmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "._UNDO" "_Group")
  (command "._UCS" "_Delete" tmpucs "._UCS" "_Save" tmpucs "._UCS" "_World")
                                        ;set World UCS

  ;;Get input
  (prompt
    (strcat
      "\nFLATTEN sets the Z coordinates of most objects to zero."
    )
  )

  (initget "Yes No")
  (setq yorn (getkword "\nDo you want to continue <Y>: "))
  (cond ((/= yorn "No")
         (graphscr)
         (prompt "\nChoose objects to FLATTEN ")
         (prompt
           "[press return to select all objects in the drawing]"
         )
         (setq ss1 (ssget))
         (if (null ss1)                 ;if enter...
           (setq ss1 (ssget "_X"))      ;select all entities in database
         )


         ;;*initialize variables
         (setq ss1len (sslength ss1)    ;length of selection set
               i      0                 ;loop counter
               numchg 0                 ;number changed counter
               numnot 0                 ;number not changed counter
               numno0 0                 ;number not changed and Z /= 0 counter
               ssno0  (ssadd)           ;selection set of unchanged entities
         )                              ;setq

         ;;*do the work
         (prompt "\nWorking.")
         (while (< i ss1len)            ;while more members in the SS
           (if (= 0 (rem i 10))
             (prompt ".")
           )
           (setq ename (ssname ss1 i)   ;entity name
                 elist (entget ename)   ;entity data list
                 etype (cdr (assoc 0 elist)) ;entity type
           )

           ;;*Keep track of entities not flattened
           (if (not (member etype
                            '("3DFACE"     "ARC"        "ATTDEF"
                              "CIRCLE"     "DIMENSION"  "ELLIPSE"
                              "HATCH"      "INSERT"     "LINE"
                              "LWPOLYLINE" "MTEXT"      "POINT"
                              "POLYLINE"   "SOLID"      "TEXT"
                             )
                    )
               )
             (progn                     ;leave others alone
               (setq numnot (1+ numnot))
               (if (/= 0.0 (car (reverse (assoc 10 elist))))
                 (progn                 ;add it to special list if Z /= 0
                   (setq numno0 (1+ numno0))
                   (ssadd ename ssno0)
                 )
               )
             )
           )

           ;;Change group 10 Z coordinate to 0 for listed entity types.
           (if (member etype
                       '("3DFACE"    "ARC"       "ATTDEF"    "CIRCLE"
                         "DIMENSION" "ELLIPSE"   "HATCH"     "INSERT"
                         "LINE"      "MTEXT"     "POINT"     "POLYLINE"
                         "SOLID"     "TEXT"
                        )
               )
             (setq elist  (zeroz 10 elist) ;change entities in list above
                   numchg (1+ numchg)
             )
           )

           ;;Change group 11 Z coordinate to 0 for listed entity types.
           (if (member etype
                       '("3DFACE" "ATTDEF" "DIMENSION" "LINE" "TEXT" "SOLID")
               )
             (setq elist (zeroz 11 elist))
           )

           ;;Change groups 12 and 13 Z coordinate to 0 for SOLIDs and 3DFACEs.
           (if (member etype '("3DFACE" "SOLID"))
             (progn
               (setq elist (zeroz 12 elist))
               (setq elist (zeroz 13 elist))
             )
           )

           ;;Change groups 13, 14, 15, and 16
           ;;Z coordinate to 0 for DIMENSIONs.
           (if (member etype '("DIMENSION"))
             (progn
               (setq elist (zeroz 13 elist))
               (setq elist (zeroz 14 elist))
               (setq elist (zeroz 15 elist))
               (setq elist (zeroz 16 elist))
             )
           )

           ;;Change each polyline vertex Z coordinate to 0.
           ;;Code provided by Vladimir Livshiz, 09-Oct-1998
           (if (= etype "POLYLINE")
             (progn
               (setq vrt ename)
               (while (not (equal (cdr (assoc 0 (entget vrt))) "SEQEND"))
                 (setq elist (entget (entnext vrt)))
                 (setq crz (cadddr (assoc 10 elist)))
                 (if (/= crz 0)
                   (progn
                     (zeroz 10 elist)
                     (entupd ename)
                   )
                 )
                 (setq vrt (cdr (assoc -1 elist)))
               )
             )
           )

           ;;Special handling for LWPOLYLINEs
           (if (member etype '("LWPOLYLINE"))
             (progn
               (setq elist  (subst (cons 38 0.0) (assoc 38 elist) elist)
                     numchg (1+ numchg)
               )
               (entmod elist)
             )
           )

           (setq i (1+ i))              ;next entity
         )
         (prompt " Done.")

         ;;Print results
         (prompt (strcat "\n" (itoa numchg) " object(s) flattened."))
         (prompt
           (strcat "\n" (itoa numnot) " object(s) not flattened.")
         )

         ;;If there any entities in ssno0, show them
         (if (/= 0 numno0)
           (progn
             (prompt (strcat "  ["
                             (itoa numno0)
                             " with non-zero base points]"
                     )
             )
             (getstring
               "\nPress enter to see non-zero unchanged objects... "
             )
             (command "._SELECT" ssno0)
             (getstring "\nPress enter to unhighlight them... ")
             (command "")
           )
         )
        )
  )

  (command "._UCS" "_Restore" tmpucs "._UCS" "_Delete" tmpucs)
  (command "._UNDO" "_End")
  (setvar "CMDECHO" oldcmd)
  (setq *error* olderr)
  (princ)
)

(prompt
  "\nFLATTEN version 2k.01f loaded.  Type FLATTEN to run it."
)
(princ)

;;;eof
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
lisp loading problem
« Reply #20 on: March 30, 2004, 12:04:42 PM »
I took a moment to begin to rework this, but at the moment, I don't have autocad on the current computer. As everything is packed, I  can't get to it. I'm on my parents computer. Anyway, I found some things interesting while looking at this in notepad. Look for comments in the main routine. Also, I reworked the function at the top of the routine, so I might be able to make better sense of it. I don't know if it will work or anything, but you might take my comments into consideration.
Code: [Select]
(defun newelev (elv)
(cond ((assoc 10 ei)
(setq pt (cdr (assoc 10 ei))
 xc (car pt)
 yc (cadr pt)
 zc elv
 coord (list xc yc zc)
 ei (subst
(cons 10 coord
  (assoc 10 ei)
 ei
)
     )
)
(entmod ei)
     )
     ((assoc 11 ei)
(setq pt (cdr (assoc 11 ei))
     xc (car pt)
     yc (cadr pt)
     zc elv
     coord (list xc yc zc)
     ei (subst
   (cons 11 coord)
      (assoc 11 ei)
    ei
)
)
(entmod ei)
     )
)

(defun c:chgelev ()
   (setvar "cmdecho" 0)
   (princ "\nChange Entities Elevation. ")
   (setq ss (ssget)
ssl (sslength ss)
elv (getreal "\nEnter new elevation: ")
loop 0
   )
   (while (< loop ssl)
 (setq e (ssname ss loop)
ei (entget e)
 )
 (if (= (cdr (assoc 66 ei)) 1)
          ;; THEN
(while (/= (cdr (assoc 0 ei)) "SEQEND")
(setq zi ei z e)
(newelev elv);;;what's this?????????
(setq e (entnext z)
     ei (entget e)
)
)
 ;; ELSE
(newelev elv);;;and this?????????
     )
     (entupd e)
     (setq loop (1+ loop))
   )
   (princ (strcat "\rDone!!! All entities Z coordinate at " (rtos elv 2 2)))
(setvar "cmdecho" 1)
(setvar "highlight" 1)
(princ)
)

P.S. Next time you paste code, you might want to use the code tags to keep the structure of the code. It makes it a whole lot easier for the rest of us to quickly and easily see what might be the problem.