Jump to content

Can't quite get this to work. (routine for subtracting Invert levels from cover levels)


Jamesclark64

Recommended Posts

Can anyone help me with this. This routine should

  1. select text  with prefix "CL "
  2. ask me what for an invert level to subtract from the cover level
  3. do the math
  4. add a prefix of IL to the outcome
  5. move the text down by 0.32

all goes well until we get to number 5. it just wont do it. any help would be appreciated.

 

(defun c:il3 ( / ent entData text-str new-text-str insert-point il-value numeric-text new-numeric-text formatted-text)
  (setq ent (entsel "\nSelect text with prefix 'CL ': ")) ; Select the text entity
  (if (and ent
           (eq (cdr (assoc 0 (entget (car ent)))) "TEXT")) ; Ensure the selected entity is a text object
    (progn
      (setq entData (entget (car ent)))
      (setq text-str (cdr (assoc 1 entData))) ; Get the text string
      (if (and (>= (strlen text-str) 3) ; Check if the text length is at least 3 (for "CL ")
               (equal (strcase (substr text-str 1 3)) "CL ")) ; Check if it starts with "CL "
        (progn
          (setq new-text-str (substr text-str 4)) ; Remove the "CL " prefix
          (setq numeric-text (atof new-text-str)) ; Convert the remaining text to a numeric value
          (if (not (numberp numeric-text))
            (prompt "\nThe text after 'CL ' is not a numeric value.")
            (progn
              (setq il-value (getreal "\nEnter the IL value: ")) ; Prompt for the IL value
              (setq new-numeric-text (- numeric-text il-value)) ; Subtract the IL value from the numeric text
              (setq formatted-text (rtos new-numeric-text 2 2)) ; Format the new numeric text to 2 decimal places
              (if (not (vl-string-search "." formatted-text)) ; Ensure there is a decimal point
                (setq formatted-text (strcat formatted-text ".00"))) ; Add ".00" if no decimal part
              (while (< (strlen (substr formatted-text (+ (vl-string-search "." formatted-text) 1))) 2) ; Ensure two decimal places
                (setq formatted-text (strcat formatted-text "0")))
              (setq insert-point (cdr (assoc 10 entData))) ; Get the insertion point of the original text
              (setq insert-point (list (car insert-point) (- (cadr insert-point) 0.32) (if (assoc 30 entData) (caddr insert-point) 0.0))) ; Apply the displacement
              (entmake
               (list
                (cons 0 "TEXT")
                (cons 8 (cdr (assoc 8 entData))) ; Layer
                (cons 10 insert-point) ; Insertion point
                (cons 1 (strcat "IL " formatted-text)) ; New text string with the "IL " prefix and adjusted by IL
                (cons 40 (cdr (assoc 40 entData))) ; Text height
                (cons 7 (cdr (assoc 7 entData))) ; Text style
                (cons 50 (cdr (assoc 50 entData))) ; Rotation angle
                (cons 41 (cdr (assoc 41 entData))) ; Width factor
                (cons 51 (cdr (assoc 51 entData))) ; Obliquing angle
                (cons 71 (cdr (assoc 71 entData))) ; Text generation flags
                (cons 72 (cdr (assoc 72 entData))) ; Horizontal alignment
                (cons 73 (cdr (assoc 73 entData))) ; Vertical alignment
                (cons 11 (cdr (assoc 11 entData))) ; Alignment point (if applicable)
                (if (assoc 210 entData) (cons 210 (cdr (assoc 210 entData)))) ; Normal vector (for 3D alignment), if applicable
               )
              )
            )
          )
        )
        (prompt "\nSelected text does not start with 'CL '.")
      )
    )
    (prompt "\nSelected entity is not a text object.")
  )
  (princ)
)

 

Link to comment
Share on other sites

I'd perhaps look at mapcar for the new insert point, something like this:

 

(setq Insert-Point (mapcar '+ '(0 -0.32 0) Insert-Point))

 

What does it do? Does it create the text in the same location as before or not create the text at all?

  • Like 1
Link to comment
Share on other sites

Posted (edited)

Post a dwg with before and after have a few change value lisps, including do multi. Make it a true dwg so can see why editing pipe inverts. 

 

 

Will filter selection for you rather than entsel. Fails on Mtext of course.

(setq ss (ssget "_+.:E:S" '((0 . "TEXT"))))

(if (= ss nil)(progn (alert "no text selected\nplease try again")(exit)))

(setq txtent (ssname ss 0))

 

Edited by BIGAL
Link to comment
Share on other sites

Posted (edited)

Right Steven but I would use doubles just in case. cant remember off the top of my head but something weird happen only using integers one time.

 

if you want to display quotes in pinc you have to put a slash in front

Selected text does not start with "CL"        this to be written in lisp like       Selected text does not start with \"CL\"

Also you don't have to do all those cos with entData you just have to update the point and string with subst

 

Also (rtos num 2 2) will always display with two decimal points so no need to be testing for that. was a bit confused on what you want the IL stuff to do so might have to be reworked.

 

also added a few quality of life tweeks

updating the first if to while will allwo you to repeat the command as long as you keep selecting an entity.

the 2nd and third if wont just prompt you but restart the command again saving you from having to retype it again. to exit the command either hit esc or don't select anthing.

 

 

 

 

il3.lsp

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