Author Topic: Problem with line break  (Read 1886 times)

0 Members and 1 Guest are viewing this topic.

engineer

  • Guest
Problem with line break
« on: September 02, 2013, 05:45:24 PM »
Hi everyone,
Can you, please, help me with the LISP I created for line breaking with text separated by pre-determined distances.
When I indicate breaking distance "BREAKDIST" by 2 points, the LISP works fine. But when I ask to type the distance on keyboard, the program halts after the first break.
Greatly will appreciate for any suggestions.

hmspe

  • Bull Frog
  • Posts: 367
Re: Problem with line break
« Reply #1 on: September 02, 2013, 06:34:40 PM »
A few thoughts:

There is no reason to use short variable names with modern computers.  Your code would be much easier to figure out if the variable names were more descriptive.

DXF code 11 for text does not give the right end of the string unless you change the justification to RIGHT.   You need to use something like TEXTBOX.
"Science is the belief in the ignorance of experts." - Richard Feynman

ymg

  • Guest
Re: Problem with line break
« Reply #2 on: September 02, 2013, 08:59:19 PM »
Change the following line:

Code: [Select]
(command "BREAK" PT1 "F" PT1 PT2)
instead of:

Code: [Select]
(command "BREAK" PT1  PT2)
You should consider MTEXT with a mask instead of breaking your LINES.


ymg

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Problem with line break
« Reply #3 on: September 03, 2013, 08:54:22 AM »
If I understand your basic concept correctly, I think I would go with ( entmake ) calls and text FIT justification

