- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I have written this AutoLISP code, but when it tries to insert the text label at the end of the function, the text command fails return the error "._text Requires a numeric value"
(defun c:CreateAreaBlock (/ blkName num layerName pt1 pt2 midPt ent rect label)
; Check if a block with the given name exists
(defun blockExists (name)
(tblsearch "BLOCK" name)
)
; Check if a block with the given number exists
(defun blockWithNameExists (num)
(blockExists (strcat "Area-" (itoa num)))
)
; Set the layer name for the block
(setq layerName "TrafficAreas")
; Prompt the user to specify the rectangle's corners
(setq pt1 (getpoint "\nSpecify first corner of the rectangle: "))
(setq pt2 (getcorner pt1 "\nSpecify opposite corner of the rectangle: "))
(setq midPt (list (/ (+ (car pt1) (car pt2)) 2) (/ (+ (cadr pt1) (cadr pt2)) 2)))
; Create the rectangle using the command function
(command "._rectang" pt1 pt2)
(princ "\nCreated rectangle\n")
(command "")
; Get the rectangle entity
(setq ent (entlast))
; Prompt the user to specify the block number
(setq num nil blkName nil)
(while (or (not num) (blockWithNameExists num))
(setq num (getint "\nInsert a number for the area block: "))
(if (and num (blockWithNameExists num))
(alert "Error: Block with the same number already exists.")
)
)
; Set the block name based on the block number
(setq blkName (strcat "Area-" (itoa num)))
; Create a layer for the block and make it current
(command "_-layer" "_make" layerName "_on" layerName)
(command "")
; Create the block using the rectangle entity
(command "._-block" blkName midPt ent)
(command "")
(princ "\nCreated block\n")
; Delete the rectangle
(entdel ent)
(entdel ent)
; Insert the block at the midpoint of the rectangle
(command "_-insert" blkName midPt)
(command "")
(princ "\nInserted block\n")
; Insert a label in the midpoint of the block
(setq labelText blkName)
(setq labelHeight 200.0)
(setq rotation 0)
; Set the first point to the midpoint
(setq firstPt midpt)
; Create the single-line text using the "._text" command
(command "._text" firstPt labelHeight labelText)
; Return control to user
(princ)
)
what am I missing?
regards
Solved! Go to Solution.