Leaderboard
Popular Content
Showing content with the highest reputation on 05/31/2024 in all areas
-
(defun c:smadd (/ ss i addnum obj num otext utext ulist onum anum rnum rtext plusminus) (vl-load-com) (setq ss (ssget '((0 . "MTEXT")))) (setq i 0) (setq addnum (/ (getreal "\nhow much should I add: ") 100)) (while (< i (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss i))) (setq otext (vla-get-textstring obj)) (setq utext (LM:UnFormat otext t)) (setq ulist (Lm:str->lst utext "+")) (if (= (length ulist) 2) (progn (setq num (vl-string-subst "+" "." (rtos (+ addnum (atof (vl-string-subst "." "+" utext))) 2 2))) (setq rtext (vl-string-subst num utext otext)) (vla-put-textstring obj rtext) ) (progn ) ) (setq i (1+ i)) ) (princ) ) ;; String to List - Lee Mac ;; Separates a string using a given delimiter ;; str - [str] String to process ;; del - [str] Delimiter by which to separate the string ;; Returns: [lst] List of strings (defun LM:str->lst ( str del / pos ) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; (defun LM:UnFormat ( str mtx / _replace rx ) (defun _replace ( new old str ) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda ( ) (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) ah i understand. like this? If the total number is negative, how should it be expressed? For example, if -0.40 then -0+40? -0-60? Or Doesn't this work with negative numbers?2 points
-
some edit of EnM4st3r's code. ah.. my mistake. Add and Subtract the last number of mtext with only one + or -. When it becomes negative, + changes to -. It does not work if there are two or more +'s. (defun c:smadd (/ ss i addnum obj num otext utext ulist onum anum rnum rtext plusminus) (vl-load-com) (setq ss (ssget '((0 . "MTEXT")))) (setq i 0) (setq addnum (getreal "\nhow much should I add: ")) (while (< i (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss i))) (setq otext (vla-get-textstring obj)) (setq utext (LM:UnFormat otext t)) (setq ulist (Lm:str->lst utext "+")) (if (= (length ulist) 2) (progn (setq onum (last ulist)) (setq anum (+ addnum (atof onum))) (if (> anum 0) (progn (setq anum (rtos anum 2 0)) (if (= (strlen anum) 1) (setq anum (strcat "0" anum)) ) (setq plusminus "+") ) (progn (if (= (strlen (rtos anum 2 0)) 2) (setq anum (strcat "0" (rtos (abs anum) 2 0))) (setq anum (rtos (abs anum) 2 0)) ) (setq plusminus "-") ) ) (setq rnum (strcat (car ulist) plusminus anum)) (setq rtext (vl-string-subst rnum utext otext)) (vla-put-textstring obj rtext) ) (progn (setq ulist (Lm:str->lst utext "-")) (if (= (length ulist) 2) (progn (setq onum (* -1 (atof (last ulist)))) (setq anum (+ addnum onum)) (if (> anum 0) (progn (setq anum (rtos anum 2 0)) (if (= (strlen anum) 1) (setq anum (strcat "0" anum)) ) (setq plusminus "+") ) (progn (if (= (strlen (rtos anum 2 0)) 2) (setq anum (strcat "0" (rtos (abs anum) 2 0))) (setq anum (rtos (abs anum) 2 0)) ) (setq plusminus "-") ) ) (setq rnum (strcat (car ulist) plusminus anum)) (setq rtext (vl-string-subst rnum utext otext)) (vla-put-textstring obj rtext) ) ) ) ) (setq i (1+ i)) ) (princ) ) ;; String to List - Lee Mac ;; Separates a string using a given delimiter ;; str - [str] String to process ;; del - [str] Delimiter by which to separate the string ;; Returns: [lst] List of strings (defun LM:str->lst ( str del / pos ) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; (defun LM:UnFormat ( str mtx / _replace rx ) (defun _replace ( new old str ) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda ( ) (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) )2 points
-
also thought of saving the formatting in a list somehow, but didnt wanna dive into that2 points
-
I'll be honest, I didn't understand what you were asking for originally Now I see this lisp I understand, and it has the gears in my mind turning with possibilities haha Knew you were in good hands.. Have a great weekend both2 points
-
@pkenewellThis works perfectly. I can usually see how the programs work, but this work of genius, i can't get my head around... I have a couple of projects coming up where this would be used around 10 times each. Thank you my friend2 points
-
@Sharper Actually I'm back from Holiday now so no problem . Hope your Holiday is going well. Just let me know how it works when you have time to look at it.2 points
-
Spammer removed. I was already suspicious of them.1 point
-
what about 0+10 substracted 500? -5-10? but since 0+00 ist the smallest value leaving it at -5+10 is the easiest.1 point
-
spam? you can use Python and BeautifulSoup import traceback from pyrx_imp import Rx, Ge, Gs, Db, Ap, Ed import wx import requests from bs4 import BeautifulSoup as bs import pandas as pd # sample source https://www.scraperapi.com/blog/python-loop-through-html-table/ def scraper9000(): url = "https://datatables.net/examples/styling/stripe.html" response = requests.get(url) soup = bs(response.text, "html.parser") table = soup.find("table", class_="stripe") data = { 'Name': [], 'Position': [], 'Office': [], 'age': [], 'Start date': [], 'salary': [], } for employee_data in table.find_all("tbody"): for row in employee_data.find_all("tr"): data['Name'].append(row.find_all("td")[0].text) data['Position'].append(row.find_all("td")[1].text) data['Office'].append(row.find_all("td")[2].text) data['age'].append(row.find_all("td")[3].text) data['Start date'].append(row.find_all("td")[4].text) data['salary'].append(row.find_all("td")[5].text) return data def PyRxCmd_doit(): try: db = Db.curDb() df = pd.DataFrame(scraper9000()) table = Db.Table() table.setDatabaseDefaults(db) table.setSize(df.shape[0]+2, df.shape[1]) table.setTextString(0, 0, "Scrape Master 9000") headers = df.columns.values.tolist() datas = df.values.tolist() for col, value in enumerate(headers): table.setTextString(1, col, "{}".format(value)) for row, data in enumerate(datas): for col, value in enumerate(data): table.setTextString(row+2, col, "{}".format(value)) model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite) model.appendAcDbEntity(table) except Exception as err: traceback.print_exception(err)1 point
-
@exceed nice , this is smart didnt think about that. (vl-string-subst rnum utext otext) but i thought he wanted only the last 2 numbers behind the plus everything else should be added like infront of the plus. So 0+48 added with +1000 should be 10+481 point
-
Quickly looking at the drawing, the mtexts in question all have formatting code 'p34;' - could use Lee Macs String to List using p34; as a delimitator, change the text portion and then list to string to remake the text again1 point
-
The Lisp has to remove the individual text formatting since it cant read the values otherwise. To retain the Formatting would be way more complicated. Just type for example -20 or -50.1 point
-
When reading direct from Excel it nearly always needs to be a custom program, reading certain cells then putting into say a attribute. The issues can be like read column 1 then 4 then 2 then 3 etc. There is a lot of code out there, I started with getexcel and added more functions, you need to have a good understanding of lisp but its fairly easy to do. The other way is to use a Excel macro and create CAD objects. Speed not a problem as I use different method than getexcel to read cells. There are a few of us here with excel code do a google. If you post a dwg and excel can see what I can do. Make it clear what is being changed. Alan Excel library.lsp Last comment working on similar for Librecalc.1 point
-
Unformat is here: https://lee-mac.com/unformatstring.html - copy and paste the code to a text file and load as a LISP, maybe add it to the same as c:smadd above - before the LISP that refers to it is often better1 point
-
like this maybe? (defun c:smadd (/ ss i addnum obj num) (setq ss (ssget '((0 . "MTEXT")))) (setq i 0) (setq addnum (/ (getreal "\nhow much should I add: ") 100)) (while (< i (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss i))) (setq num (+ addnum (atof (vl-string-subst "." "+" (LM:UnFormat (vla-get-textstring obj) t))))) (vla-put-textstring obj (vl-string-subst "+" "." (rtos num 2 2))) (setq i (1+ i)) ) ) also beware that your text uses individual text formatting. cant read the text values with it so using LM:UnFormat to remove it. https://www.lee-mac.com/unformatstring.html1 point