Code - Auto/Visual Lisp: [Select]
  1. (defun c:DB:txtline (/ en ss txt dis tht ed spc
  2.                        p1 p2 pc p3 p4 p10 p11)
  3.  
  4.   (princ "\nSelect 1 Line To Add Text To")
  5.   (while (not en)
  6.          (setq ss (ssget '((0 . "LINE"))))
  7.          (and (= (sslength ss) 1)
  8.               (setq en (ssname ss 0))))
  9.  
  10.   (setq txt (getstring t "\nText to Insert:   "))
  11.  
  12.   (initget 7)
  13.   (setq dis (getdist "\nBreak Distance:   "))
  14.  
  15.   (setq tht (getvar "TEXTSIZE"))
  16.  
  17.   (setq spc 1.0)   ;;;SPACE FROM LINE BREAK PT TO TEXT
  18.  
  19.   (setq ed (entget en)
  20.         p1 (cdr (assoc 10 ed))
  21.         p4 (cdr (assoc 11 ed))
  22.         pc (polar p1 (angle p1 p4) (* (distance p1 p4) 0.5))
  23.         p2 (polar pc (angle p4 p1) (* dis 0.5))
  24.         p3 (polar pc (angle p1 p4) (* dis 0.5))
  25.         p10 (polar p2 (angle p2 p3) spc)
  26.         p11 (polar p3 (angle p3 p2) spc)
  27.         )
  28.  
  29.   (entdel en)
  30.  
  31.   (entmake (list (cons 0 "LINE")
  32.                  (assoc 8 ed)
  33.                  (cons 10 p1)
  34.                  (cons 11 p2)
  35.                  (if (assoc  6 ed) (assoc  6 ed) '(6 . "BYLAYER"))
  36.                  (if (assoc 39 ed) (assoc 39 ed) '(39 . 0))
  37.                  (if (assoc 26 ed) (assoc 62 ed) '(62 . 256))
  38.                  (assoc 210 ed)))
  39.   (entmake (list (cons 0 "LINE")
  40.                  (assoc 8 ed)
  41.                  (cons 10 p4)
  42.                  (cons 11 p3)
  43.                  (if (assoc  6 ed) (assoc  6 ed) '(6 . "BYLAYER"))
  44.                  (if (assoc 39 ed) (assoc 39 ed) '(39 . 0))
  45.                  (if (assoc 26 ed) (assoc 62 ed) '(62 . 256))
  46.                  (assoc 210 ed)))
  47.   (entmake (list (cons 0 "TEXT")
  48.                  (cons 1 txt)
  49.                  (cons 6 "CONTINUOUS")
  50.                  (cons 7 (getvar "TEXTSTYLE"))
  51.                  (assoc 8 ed)
  52.                  (cons 10 (polar p10 (+ (angle p1 p4) (* pi -0.5)) (* tht 0.5)))
  53.                  (cons 11 (polar p11 (+ (angle p1 p4) (* pi -0.5)) (* tht 0.5)))
  54.                  (cons 39 1e-8)
  55.                  (cons 40 tht)
  56.                  (cons 41 1.0)
  57.                  (cons 50 0.0)
  58.                  (cons 51 0.0)
  59.                  (if (assoc 26 ed) (assoc 62 ed) '(62 . 256))
  60.                  (cons 71 0)
  61.                  (cons 72 5)
  62.                  (cons 73 0)
  63.                  (assoc 210 ed)))
  64.  

Depending om the setup, command line "_.BREAK" can can have errors on lines with large gaps it's LINETYPE

Depending the textstyle x_scale factor of the the style, you could have very long text strings boundaries

This would make is possible to ensure that the text is always displayed right to left or bottom to top, not just the direction of the line points

I added some my personal preferences ( text always has a bit if thickness, continuous linetype ).

-David


R12 Dos - A2K

engineer

  • Guest
Re: Problem with line break
« Reply #4 on: September 06, 2013, 06:36:52 PM »
Change the following line:

Code: [Select]
(command "BREAK" PT1 "F" PT1 PT2)
instead of:

Code: [Select]
(command "BREAK" PT1  PT2)
You should consider MTEXT with a mask instead of breaking your LINES.


ymg


Hi ymg, I have tried whatever you have proposed, but it still doesn't work. Even worse, usually it just said that it cannot find the object, now it in addition to the phrase sees "F" as "Fence"...

engineer

  • Guest
Re: Problem with line break
« Reply #5 on: September 06, 2013, 06:50:33 PM »
Hi David,
You have created a nice function, but it's not what I did. My intent is to break an existing line multiple times with the same text, aka similar to whatever is done by different linetypes (e.g. GAS, ZIGZAG, etc), but without dependance from LTSCALE, rotation, etc.
Anyway, thanks for the try.

ymg

  • Guest
Re: Problem with line break
« Reply #6 on: September 06, 2013, 10:16:07 PM »
Quote
Hi ymg, I have tried whatever you have proposed, but it still doesn't work.

I have just checked again and it would insert and break the line wheter you enter the distance at the keyboard or you pick the distance.
and here is your code modified exactly as I told you.  Only line 36. is changed.  So Cut&Paste and that should work.

Command: BREAK
Select object:
Specify second break point or [First point]: f

Specify first break point:
Specify second break point:

Above is the typical command prompt if you issue the command at the keyboard.

ymg

Code - Auto/Visual Lisp: [Select]
  1. (defun C:txtline()
  2.  (setq CMD-ECHO (getvar "cmdecho")
  3.        O-SMODE (getvar "osmode"))
  4.  (setvar "cmdecho" 0)
  5.  (setvar "osmode" 0)
  6.  
  7.  (setq PICK (entsel))
  8.  (setq BREAKTXT (getstring T "\nTYPE TEXT TO BE INSERTED: "))
  9.  (setq BREAKDIST (getdist "\nTYPE BREAKING DISTANCE: "))
  10.  (setq TXTHGT (getvar "TEXTSIZE"))
  11.  (if PICK
  12.      (progn
  13.        (setq PTL (cdr (assoc 10 (entget (car PICK)))))
  14.        (setq PTR (cdr (assoc 11 (entget (car PICK)))))
  15.        (setq ANG (angle PTL PTR))
  16.        (setq TDST (distance PTL PTR))
  17.  
  18.        (setq N (fix (/ TDST BREAKDIST)))
  19.        (setq DST (/ (- TDST (* N BREAKDIST)) 2.0))
  20.        (setq LEN (strlen BREAKTXT))
  21.        (setq BRKDST (* (* LEN 0.6) TXTHGT))
  22.  
  23.        (if (= LEN 1)
  24.            (setq BRKDST (* BRKDST 2.0))
  25.        )
  26.  
  27.        (if (< DST (* 2.0 BRKDST))
  28.            (setq DST (/ (- TDST (* (1- N) BREAKDIST)) 2.0))
  29.        )
  30.  
  31.        (while (< DST TDST)
  32.            (setq PT (polar PTL ANG DST)
  33.                  PT1 (polar PT ANG BRKDST)
  34.                  PT2 (polar PT (+ ANG PI) BRKDST)
  35.            )
  36.            (command "BREAK" pt1 "f" PT1 PT2)
  37.  
  38.            (command "TEXT" "MC" PT TXTHGT (* ANG (/ 180 pi)) BREAKTXT)
  39.  
  40.            (setq DST (+ DST BREAKDIST))
  41.        ); WHILE END
  42.     ); PROGN
  43.   ); IF END
  44.   (setvar "osmode" O-SMODE)
  45.   (setvar "cmdecho" CMD-ECHO)
  46. ); DEFUN END
  47.  
  48.  

ymg

  • Guest
Re: Problem with line break
« Reply #7 on: September 06, 2013, 11:09:05 PM »
Engineer,

I also tested David's routine from above and it works flawlessly, and indeed solves the problems that he mentionned about the BREAK command.

So you must be doing something wrong.

Again, I tell you it is a bad idea to break your line like that and end up with a multitude of small segments.

What happen if you need to move the line, that why they invented all those linetype.

The alternative with an MTEXT with a mask,  keeps the  lines complete,  but you are still stuck with that bunch of text objects.

ymg

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Problem with line break
« Reply #8 on: September 07, 2013, 09:05:13 AM »
Engineer,

It seems like you are looking for a non-lintype scale associated linetype.  Maybe you should be looking to utilize a different method of assigning the linetype scale so it works properly with you current drawing scale.  Then create the linetypes you need for the text portion (not that difficult).  You can create your own *.lin file and a way to access it, maybe a sub-menu item.  It is possible to call a DCL and have it populated by the linetypes in your *.lin file so you do not have to re-write the lsp file each time you create a new linetype.


David Bethel

  • Swamp Rat
  • Posts: 656
Re: Problem with line break
« Reply #9 on: September 07, 2013, 11:43:23 AM »
Your original post was not very clear as to your total concept.

To use some very old techniques of text masking, it requires SPLFRAME set to 0 and use Hide in plotting

Also, cross posting on Cadtutor isn't real good etiquette.  A lot of people are members of both.

Attached gives a lot of flexibility to piping labels.  -David
R12 Dos - A2K

engineer

  • Guest
Re: Problem with line break
« Reply #10 on: September 07, 2013, 07:01:44 PM »
THANKS EVERYONE FOR THE ADVICES!!! ^-^