Jump to content

Text edit lisp routine


jondoeiowa

Recommended Posts

Is it possible to write a lisp routine that will take a single line text and adjust it up or down digets? When I draft a line and tag is 10-0 I would like to be able to build a routine to go through the drawing click on the object and have it adjust down 2, making it 9-10. Anyone have some suggestions or idea if it is even possible?

Link to comment
Share on other sites

First, please ask a moderator to move your thread in the appropriate section. You issue will get more support there.

 

Second, what type of entity is that tag? You are talking about a text or a dimension?

 

Regards,

Mircea

Link to comment
Share on other sites

Your routine will be like:

 

;select entity to edit (ENTSEL)
;get the associated list of the entity (ENTGET)
;get the label content (ASSOC)
;convert that value to a double taking care of format (DISTOF)
;perform the math
;convert back the value to string taking care of format (RTOS)
;modify the associated list of the entity (SUBST)
;update the entity (ENTMOD)

 

Please try to follow the above scheme and ask where you have issues. Good luck!

 

Regards,

Mircea

Link to comment
Share on other sites

I guess you mean reversing string.

 

(defun c:TesT (/ ss sset lst e)
 ;; Tharwat 04. 08. 2011
 (prompt "\n Select Texts to reverse >> ...")
 (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
   (while
     (setq sset (ssname ss 0))
      (setq lst (vl-string->list (cdr (assoc 1 (setq e (entget sset))))))
      (entmod (subst (cons 1 (vl-list->string (reverse lst)))(assoc 1 e)  e ))
      (ssdel sset ss)
   )
   (princ)
 )
 (princ)
)

 

Tharwat

Link to comment
Share on other sites

I guess you mean reversing string.

 

Sorry @Tharwat, but seems to me that the OP isn’t looking for a reversing string routine.

 

Regards,

Mircea

Link to comment
Share on other sites

......When I draft a line and tag is 10-0 I would like to be able to build a routine to go through the drawing click on the object and have it adjust down 2, making it 9-10.

 

Are you saying "adjust it down" is 10-0 less 2 is 9-10. so 10-1 will be 9-11?, and if "up" 9-11 will be 10-1?

 

10-2 to 10-0? :unsure:

Link to comment
Share on other sites

@pBe: The OP is talking about imperial values: 10'-0" (10 feet, 11 inches) minus 2" (2 inches) will be 9'-10" (9 feet, 10 inches).

 

(rtos (- (distof "10'0\"" 4) (distof "2\"" 4)) 4)

 

(Or, maybe, I didn't understood your question?)

 

Regards,

Mircea

Link to comment
Share on other sites

@pBe: The OP is talking about imperial values: 10'-0" (10 feet, 11 inches) minus 2" (2 inches) will be 9'-10" (9 feet, 10 inches).

 

(rtos (- (distof "10'0\"" 4) (distof "2\"" 4)) 4)

 

(Or, maybe, I didn't understood your question?)

 

Regards,

Mircea

 

I guess you're right msasu.. thought it would be more complex than that like

sheet numbering, i.e. sheet number 9 of 10 sheets or 13 of 19... , so the first and second digits would vary greatly,

 

it would have been a fun code to write :)

 

EDIT:

Odd as it is, give this a try

 

(defun c:Addless ( / DoTheMath strs str j intval)
(defun AddSub (ent sym  num / strs g DoTheMath ft)
     (setq strs (vla-get-textstring ent))
     (setq g (read (strcat "(" (vl-string-subst " " "-" strs) ")")))
     (setq DoTheMath (/
                ((eval (read sym))
                      (+ (* (car g) 12.0)
                         (cadr g))
                      num) 12))(vla-put-textstring ent
      (strcat (itoa (setq ft (fix DoTheMath))) "-"
              (rtos (* (- DoTheMath ft) 12) 2 0)))
)
     (cond ((and
 (setq strs (ssget ":L" '((0 . "*TEXT"))))

               (progn
                     (initget 7)
                     (setq IntVal (getint "\nEnter Value to Add\Subtact: "))

                     )

       (princ "\nPress [+/-] Any key to Exit")
 (while (member (setq j (grread nil 10)) '((2 45)(2 43)))
 (if (member j '((2 45) (2 43)))
     (repeat (setq i (sslength strs))
                          (setq str (vlax-ename->vla-object (ssname strs (setq i (1- i)))))
                     (Addsub str (chr (cadr j)) IntVal))
                   )
                     )
              )
            )
           )
     (princ)
      )       

 

Notice how mess up the way i do the math? :D

well i guess you get the general idea :)

Edited by pBe
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...