Author Topic: Specific drawing files causing lisp routine to fail?  (Read 8189 times)

0 Members and 1 Guest are viewing this topic.

KewlToyZ

  • Guest
Specific drawing files causing lisp routine to fail?
« on: August 18, 2006, 07:12:27 PM »
I went through all setvars in the drawings and I cant figure out what is causing my lisp routine to fail.
It runs fine in Versions 2004-2007, just these specific drawings make my lisps fail and I am baffled?
Normally the routine asks for the label i want to type then just places that text on the object i specify and trims the object around it.

Routine:
Code: [Select]
(defun textinline (txt / entt txt ent pkpt entinf enttyp rot txtnam)
  (SETUP)
  (lrs "G-ANNO-TEXT")
  (SETVAR "OSMODE" 0)
  (setvar "texteval" 1)
(if (= nil txt)
  (setq txt (getstring T "\n(Press 'Esc' to cancel) Enter Label: ")))
  (while (setq ent (entsel "\n(Press 'Esc' to cancel) What do you want to label?"))
    (setq pkpt (osnap (cadr ent) "nea"))
    (setq entt (car ent))
    (setq entinf (entget entt))
    (setq enttyp (cdr (assoc 0 entinf)))
    (cond
      ((member enttyp '("LINE" "LWPOLYLINE"))
       (setq rotpt (osnap pkpt "end"))
      )
      ((member enttyp '("ARC" "CIRCLE"))
       (setq rotpt (osnap pkpt "cen"))
      )
      (T (ALERT "Must Select ARC CIRCLE POLYLINE or LINE"))
    )
    (setq rot (angle pkpt rotpt))
    (if (and (<= rot (* 3 (/ pi 2))) (> rot (/ pi 2)))
      (setq rot (+ rot pi))
    )
    (if (equal rot (* 3 (/ pi 2)) 0.01)
      (setq rot (/ pi 2))
    )   
    (command "text" "j" "m" pkpt "" (* rot (/ 180 pi)) txt)
    (setq txtnm (entlast))
    (cond
      ((member enttyp '("ARC" "CIRCLE"))
       (command "rotate" txtnm "" pkpt 90)
      )
      (T)
    )
    (setq ed (entget txtnm))
    (setq rot (cdr (assoc 50 (entget txtnm))))
    (entmod ed)
    (entupd txtnm)
    (command "trim" txtnm "" ent "")
  )
  (END)
  (C:textinline)
)
(defun c:textinline()
(textinline nil)
)

Error description:
The command line spits out:
Command: textinline
Command: (Press 'Esc' to cancel) Enter Label: HWC
What do you want to label?Unknown command "HWC". Press F1 for help.


The drawing ends up inserting a numeric value as text with a decimal going out 12 places and trimming the line to fit around the text.

Any suggestions what drawing settings could cause these types of lisp failures?




EDIT: The [ code ] and [ pre ] tag thing
« Last Edit: August 19, 2006, 07:38:29 AM by nivuahc »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #1 on: August 18, 2006, 07:18:39 PM »
What is the code for the LRS routine ?

Can you post the offending drawing ?

What have you done to try to find the problem ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #2 on: August 18, 2006, 07:22:36 PM »
.. and the  (SETUP) routine ? ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Specific drawing files causing lisp routine to fail?
« Reply #3 on: August 18, 2006, 07:23:45 PM »
Define your error handler as (defun *error* (x) (vl-bt)) then run the program.

Without running the program my money is on one of these lines --

29: (command "text" "j" "m" pkpt "" (* rot (/ 180 pi)) txt)

or

33: (command "rotate" txtnm "" pkpt 90)

or

41: (command "trim" txtnm "" ent "")

The numbers at the beginning of each line above are the text file line numbers assuming (defun textinline ... is line number #1. An extra carriage return is being passed to command (guess).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #4 on: August 18, 2006, 07:29:11 PM »
.. and the (END) routine .. ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #5 on: August 18, 2006, 07:30:46 PM »
This is an unusual circular reference ..
Code: [Select]
(DEFUN textinline (txt / entt txt ent pkpt entinf enttyp rot txtnam)
  ;;; do stuff
 (c:textinline)
)
(DEFUN c:textinline () (textinline nil))
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #6 on: August 18, 2006, 07:32:44 PM »
I have the code working .. what was your error message ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #7 on: August 18, 2006, 07:34:08 PM »
Code: [Select]
     (COND ((MEMBER enttyp '("LINE" "LWPOLYLINE"))
            (SETQ rotpt (OSNAP pkpt "end"))
           )
           ((MEMBER enttyp '("ARC" "CIRCLE")) (SETQ rotpt (OSNAP pkpt "cen")))
           (T (ALERT "Must Select ARC CIRCLE POLYLINE or LINE"))
     )
What do you expect to happen if/after this conditional gets to the alert message
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #8 on: August 18, 2006, 09:14:07 PM »
I was waiting for a response, but realised you are probably in bed. 

I'll see if I can throw something together ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #9 on: August 18, 2006, 09:47:03 PM »
This code is not optimal, and is probably a little more compartmentalised than you are used to ...
.. give it a run.

Code: [Select]
(DEFUN c:textinline () (textinline nil))

(DEFUN textinline (textstring      /
                   etype           selectedent
                   selectionpoint  textstring
                   ;;
                   *error*         _dtr
                   _rtd            _stringprintable-p
                   _drawtext       _settextangle
                   _trimfortext    _textincircle
                   _textinline
                  )
  ;;
  ;;-----------------------------------------
  ;; kwb@theSwamp 20060819
  ;; proof of concept code for
  ;; http://www.theswamp.org/index.php?topic=11903.msg148247#msg148247
  ;;----------------------------------------- 
  ;; 
  ;;  (setup)
  ;; (lrs "G-ANNO-TEXT")
  ;;
  ;; The previous values SHOULD be saved and restored later.
  (SETVAR "OSMODE" 0)
  (SETVAR "texteval" 1)
  ;;
  ;;-----------------------------------------
  (DEFUN *error* (errormessage /)
    (COND ((NOT errormessage))                              ; no error, do nothing
          ((VL-POSITION (STRCASE errormessage T)            ; cancel
                        '("console break"
                          "function cancelled"
                          "quit / exit abort"
                         )
           )
          )
          ((PRINC (STRCAT "\nApplication Error: "
                          (GETVAR "errno")
                          " :- "
                          errormessage
                  )
           )
          )
    )
    ;; (VL-BT)
    ;;(end)
  )
  ;;-----------------------------------------
  (DEFUN _dtr (ang) (* PI (/ ang 180.0)))
  ;;-----------------------------------------
  (DEFUN _rtd (ang) (/ (* ang 180.0) PI))
  ;;-----------------------------------------
  (DEFUN _stringprintable-p (arg)
    (AND (= (TYPE arg) 'str)
         (/= 0 (STRLEN arg))
         (/= 0 (STRLEN (VL-STRING-TRIM " " arg)))
    )
  )
  ;;-----------------------------------------
  (DEFUN _settextangle (ang)
    (IF (AND (> ang (_dtr 105)) (<= ang (_dtr 285)))
      (- ang PI)
      ang
    )
  )
  ;;-----------------------------------------
  (DEFUN _drawtext (selectionpoint rotationangle /)
    (COMMAND "text"
             "j"
             "m"
             selectionpoint
             ""
             (_rtd (_settextangle rotationangle))
             textstring
    )
    (ENTLAST)
  )
  ;;-----------------------------------------
  (DEFUN _textinline (selectedent selectionpoint / textent)
    (IF (SETQ textent (_drawtext
                        selectionpoint
                        (ANGLE selectionpoint
                               (OSNAP selectionpoint "end")
                        )
                      )
        )
      (_trimfortext textent selectedent)
    )
  )
  ;;-----------------------------------------
  (DEFUN _textincircle
         (selectedent selectionpoint / textent)
    (IF (SETQ
          textent (_drawtext
                    selectionpoint
                    (+ (ANGLE (OSNAP selectionpoint "cen")
                              selectionpoint
                       )
                       (* PI 0.5)
                    )
                  )
        )
      (_trimfortext textent selectedent)
    )
  )
  ;;-----------------------------------------
  (DEFUN _trimfortext (textent selectedent /)
    (COMMAND "trim" textent "" selectedent "")
  )
  ;;-----------------------------------------
  ;;
  ;; Main ... 
  ;;
  (WHILE (NOT (_stringprintable-p textstring))
    (SETQ textstring
           (GETSTRING
             T
             "\n(Press 'Esc' to cancel) Enter Label: "
           )
    )
  )
  (WHILE (SETQ selectedent
                (ENTSEL
                  "\n(Press 'Esc' to cancel) What do you want to label?"
                )
         )
    ;;
    (SETQ selectionpoint (OSNAP (CADR selectedent) "nea")
          etype          (CDR (ASSOC 0 (ENTGET (CAR selectedent))))
    )
    (COND ((MEMBER etype '("LINE" "LWPOLYLINE"))
           (_textinline selectedent selectionpoint)
          )
          ((MEMBER etype '("ARC" "CIRCLE"))
           (_textincircle selectedent selectionpoint)
          )
          (T
           (ALERT "Must Select ARC CIRCLE POLYLINE or LINE")
          )
    )
  )
  ;;-----------------------------------------
  ;;  (end)
  (PRINC)
)
(PROMPT "\n command-line >>  TextInline ")
(PRINC)
« Last Edit: August 18, 2006, 09:49:30 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Specific drawing files causing lisp routine to fail?
« Reply #10 on: August 19, 2006, 04:25:38 AM »
Kerry, good job keepin' on answering posts.... :-)

As for this one, it appears that this same question was asked on the Adesk forum under the name CCMoor on Friday. I responded to that question at the same time the one was posted here. They have not yet responded.....

What I found was that the routine works (once the lines referencing unknown funtions are removed) in drawings with a current textstyle of 0 height, but fails in those with a set height. All due to the TEXT command acting differently based on the height, or lack thereof.

Have a good weekend!
Jeff

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #11 on: August 19, 2006, 04:56:05 AM »
I'm not working today Jeff, so had a little spare time ..

TextHeight non zero < or somesuch> is what I imagined Jeff ..  thats why I asked for the setup routine and drawing etc.

There is a lesson here for anyone asking questions .. do not assume that what you post holds the answer to the problem ... and be as descriptive of the actual problem as possible.

kwb
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

KewlToyZ

  • Guest
Re: Specific drawing files causing lisp routine to fail?
« Reply #12 on: August 19, 2006, 12:44:20 PM »
Wow you guys never cease to amaze me with the attention to posts here!
I am home doing the domestic stuff.
Just reading through the posts trying to digest everything and respond.
I've been working long hours all week and the missus is going to beat me if she catches me on the PC lol.

A very gracious thank you for the assistance.
I'll get this all together monday when my honey do list isn't nagging  :lol:

KewlToyZ

  • Guest
Re: Specific drawing files causing lisp routine to fail?
« Reply #13 on: August 19, 2006, 02:32:29 PM »
I couldn't wait I had to try this example you offered out.
Nice exit I need to start applying myself to structuring better.
I am going to bind this drawing and post a zip here because the code works great but does the exact same thing in these project files.
It is rather baffling for me what is causing the code to deviate from its normal progress.
All I did below was run the routine and enter a two letter label the rest it did on its own.

Command: textinline

(Press 'Esc' to cancel) Enter Label: CW

(Press 'Esc' to cancel) What do you want to label?text
Current text style:  "Standard"  Text height:  0'-4 1/2"
Specify start point of text or [Justify/Style]: j Enter an option
[Align/Fit/Center/Middle/Right/TL/TC/TR/ML/MC/MR/BL/BC/BR]: m
Specify middle point of text:
Specify rotation angle of text <0.0000>:
Enter text: 0.000000000000000
Command: CW Unknown command "CW".  Press F1 for help.

Command: trim
Current settings: Projection=UCS, Edge=None
Select cutting edges ...
Select objects or <select all>:   1 found

Select objects:
Select object to trim or shift-select to extend or
[Fence/Crossing/Project/Edge/eRase/Undo]:
Select object to trim or shift-select to extend or
[Fence/Crossing/Project/Edge/eRase/Undo]:
Command:
(Press 'Esc' to cancel) What do you want to label?*Cancel*

KewlToyZ

  • Guest
Re: Specific drawing files causing lisp routine to fail?
« Reply #14 on: August 19, 2006, 02:45:08 PM »
OK here is the LRS routine as well from the earlier questions.
It's just an NCS layer creation script.

I'm in process of learning Architectural Building Systems for setting up with this company too.
The nice thing is most of their lisp routines are replaced by the ABS smart objects.
But I am still curious what objects in this drawing is causing command structure failures.
Not to mention it is nice to get feedback from people who seem a hell of a lot more versed with AutoCAD coding than I have been