Jump to content

Recommended Posts

Posted

Hello good afternoon,


First of all, I apologize but I don't have any kind of training in programming and I try to get by with the tools I have at my disposal (forums, YouTube, AI,...)

 

I am a topographic engineer and I needed a lisp that would draw the grid the way I wanted, I have already developed much of it using the methods mentioned above but now I am stuck in creating the coordinate text. According to my analysis, it must be the justification of the text, I say this because even doing an isolated test on the creation of the text (entmake) the justification remains by default.

 

The following image is a representation of the final result.

imagem.thumb.png.f38d8adba6592a31ed704ca67987bcff.png

 

I'll leave my humble lines of code attached so that a kind soul can help me :D

Thank you for taking the time to read the post

 

 

Grid__.lsp

Posted (edited)

Hi Gaudencio,

 

I looked up in your "Grid__.lsp" and there is few things:

 

- in my opinion I would exclude it 72 and 73 codes in "create-text" subfunction, because of this: If group 72 and/or 73 values are nonzero, then the first alignment point values are ignored and AutoCAD calculates new values based on the second alignment point and the length and height of the text string itself (after applying the text style). If the 72 and 73 values are zero or missing, then the second alignment point is meaningless. (https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-62E5383D-8A14-47B4-BFC4-35824CAE8363). If you leave the 72 and 73 codes, then you need to calculate a "good" second alignment point and include of (cons 11 "second points") in "create-text" subfunction.

 

- so, when 72 and 73 code are excluded, the "create-text" subfunction will look this: 

 

(defun create-text (pos height rotation content)
    (entmake (list (cons 0 "TEXT")
                   (cons 8 *layer*) ; Define the layer
                   (cons 10 pos) ; Text position
                   (cons 40 height) ; Text height
                   (cons 50 rotation) ; Text rotation
                   (cons 1 content) ; Text content
           ))
  )

 

- and then will look like this for creating a text (for rotation you need to define a rotation in radians, otherwise you need to create a subfunction to convert deegres in radians)

 

;; Draw the coordinate text in the corners
  ;; Bottom-left corner
  (create-text (list (+ minx 2) (+ miny 0.5)) text-size 0 (format-text-x minx)) ; X coordinate (Bottom Left)
  (create-text (list (+ minx 0.5) (+ miny 2)) text-size (/ pi 2) (format-text-y miny)) ; Y coordinate (Top Left)

  ;; Bottom-right corner
  (create-text (list (- maxx 2) (+ miny 0.5)) text-size 0 (format-text-x maxx)) ; X coordinate (Bottom Right)
  (create-text (list (- maxx 0.5) (+ miny 2)) text-size (/ pi 2) (format-text-y miny)) ; Y coordinate (Top Right)

  ;; Top-right corner
  (create-text (list (- maxx 2) (- maxy 0.5)) text-size 0 (format-text-x maxx)) ; X coordinate (Top Right)
  (create-text (list (- maxx 0.5) (- maxy 2)) text-size (+ pi (/ pi 2)) (format-text-y maxy)) ; Y coordinate (Top Right)

  ;; Top-left corner
  (create-text (list (+ minx 2) (- maxy 0.5)) text-size 0 (format-text-x minx)) ; X coordinate (Top Left)
  (create-text (list (+ minx 0.5) (- maxy 2)) text-size (+ pi (/ pi 2)) (format-text-y maxy)) ; Y coordinate (Top Left)

 

For improvement of code, try to play with length of string to calculate a "good" positon of X and Y inside of grid based on variables "minx, maxx, miny and maxy". This will replace a "justification" of the text.

 

Best regards.

Edited by Saxlle
Posted (edited)

I have another it draws grids in layout paperspace by picking a view port. It includes drawing the grids on rotated views. Let me know if interested.

 

Have you looked at using just plain command as you can do the justification when adding the text. You are only drawing 8 text so will be instant. Example code.

(command "TEXT" "J" "BL" (getpoint "\nPick pt ") 2.5 90 (getstring "\nType text " T) )

 

image.thumb.png.f106473e8e0dc9d63a75be2e91402bc9.png

 

Edited by BIGAL
Posted
On 9/16/2024 at 2:28 AM, BIGAL said:

I have another it draws grids in layout paperspace by picking a view port. It includes drawing the grids on rotated views. Let me know if interested.

 

Have you looked at using just plain command as you can do the justification when adding the text. You are only drawing 8 text so will be instant. Example code.

(command "TEXT" "J" "BL" (getpoint "\nPick pt ") 2.5 90 (getstring "\nType text " T) )

 

image.thumb.png.f106473e8e0dc9d63a75be2e91402bc9.png

 

YES PLEASE SHARE THE LISP CODE; THANKS

Posted

Send me a PM and can talk more, without bloating the post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...