Autolisp, editing existing code

Autolisp, editing existing code

bdemirQDGWN
Contributor Contributor
744 Views
6 Replies
Message 1 of 7

Autolisp, editing existing code

bdemirQDGWN
Contributor
Contributor

Hello friends, I developed a command (Down here) a long time ago with the help of friends here, but there are a few missing parts for it to work as we want. I would like the Text command to be 200 units. I also want the line drawn in the middle to work with the PL command because I want to be able to change the thickness of all lines. I want the global width of the rectangle and the middle line to be 50 mm. Finally, I want the text to be in the middle of the line, framed as in the example, and brought to the front using the draworder command. Thank you so much...🙂

 

 

(defun c:wapeningstype ()

  (setq startPoint (getpoint "\nSelect the first point of the rectangle: "))                                            ; Prompt the user to select the first point of the rectangle

  (setq endPoint (getcorner startPoint "\nSelect the other corner of the rectangle: ")) ; Prompt the user to select the other corner of the rectangle

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

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

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

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

  (command "_.LINE" lowerLeftCorner upperRightCorner "")                                                                                                                 ; Create a line from the lower-left corner to the upper-right corner

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

                                                                                                                                                                                                                                                                                                                                                          ; Calculate the midpoint of the line

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

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

  ; Add an MTEXT (multiline text) containing the user-entered information to the middle of the line

;  (command "_.MTEXT" lineMidPoint "@1.0,1.0" userInput "") ; opposite corner changed to relative to the first corner.

  (vla-put-color

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

                                                                 (vlax-3d-point lineMidPoint)

                                                                  0

                                                                  userInput

                )

                1

  )

  (vla-put-height (vlax-ename->vla-object (entlast)) 160)

  ; End the function

  (princ)

)

0 Likes
Accepted solutions (1)
745 Views
6 Replies
Replies (6)
Message 2 of 7

bdemirQDGWN
Contributor
Contributor

ive edit some of my questions, now i only have to make the global width 50 mm.

 

(defun c:wapeningstype ()
(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)
)

0 Likes
Message 3 of 7

David_W_Koch
Mentor
Mentor
(command "_.PLINEWID" "50")

 

The above will set the global width of subsequently created polylines to 50 units.


David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
EESignature

0 Likes
Message 4 of 7

bdemirQDGWN
Contributor
Contributor

THANK YOUUUU!

IS IT POSSIBLE TO DO THE SAME FOR RECTANGLE?

0 Likes
Message 5 of 7

bdemirQDGWN
Contributor
Contributor

its only the pline the becomes 50 mm thick

0 Likes
Message 6 of 7

David_W_Koch
Mentor
Mentor
Accepted solution

It appears that the RECTANG command does not respect the setting for PLINEWID, but does maintain its own Width value.  I was not able to find a System Variable for that.  It does not carry across already open drawings; I do not know if the value is saved with a drawing or if it resets to default (0) when opening a file.

 

That said, the following will force a width of 50.

 

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

 

The command function in AutoLISP simply feeds things to the command line.  If you know the keystrokes you would use when running the command live, you know what to write in AutoLISP.  Enclose input in double quotes.  There is an implied ENTER at the end of a quoted string.  If you need to press ENTER a second time after some input, provide a null string: "".


David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
EESignature

0 Likes
Message 7 of 7

bdemirQDGWN
Contributor
Contributor

Hey David, this is indeed what i need. thanks a lot! You were very helpfull🙂

0 Likes