Author Topic: Automatic writing of street names with justification  (Read 981 times)

0 Members and 1 Guest are viewing this topic.

fabcad

  • Newt
  • Posts: 43
Automatic writing of street names with justification
« on: April 07, 2022, 03:50:28 AM »
Hello fellow lispers,

I am trying to create a routine which allows to create street names in Mtext objects according to a choice of 3 solutions.

1- Select the reference text to be multiplied.

2- Select the linear (PLINE or LINE) serving as a reference for the creation.

3- Creation of the textual Mtexts according to the chosen solution.

I have a question when the start and end points are reversed when creating the line or pline for the correct justification of the street Mtexts.

Attached is a screenshot and my almost finished routine.

Thank you in advance,

Fabcad Le Rennais Métropolitain
« Last Edit: April 08, 2022, 10:11:21 AM by fabcad »

mhupp

  • Bull Frog
  • Posts: 250
Re: Automatic writing of street names with justification
« Reply #1 on: April 08, 2022, 10:26:49 AM »
Assumes mtext is one line. that you are picking a line or polyline with only two points.
Change the Cond to match the spacing you want.  Right now its set to.
 
middle label only if line is 3.5 or less times longer then the street name
Code - Auto/Visual Lisp: [Select]
  1. ((<= dist (* TW 3.5))
ends labels only if line is between 3.5 and 5.5 times longer then street name
Code - Auto/Visual Lisp: [Select]
  1. ((<= dist (* TW 5.5))
all lables if line is greater than 5.5 times longer than street name
Code - Auto/Visual Lisp: [Select]
  1. ((> dist (* TW 5.5))

Code - Auto/Visual Lisp: [Select]
  1. (defun C:Street (/ name typ ent Street TW OBJ PT1 PT2 MPT dist ang x y)
  2.   (if (and (setq name (car (entsel "\nSelect Street name")))
  3.            (member (setq typ (cdr (assoc 0 (setq ent (entget name)))))
  4.                 '( "TEXT" "MTEXT")
  5.            )
  6.       )
  7.         (progn
  8.           (setq Street (cdr (assoc 1 ent)))
  9.           (setq TS (cdr (assoc 40 ent)))
  10.           (if (= typ "TEXT")
  11.             (setq TW (apply '- (reverse (mapcar 'car (textbox ent)))))
  12.             (setq TW (cdr (assoc 42 ent)))
  13.           )
  14.         )
  15.   )  
  16.   (if (setq OBJ (car (entsel "\nSelect line")))
  17.     (progn
  18.       (setq PT1 (vlax-curve-getStartPoint OBJ)
  19.             PT2 (vlax-curve-getendpoint OBJ)
  20.             MPT (mapcar '/ (mapcar '+ PT1 PT2) '(2 2 2))
  21.             dist (distance PT1 PT2)
  22.       )
  23.       (if (< (car PT1) (car PT2))
  24.         (setq ang (angle PT1 PT2)
  25.               x PT1
  26.               y PT2
  27.         )
  28.         (setq ang (angle PT2 PT1)
  29.               x PT2
  30.               y PT1
  31.         )
  32.       )
  33.     )
  34.   )
  35.   (cond
  36.     ((<= dist (* TW 3.5))
  37.       (entmake (list (cons 0 "TEXT")
  38.                      (cons 10 MPT)
  39.                      (cons 11 MPT)
  40.                      (cons 40 TS)
  41.                      (cons 1 STREET)
  42.                      (cons 50 ang)
  43.                      (cons 72  1)
  44.                      (cons 73  2)                    
  45.                )
  46.       )
  47.     )
  48.     ((<= dist (* TW 5.5))
  49.       (entmake (list (cons 0 "TEXT")
  50.                      (cons 10 x)
  51.                      (cons 11 x)
  52.                      (cons 40 TS)
  53.                      (cons 1 STREET)
  54.                      (cons 50 ang)
  55.                      (cons 72  0)
  56.                      (cons 73  2)                    
  57.                )
  58.       )
  59.       (entmake (list (cons 0 "TEXT")
  60.                      (cons 10 y)
  61.                      (cons 11 y)
  62.                      (cons 40 TS)
  63.                      (cons 1 STREET)
  64.                      (cons 50 ang)
  65.                      (cons 72  2)
  66.                      (cons 73  2)                    
  67.                )
  68.       )
  69.     )
  70.     ((> dist (* TW 5.5))
  71.       (entmake (list (cons 0 "TEXT")
  72.                      (cons 10 x)
  73.                      (cons 11 x)
  74.                      (cons 40 TS)
  75.                      (cons 1 STREET)
  76.                      (cons 50 ang)
  77.                      (cons 72  0)
  78.                      (cons 73  2)                    
  79.                )
  80.       )
  81.       (entmake (list (cons 0 "TEXT")
  82.                      (cons 10 y)
  83.                      (cons 11 y)
  84.                      (cons 40 TS)
  85.                      (cons 1 STREET)
  86.                      (cons 50 ang)
  87.                      (cons 72  2)
  88.                      (cons 73  2)                    
  89.                )
  90.       )
  91.       (entmake (list (cons 0 "TEXT")
  92.                      (cons 10 MPT)
  93.                      (cons 11 MPT)
  94.                      (cons 40 TS)
  95.                      (cons 1 STREET)
  96.                      (cons 50 ang)
  97.                      (cons 72  1)
  98.                      (cons 73  2)                    
  99.                )
  100.       )
  101.     )
  102.   )
  103.   (princ)
  104. )
« Last Edit: April 08, 2022, 02:13:14 PM by mhupp »

fabcad

  • Newt
  • Posts: 43
Re: Automatic writing of street names with justification
« Reply #2 on: April 08, 2022, 01:05:35 PM »
Thank you very much for your answer Mr. mhupp, very interesting as a method of approach.

I just have to dissect your program.

mhupp

  • Bull Frog
  • Posts: 250
Re: Automatic writing of street names with justification
« Reply #3 on: April 08, 2022, 02:13:50 PM »
Sorry updated the code so the text will be the same size as selected text.