Author Topic: Specific drawing files causing lisp routine to fail?  (Read 8054 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: 4087
  • 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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Specific drawing files causing lisp routine to fail?
« Reply #15 on: August 19, 2006, 02:51:47 PM »
Just looking at the code the problem would appear to be in the _drawtext function. It needs to behave (feed instructions to the text command) according to the textsize for the active style (0 and not 0); it currently doesn't. Do want one possible solution or do you want to figure it out yourself?

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Specific drawing files causing lisp routine to fail?
« Reply #16 on: August 19, 2006, 03:40:51 PM »
I won't be around later so I don't want to leave you twistin' in the wind, here's one possible remedy :replace the _DrawText function in previous posts with the following (no offence to the fine work of prior posters is this thread) --

Code: [Select]
(defun _DrawText ( selectionPoint rotationAngle / elast result )

    ;;  If it were me I would make the (lexical) global
    ;;  variable 'textstring' an argument of the _DrawText
    ;;  function but I wanted to honour the function's
    ;;  signature as you had originally penned, lest calling
    ;;  code get a rake in the face. An aside, I'd make the
    ;;  text via entmake or vla-addtext but that's another
    ;;  story. Anyway ...

    (setq elast (entlast))
   
    (apply 'command   
        (append
            (list ".text" "_j" "_m" selectionPoint)
            (if
                (zerop
                    (cdr
                        (assoc 40
                            (tblsearch "style" 
                                (getvar "textstyle")
                            )
                        )
                    )
                    ;;  the activex route to same if you're
                    ;;  interested --
                    ;;
                    ;;  (vla-get-height
                    ;;      (vla-get-activetextstyle
                    ;;          (vla-get-activedocument
                    ;;              (vlax-get-acad-object)
                    ;;          )
                    ;;      )
                    ;;  )
                )
                ;;  we could use a space / carriage
                ;;  return but let's be explicit
                (list (getvar "textsize"))
            )
            (list rotationAngle textstring)
        )   
    )
   
    ;;  Caller should deal with a null result, which
    ;;  indicates the text entity was not created for
    ;;  some reason.

    (if (/= elast (setq result (entlast)))
        result
    )   
)

I didn't test the program greater so I don't know if it will actually remedy all the ills. Like I inferred earlier, it's just what lept off the page at me.
« Last Edit: August 19, 2006, 05:19:53 PM by MP »
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 #17 on: August 19, 2006, 05:34:11 PM »
Just to confirm the comments regarding textHeight ..

This is the result of a command call when using a textStyle which has height set to 0.0.
The command asks you to confirm the height, using the current global system variable "TEXTSIZE" as the default.
This is the way you called the text command in your original code, so you have included a "" after the insertion point prompt to accept the offered default.
Quote
Command: text
Current text style:  "NORMAL"  Text height:  50.00
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 height <35.00>:

Specify rotation angle of text <0.000>:


Now if we change the TextStyle ...
Quote
Command: textstyle
Enter new value for TEXTSTYLE <"NORMAL">: T35



This is the result of a command call when using a textStyle which has height set to a value other than 0.
Notice that there is NO prompt for TextHeight ..
Quote
Command: text
Current text style:  "T35"  Text height:  35.00
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.000>:

It appears that the particular drawing you are running the code in has height set, while your "TEXT" command does NOT expect that to be the case.

You could use and build on Michaels excellent solution,
or ; ensure the correct text style is set prior to running your code
or ; set the style as part of the TEXT command code, ie
Code: [Select]
  ;;-----------------------------------------
  (DEFUN _drawtext (selectionpoint rotationangle /)
    (COMMAND "text"
             "Style"
             "MySuperDuperTextStyleWithZeroHeight"
             "j"
             "m"
             selectionpoint
             ""
             (_rtd (_settextangle rotationangle))
             textstring
    )
    (ENTLAST)
  )
  ;;-----------------------------------------

or ;

Code: [Select]
  ;;-----------------------------------------
  (DEFUN _drawtext (selectionpoint rotationangle /)
    (COMMAND "text"
             "Style"
             "MySuperDuperTextStyleWithFixedHeight"
             "j"
             "m"
             selectionpoint
             ;; "" <-- not needed in this case
             (_rtd (_settextangle rotationangle))
             textstring
    )
    (ENTLAST)
  )
  ;;-----------------------------------------

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 #18 on: August 21, 2006, 11:01:28 AM »
I won't be around later so I don't want to leave you twistin' in the wind, here's one possible remedy :replace the _DrawText function in previous posts with the following (no offence to the fine work of prior posters is this thread) --

I didn't test the program greater so I don't know if it will actually remedy all the ills. Like I inferred earlier, it's just what lept off the page at me.

Works flawlessly Kerry & MP many thanks!
Just trying to digest what you have shown me here.
I did not see the cause until you put my nose on it.
I was looking for something major in the drawing format itself. :ugly:

Do you guys have any AutoLISP books published?
Looking for some good reading to get past a script kitty mentality here.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Specific drawing files causing lisp routine to fail?
« Reply #19 on: August 21, 2006, 11:21:01 AM »
Works flawlessly Kerry & MP many thanks!

My pleasure. Kerry's too from his participation I'd say.

Do you guys have any AutoLISP books published?

Woo wee that's a good compliment but no, just what's here at the swamp and this (something I'm toying with).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

KewlToyZ

  • Guest
Re: Specific drawing files causing lisp routine to fail?
« Reply #20 on: August 24, 2006, 05:21:45 PM »
I have noticed a problem with the performance now.
The text is not in line with the lines it seems rotated at odd angles to the lines or arcs.

Just trying to interperet where you text angle indication and mine are differing,
but the approaches are so different it is taking some experimentation.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #21 on: August 24, 2006, 05:26:44 PM »
are you converting the radians to degrees ??
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 #22 on: August 24, 2006, 06:45:55 PM »
Right now I am just trying to get an idea from your DrawText where it is assigning the angle.
The previous method for the drawtext by Mike did follow the lines properly but did not allow for the text to have a style and height assigned.
Yours worked around the text height problem but I am missing where the angle or type of angle is assigned?
What throws me is you use list up to a point without setting the angle.
I tried to add into it but not having much luck, havent tried the active x version you placed into it.

MP's
Code: [Select]
(DEFUN _drawtext (selectionpoint rotationangle /)
  (COMMAND "text"
           "j"
           "m"
           selectionpoint
           ""
           (_rtd (_settextangle rotationangle))
           textstring
  )
  (ENTLAST)
)

Your DrawText:
Code: [Select]
(DEFUN _DrawText (selectionPoint rotationAngle / elast result)

    (setq elast (entlast))
   
    (apply 'command   
        (append
            (list ".text" "_j" "_m" selectionPoint)
            (if
                (zerop
                    (cdr
                        (assoc 40
                            (tblsearch "style" 
                                (getvar "textstyle")
                            )
                        )
                    )
                )
                (list (getvar "textsize"))
            )
            (list rotationAngle textstring)
        )   
    )
    ;;  Caller should deal with a null result, which
    ;;  indicates the text entity was not created for
    ;;  some reason.
    (if (/= elast (setq result (entlast)))
        result
    )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #23 on: August 24, 2006, 07:15:38 PM »
You'd better get your author references correct ... MP's code is much nicer than mine .. :lol:
....
MP's
Code: [Select]
(DEFUN _drawtext (selectionpoint rotationangle /)
;;..
 

Your DrawText:
Code: [Select]
(DEFUN _DrawText (selectionPoint rotationAngle / elast result)
;;...
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 #24 on: August 24, 2006, 07:16:32 PM »
are you converting the radians to degrees ??

... and you didn't answer the question ..
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 #25 on: August 24, 2006, 07:22:57 PM »
lol my bad, thats just it I can't figure out where to call _settextangle then _rtd to use the conversions.

I keep trying to form it into the list routine which doesn't seem right but it seems to be where the action takes place?
« Last Edit: August 24, 2006, 07:25:53 PM by KewlToyZ »

KewlToyZ

  • Guest
Re: Specific drawing files causing lisp routine to fail?
« Reply #26 on: August 24, 2006, 07:30:36 PM »
_DrawText
went over my head to put it lightly  :-o

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #27 on: August 24, 2006, 07:34:41 PM »
post the DRAWTEXT routine you are trying to use ..

and what are you passing to it

is it
a STRING and a REAL for the  radian angle value ?
or
a STRING and a REAL for the  degrees angle value ?
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 #28 on: August 24, 2006, 08:06:35 PM »
Just the code posted. Trying to digest the notes.
There is no reference in this itself to either _rtd = Radians 2 Degrees nor _dtr.
Trying to follow the "apply 'command" through it's steps to call for the two functions determining the rotation.

Code: [Select]
(DEFUN _DrawText (selectionPoint rotationAngle / elast result)

    (setq elast (entlast))
   
    (apply 'command   
        (append
            (list ".text" "_j" "_m" selectionPoint)                                            ;; begins the sequence
            (if (zerop (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))))    ;; from here this is checking the text height for zero?
                (list (getvar "textsize"))
            )  
          (list rotationAngle textstring)
        )   
    )
    (if (/= elast (setq result (entlast))) result)
   (ENTLAST)
)

So far I think I see it listing the real without using it as a string?
I'm running out of gas here. I'll pick up in the morning and see if I can get this through my knot head  :lol:
« Last Edit: August 24, 2006, 08:08:24 PM by KewlToyZ »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Specific drawing files causing lisp routine to fail?
« Reply #29 on: August 24, 2006, 10:37:06 PM »
OK, I'l' try another tack ..

When you call that _DrawText routine, what values are you passing to it ?

is the rotation angle value still in radians ?

if so ,

you could try something like this ;

(_DrawText  TextInsertPoint (_rtd (_settextangle Textangle)) )

which will pass a degree value to the  (_DrawText routine   which I think is what you want.



Just a note.
Some of us sometimes ask question to help with responding to the original or subsequent posts. If you dont understand the questions, please say so, 'cause usually a solution depends on your answers.


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.

nivuahc

  • Guest
Re: Specific drawing files causing lisp routine to fail?
« Reply #30 on: August 25, 2006, 08:34:39 AM »
I'm running out of gas here. I'll pick up in the morning and see if I can get this through my knot head 

Just a note.
Some of us sometimes ask question to help with responding to the original or subsequent posts. If you dont understand the questions, please say so, 'cause usually a solution depends on your answers.

Please, everyone, listen to that advice. There is a wealth of knowledge being offered throughout this entire forum from the likes of Kerry and MP (among many, many others). You would be doing yourself a great disservice if you missed out on it by being afraid to say "I don't understand".

Too many times I've seen the original poster get frustrated and give up because it was obvious that the responses were over their heads. And, likewise, the people offering their help (free of charge, I might add) sometimes get frustrated because the questions they ask never get answered and it's almost as if they are being ignored by the very person they are trying to help.

If someone is trying to help you out, and they ask you a question, take the time to try your best at answering them. Like Kerry says, if you don't understand the question or the supplied information is over your head, say so. It will make things much easier for you in the long run, and it will make it a more pleasurable experience for the people trying to help you out.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Specific drawing files causing lisp routine to fail?
« Reply #31 on: August 25, 2006, 09:05:05 AM »
Well said nivuahc!

Here is the simple routine I often use to place text.

Code: [Select]
(defun _drawtext (txt txtjust txtpt txtang)
  ;; If text height is undefined (signified by 0 in the table)
  (if (= (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
    ;; Draw the text using the current text height (textsize)
    (command "._text" "_J" txtjust txtpt "" txtang txt)
    ;; Otherwise use the defined text height
    (command "._text" "_J" txtjust txtpt txtang txt)
  ) ; endif
)

(defun c:test ()
  (defun rtd (r) (* 180.0 (/ r pi)))

  (and
    (setq mytext (getstring t "\nEnter text: "))
    (setq textpoint (getpoint "\nSelect text point."))
    (setq textangle (rtd 0.785398)) ; 45 degrees
    (_drawtext mytext "_m" textpoint textangle)
  )
  (princ)
)
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.

KewlToyZ

  • Guest
Re: Specific drawing files causing lisp routine to fail?
« Reply #32 on: August 25, 2006, 10:12:34 AM »
Thanks Kerry!
My thing is I am trying to learn new ways to accomplish things so I am willing to struggle a bit to find the answer.
I didn't intend to be difficult for you. Especially when you are so graciously trying to help  :-)

Trust me I'm not afraid to say I don't have a clue :ugly:

I truly do appreciate the help I've gotten from this forum. Kerry, MP, CAB and many others have posted some extremely insightful articles here.

The normal working conditions of our drawing environment is using degrees.
What had me hung up on the question was to remember if I do have the drawing set to degrees in units,
Do I still need to convert with radians for the autocad api?
The other was the bulk of the routine written here on this forum by Kerry,
while being compartmentalized was in form much more advanced in its approach than I can interperet so I appreciate Kerry trying to lead me through it to find my own answers.
My conditional handling leaves a lot to be desired albeit non-existent lol.

« Last Edit: August 25, 2006, 10:14:19 AM by KewlToyZ »