Jump to content

Extract text from dimension , make summ


Recommended Posts

Posted (edited)

In the attached file you will see a plan which show the placing of the stirrups , so I want :

To extract all number that are before "x" variable and summ all of them !!!

In this case we should obtain 1501.

stirrup.dwg

Edited by sergiu_ciuhnenco
Posted

That's odd, i only get 1437 as total, Numbers before "x" string . i.e "15x100=1500" ?

Posted

1501 I do it one more time manualy , same result; You said correct numbers before "x" string for example "15x100=1500"; "5x90=450"

Posted (edited)

I see, apparently there are Mtext character formatting thats why it missed around 6 values with a sum of 64 :lol:

 

Will that always be the case? some have and some not formatted?

 

HYG [LM:UnFormat

 

(defun c:summd (/ LM:UnFormat Total ss val)
 (defun LM:UnFormat (str mtx / _Replace regex)
   (vl-load-com)
   ;; © Lee Mac 2010

   (defun _Replace (new old str)
     (vlax-put-property regex 'pattern old)
     (vlax-invoke regex 'replace str new)
   )
   (setq regex (vlax-get-or-create-object "VBScript.RegExp"))
   (mapcar
     (function
(lambda (x) (vlax-put-property regex (car x) (cdr x)))
     )
     (list (cons 'global actrue)
    (cons 'ignorecase acfalse)
    (cons 'multiline actrue)
     )
   )
   (mapcar
     (function
(lambda (x) (setq str (_Replace (car x) (cdr x) str)))
     )
     '(
("Ð" . "\\\\\\\\")
(" " . "\\\\P|\\n|\\t")
("$1"
 .
 "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]"
)
("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
("$1$2" . "\\\\(\\\\S)|[\\\\](})|}")
("$1" . "[\\\\]({)|{")
      )
   )
   (setq str
   (if mtx
     (_Replace
       "\\\\"
       "Ð"
       (_Replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)
     )
     (_Replace "\\" "Ð" str)
   )
   )
   (vlax-release-object regex)
   str
 )
 (setq	aDoc  (vla-get-ActiveDocument (vlax-get-acad-object))
Total 0
 )
 (if (ssget '((0 . "*DIMENSION")
       (-4 . "<OR")
       (1 . "*?*")
       (-3 ("ACAD"))
       (-4 . "OR>")
      )
     )
   (progn
     (vlax-for	e (setq ss (vla-get-ActiveSelectionSet aDoc))
(if
  (vl-string-position
    88
    (strcase (setq val (LM:UNFORMAT (vla-get-textoverride e) t))
    )
  )
   (setq total (+ (atoi val) total))
)
     )
     (vla-delete ss)
     (alert (itoa Total))
   )
 )
)

Edited by pBe
Posted

It will be better, if it will be a universal lisp , good for all types of dimensions ( formated, unformated )

But about the lisp that you have attached , does not work .

???

Posted

I don't know I try allready several times It show me "Command: (LOAD "C:/Users/S_C/Desktop/text find - копия.lsp") C:SUMMD

Command: SUMMD

Select objects: Specify opposite corner: 108 found

Select objects: ; error: Ошибка

Command: "

Posted (edited)

Hang on, i will strip down the code , its probably language issue with RegExp.

BTW: what does this mean? Ошибка

 

UPDATE: Nothing to do with RegExp, apparently its just a case of "unicode" encoding

 

Kudos to LM for LM:UnFormat function

Edited by pBe
Posted

Can you attach the lisp file , when a copy the code in mine lisp file it show me something wrong about the unicode file , for me is first time when is appear something like that !!!

Posted

Ошибка mean error !!!

Posted (edited)
can you attach the lisp file , when a copy the code in mine lisp file it show me something wrong about the unicode file , for me is first time when is appear something like that !!!

 

hyg

summd.LSP

 

Tell me how it goes before i start to modify the code

 

[customize for sergiu]

(defun c:summd (/ aDoc Total ss val)
 (setq	aDoc  (vla-get-ActiveDocument (vlax-get-acad-object))
Total 0
 )
 (if (ssget '((0 . "*DIMENSION")
       (-4 . "<OR")
       (1 . "*?*")
       (-3 ("ACAD"))
       (-4 . "OR>")
      )
     )
   (progn
     (vlax-for	e (setq ss (vla-get-ActiveSelectionSet aDoc))
(if (wcmatch (setq val (strcase (vla-get-textoverride e))) "*#X#*")
  (progn
    (while (and	(setq p (vl-string-position 59 val))
		(setq val (substr val (+ 2 p)))
		(eq (substr val 1 1) "\\")
	   )
    )
    (setq total (+ (atoi val) total))
  )
)
     )
     (vla-delete ss)
     (alert (itoa Total))
   )
 )
)

Edited by pBe
Might as well
Posted (edited)

super !!! it works now, 1501 final result !!!

Now I will waste less time .

Thanks a lot !!!

Edited by sergiu_ciuhnenco
Posted
super !!! it works now

Phanks a lot !!!

 

I guess that means Thanks [ or is this another case of the "unicode" thingy :lol: ]

 

Good for you and you are welcome, glad you had it sorted.

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