Jump to content

Recommended Posts

Posted (edited)

Hello friends, Could you please add the code that centers the input information (mtext) from the keyboard in the code below? Like middle centre of mtext at the accrossing line cause now it is automaticallt top left.

 

(defun c:wapeningstype ()

  (command "_.RECTANG" "_W" "50" startPoint endPoint)

  (setq startPoint (getpoint "\nSelect the first point of the rectangle: "))

  (setq endPoint (getcorner startPoint "\nSelect the other corner of the rectangle: "))



  ; Create a rectangle using the selected points

  (command "_.RECTANGLE" startPoint endPoint)



  ; Set color of the rectangle to color 1

  (vla-put-color (vlax-ename->vla-object (entlast)) 1)



  ; Get the corners of the rectangle

  (setq lowerLeftCorner startPoint)

  (setq upperRightCorner endPoint)



  ; Create a polyline from the corners of the rectangle

  (command "_.PLINE" lowerLeftCorner upperRightCorner "")



  ; Set color of the polyline to color 1

  (vla-put-color (vlax-ename->vla-object (entlast)) 1)



  ; Calculate the midpoint of the polyline

  (setq polylineMidPoint (polar lowerLeftCorner (angle lowerLeftCorner upperRightCorner) (/ (distance lowerLeftCorner upperRightCorner) 2.0)))



  ; Prompt the user to enter information

  (setq userInput (getstring "\nEnter the information: "))



  ; Add MTEXT at the midpoint of the polyline with the user-entered information

  (setq mtextObj

    (vla-addmtext

      (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))

      (vlax-3d-point polylineMidPoint)

      0

      userInput

    )

  )



  ; Set height of the MTEXT to 200 units

  (vla-put-height mtextObj 200)



  ; Set MTEXT background fill and border

  (vla-put-backgroundfill mtextObj :vlax-true) ; Enable background fill

  (vla-put-borderstyle mtextObj 1)             ; Set border style (1 for a frame)

  (vla-put-bordercolor mtextObj 1)             ; Set the border color to color 1

  (vla-put-borderwidth mtextObj 2.0)           ; Set the border width



  ; End the function

  (princ)

)

Schermopname (86).png

Edited by SLW210
Added Code Tags!
Posted

Please use Code Tags in the future. (use the <> in the Editor Toolbar)

Posted

Hello Beyza, welcome in the forum!

I tried to run the program you posted, but it ends with an error, it says " no function definition: VLA-PUT-BORDERSTYLE"

I won't start debugging the code, but if you wish to change the justification of an Mtext, insert this code right after the creation of that Mtext

(entmod (setq el (entget (entlast)) el (subst '(71 . 5) (assoc 71 el) el)))

 

Posted

I'd be tempted to create the mtext using entmake or entmakex, looks like you are creating mtext and then modifying it - entmake should let you do all of that in one step.

 

If you create an mtext set with the colours, background and so on that you want to use and use (entget(car(Entsel))) this will give you the dxf codes to entmake the text, background masks need 90, 63, 45, and 441 in addition to the usual formatting

Posted (edited)

I'd have to do some reading how to add a mtext border, not sure if it is part of the text definition or needs to be a separate entity

 

(defun c:wapeningstype ()
  (command "_.RECTANG" "_W" "50" startPoint endPoint)
  (setq startPoint (getpoint "\nSelect the first point of the rectangle: "))
  (setq endPoint (getcorner startPoint "\nSelect the other corner of the rectangle: "))

  ; Create a rectangle using the selected points
  (command "_.RECTANGLE" startPoint endPoint)

  ; Set color of the rectangle to color 1
  (vla-put-color (vlax-ename->vla-object (entlast)) 1)

  ; Get the corners of the rectangle
  (setq lowerLeftCorner startPoint)
  (setq upperRightCorner endPoint)


  ; Create a polyline from the corners of the rectangle
  (command "_.PLINE" lowerLeftCorner upperRightCorner "")


  ; Set color of the polyline to color 1
  (vla-put-color (vlax-ename->vla-object (entlast)) 1)

  ; Calculate the midpoint of the polyline
  (setq polylineMidPoint (polar lowerLeftCorner (angle lowerLeftCorner upperRightCorner) (/ (distance lowerLeftCorner upperRightCorner) 2.0)))

  ; Prompt the user to enter information
  (setq userInput (getstring "\nEnter the information: "))

   (entmakex (list
     (cons 0   "MTEXT")         
     (cons 100 "AcDbEntity")          
     (cons 100 "AcDbMText")    
     (cons 10 polylineMidPoint)
     (cons 40 200) 
     (cons 71 5)
     (cons 72 5)
     (cons 1 userInput)
     (cons 73 1)
     (cons 90 17) 
     (cons 63 1) 
     (cons 45 1) 
     (cons 441 0) 
  ))

;  ; Set MTEXT background fill and border
;  (vla-put-borderstyle mtextObj 1)             ; Set border style (1 for a frame)
;  (vla-put-bordercolor mtextObj 1)             ; Set the border color to color 1
;  (vla-put-borderwidth mtextObj 2.0)           ; Set the border width
;
  ; End the function
  (princ)
)

 

Edited by Steven P

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...