Jump to content

Need help with DTEXT Lisp routine. Thanks


tmelancon

Recommended Posts

Just need some help with a simple routine that I starting tweaking. Originally the routine was written to enter text and sized it based on the DIMSCALE. It also featured an option to type "A" after you typed DTEXT, to be able to add lines to the specific line of text selected.

 

The problem I am having is I am getting an error: bad argument type: numberp: "0.08". I need it to where is doesnt look at DIMSCALE anymore just the standard 0.1295 spacing. See code below.

 

(defun add-text ()
   (setq exist_text (entget (car (entsel "\nPick last line of Text: "))))
   (setq exist_just (cdr (assoc 72 exist_text))) 
   (cond
       ((= exist_just 0) (setq just "") (setq ins_pt (cdr (assoc 10 exist_text))))
       ((= exist_just 1) (setq just "c") (setq ins_pt (cdr (assoc 11 exist_text))))
       ((= exist_just 2) (setq just "r") (setq ins_pt (cdr (assoc 11 exist_text))))
       ((= exist_just 4) (setq just "m") (setq ins_pt (cdr (assoc 11 exist_text))))
       ((not exist_just) (setq just "") (setq ins_pt (cdr (assoc 10 exist_text))))
   )
   (setq text_pt (polar ins_pt (* 3 (/ pi 2)) (* 5 (/ t_size 3))))
)
;
;
(defun c:dt ()
   (setvar "cmdecho" 0)
   (setq t_size ".08")
   ;
   ; is text height = 0.0 for current style?   
   ; if not, change height to 0.0 and save current height  
   ;
   (setq ts (getvar "textstyle"))                   
   (setq style_info (tblsearch "style" ts))
   (setq th (assoc '40 style_info))
   (setq text_h (cdr th))
   (if (/= text_h 0.0)
       (command "style" ts "" 0.0 "" "" "" "" "")
   )
   ;
   ; change layer to predetermined text layer
   ;
   (setq c_layer (getvar "clayer"))
   (command "layer" "s" "TEXT" "")
   (princ)
   (setq just (getstring "\nJustification or <A>dd Text Under Existing Line of Text: "))
   (if (or (= just "a") (= just "A"))
       (add-text)
       (setq text_pt (getpoint "\nInsertion Point of Text"))
   )
   (princ "\nText:")
   (if (= just "")
       (command "dtext" text_pt t_size "0")
       (command "dtext" just text_pt t_size "0")
   )
   ;    
   ; return to original layer and text height values   
   ;
   (command "layer" "s" c_layer "")
   (if (/= text_h 0.0)
       (command "style" ts "" text_h "" "" "" "" "")
   )
)

Link to comment
Share on other sites

It's a pretty simple fix. You are currently trying to divide a string. If you are insistent on leaving the variable "t_size" as a string, then you have to convert it to a number before dividing it. Otherwise, I would just take the quotes away form ".08" and make it 0.08

 

 

Side note: Don't forget to change your variables back to the original configuration at the end of your code. You should probably also add an error function if your code ever crashes.

Link to comment
Share on other sites

Hmm for some reason I am noticing that the spacing of the "NEW" text (using the 'A' for add feature) is spacing out 0.1333, instead of 0.1295. Any reason why? I would like it to space 0.1295 just like normal. If there is someone who can make this code simpler if it is too complicated I would greatly appreciate it. It was adopted from my flash drive that I havent looked at in years.

Link to comment
Share on other sites

Also, if anyone can chime in. Some of my users that are using this routine, when they actually initiate the command they do not get this DTEXT function, instead they get the default DTEXT routine. Any ideas?

Link to comment
Share on other sites

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