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

0 Members and 3 Guests are viewing this topic.

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.