Jump to content

Recommended Posts

Posted

Hello every one

I have some text in model space like this        45#55        63#16       28#69        ofcource   %%c  replace #

(I cant find %%c on my keyboard)

 

   (setq txt 45#55)  ;; for example

    (setq m (strlen txt))
    (setq d1 "")
    (setq d2 "")
    (setq i 0)
    (setq j 1)
(repeat m
      (setq i (1+ i))
      (setq let (substr txt i 1))
      (if (/= let "#")
    (cond
      ((= j 1) (setq d1 (strcat d1 let)))
      ((= j 2) (setq d2 (strcat d2 let)))
    )
 
    (cond ((= let "#") (setq j 2)))
)
 
when I use %%c replace #   It doesn't work
 
Thanks all
 
   
 

 

Posted (edited)

Its a alt+number that's some home work for you ² damm metres squared °   ± ³  I will get there soon. It depends on the font. 

 

Its like the "any" key to quote Homer Simpson, hint its bottom left.

 

Big hint Use Mtext insert symbol.

Edited by BIGAL
Posted

excuse me my english is too bad

IT's not my problem . my problem is not typing .

my problem is that .this lisp dosent work with delimeted %%c

because that's more than one character

thanks

Posted

I'm still not understanding what you're trying to achieve.

 

It looks to me like you want to get the prefix and suffix, given the delimiter at the middle.

 

Because you're using (substr txt i 1) and %%c is three characters long, it's no wonder you couldn't get a match.

 

I suggest you look at Lee Mac's String to List routine with a delimiter. You should get a list of strings with the delimiter.

 

Or you can use mine if you'd like to escape some delimiters by adding an escape character just before the delimiter character.

 

;; JH:str->lst-escape_delimiter --> Jonathan Handojo
;; Parses a string to a list with a supplied delimiter, excluding delimiters with an escape character
;; str - string to parse
;; del - delimiter character
;; esc - escape character placed before the delimiter
;; Example call:
;; _$ (JH:str->lst-escape_delimiter "1,2,3`,4`,5,67,89`,100`,101" "," "`")
;; ("1" "2" "3,4,5" "67" "89,100,101")

(defun JH:str->lst-escape_delimiter (str del esc / nstr sstr final put)
  (setq put "")
  (while (setq nstr (vl-string-search del str))
    (cond
      ((vl-catch-all-error-p
       (vl-catch-all-apply
         'substr
         (list
           (setq sstr (substr str 1 nstr))
           (strlen sstr)
           )
         )
       )
       (setq final (cons put final)
         put ""
         )
       )
      ((eq (substr (setq sstr (substr str 1 nstr)) (strlen sstr)) esc)
       (setq put (strcat put (substr sstr 1 (1- (strlen sstr))) del))
       )
      (
       (setq final (cons (strcat put (substr sstr 1 (strlen sstr))) final)
         put ""
         )
       )
      )
    (setq str (substr str (+ 1 nstr (strlen del))))
    )
  (reverse (cons (strcat put str) final))
  )

 

Posted

Please upload your sample dwg , so we can check how the diameter sign is done.  

Posted (edited)
(defun c:s ()
(setq ss (ssget '((0 . "TEXT"))))
(setq n (sslength ss))
(setq k -1)
(repeat n
    (setq k (1+ k))
    (setq s (ssname ss k))
    (setq en (entget s))
    (setq txt (cdr (assoc 1 en)))
    (setq m (strlen txt))
    (setq d1 "")
    (setq d2 "")
    (setq d3 "")
    (setq d4 "")
    (setq d5 "")
    (setq i 0)
    (setq j 1)
    (repeat m
      (setq i (1+ i))
      (setq let (substr txt i 1))
      (if (/= let "%%C");;;;;;;;;;;;;;;;;;;;;;;;;;here is my problem
	(cond
	  ((= j 1) (setq d1 (strcat d1 let)))
	  ((= j 2) (setq d2 (strcat d2 let)))
	  ((= j 3) (setq d3 (strcat d3 let)))
	  ((= j 4) (setq d4 (strcat d4 let)))
	  ((= j 5) (setq d5 (strcat d5 let)))
	)
	(setq j (1+ j))
      )
    )
    (setq li (append li (list (list d1 d2 d3 d4 d5))))
  )
)

It doesn't work.   for %%c (diameter sign)

Why ?    It doesn't work   with (diameter sign) delimited

Edited by mstb
Posted


(defun split ( s / i)
  (vl-load-com)
  (cond
    ((setq i (vl-string-search "%%" s))
     (princ (strcat "\ntxt1 = " (substr s 1 i) "\ntxt2 = " (substr s (+ i 4)))))
    ((setq i (vl-string-search "#" s))
     (princ (strcat "\ntxt1 = " (substr s 1 i) "\ntxt2 = " (substr s (+ i 2)))))
    (t (princ "\nNo # or %%c found"))
  )
  (princ)
)

(defun c:tst ( / )
  (princ "\n\ntesting : 123%%c456\n")
  (split "123%%c456")
  (princ "\n\ntesting : 78#90\n")
  (split "78#90")
  (princ)
)

 

Posted (edited)

Try doing (JH:str->lst-escape_delimiter txt "%%c" ""). You'll get all your delimited values in a list, so you don't need to bother with d1 d2...

 

So just do:

 

(repeat (sslength ss)

  (setq s (ssname ss (setq k (1+ k))

        txt (cdr (assoc 1 (entget s)))

        lst (JH:str->lst-escape_delimiter txt "%%c" "")

        )

  ; ..... the rest of your code here

Edited by Jonathan Handojo
Posted (edited)
4 hours ago, mstb said:

(defun c:s ()
(setq ss (ssget '((0 . "TEXT"))))
(setq n (sslength ss))
(setq k -1)
(repeat n
    (setq k (1+ k))
    (setq s (ssname ss k))
    (setq en (entget s))
    (setq txt (cdr (assoc 1 en)))
    (setq m (strlen txt))
    (setq d1 "")
    (setq d2 "")
    (setq d3 "")
    (setq d4 "")
    (setq d5 "")
    (setq i 0)
    (setq j 1)
    (repeat m
      (setq i (1+ i))
      (setq let (substr txt i 1))
      (if (/= let (chr 216));;;;;;;;;;;;;;;;;;;;;;;;;;here is my problem
	(cond
	  ((= j 1) (setq d1 (strcat d1 let)))
	  ((= j 2) (setq d2 (strcat d2 let)))
	  ((= j 3) (setq d3 (strcat d3 let)))
	  ((= j 4) (setq d4 (strcat d4 let)))
	  ((= j 5) (setq d5 (strcat d5 let)))
	)
	(setq j (1+ j))
      )
    )
    (setq li (append li (list (list d1 d2 d3 d4 d5))))
  )
)

It doesn't work.   for %%c (diameter sign)

Why ?    It doesn't work   with (diameter sign) delimited

 

Try using (chr 216) instead of "%%c". See above code.

 

%%c is a way of generating the diameter sign inside a text or mtext, command. It is not the actual sign.

Edited by dlanorh
Posted

Thank you very much

Thank you very much all

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