I am writing a AutoLISP but I need help, please

I am writing a AutoLISP but I need help, please

32471490
Contributor Contributor
411 Views
5 Replies
Message 1 of 6

I am writing a AutoLISP but I need help, please

32471490
Contributor
Contributor

I am a new in writing code. And I use AI to write this one. Here are my requests:

 

Environment: CAD2020 & TArchT20V5(a second development software based on cad)

1. support the queries of TEXT, MTEXT, TCH_TEXT, TCH_LEADERTEXT

2. after running the command, it can filter the others objects and keep the above objects only.

3. search the contents and sort them out.

4. extract the numbers only and sum them up. Follows the rules below

    a. when there are spaces in the contents, extract the first number after the first space and classify the numbers into the category with the name as the contents before the space.

    b. when there is no space in the contents, extract the first number and classify the numbers into the category with the name as the contents before the number.

    c. when there are no characters before numbers, extacrt the first number and classify them into one category with with the name as null.

5. feedback the result in the command lines.

 

notes: all the contents obey the following writing format

A 20m2

A20M2

A 20

A20

 

for example, there are text objects bellow

AAA 20M

BBB60M

aaa 10m2

AAA50m2

80m

 

after running the programm, I hope get the result like this

AAA 70

BBB 60

aaa 10

null 80

 

I test the code and it can sellect the right objects like:

mao 10
mao10
jing 10m2
测试10m2
jing10m2
测试 10m2

 

but I got the wrong result which can't classify correctly, like

ma 80

 

Please Help.

0 Likes
Accepted solutions (1)
412 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

Post a sample drawing. Also include those specific types of entities.

 

Also, copy-paste these line (first one, then second one) into command-line and select those special entities: TCH_TEXT, TCH_LEADERTEXT (one at a time)

Do that with both lines, both objects. All 4 results that are listed to command-line copy-paste here.

 

(entget (car (entsel)))

 

(vlax-dump-object (vlax-ename->vla-object (car (entsel))) t)

0 Likes
Message 3 of 6

32471490
Contributor
Contributor

I have no any idea about coding. so I use DeepSeek to write this code for me. DS solve that problem by itself. I tested the code. when there are few objects,for example 10 of them, everything seems perfect. the result meets all my requirements. but when there are many objects like few hundreds, instead of categorizing and summing them up, it listed each object separately.

 

load tch_kenal.arx first, I am not sure whether you can see the Tch objects without installing the software. you can use CAD text for testing.

 

sumtext.lsp is a phased achievement, it can classify and sum up perfect with few objects. So I try to further improve the code(textsum DS.lsp) and DS hasn't completed yet.

0 Likes
Message 4 of 6

32471490
Contributor
Contributor

in T20V5

command: (entget (car (entsel)))
选择对象: ((-1 . <图元名: 1b88ae488a0>) (0 . "TCH_MULTILEADER") (330 . <图元名: 1b88ab641f0>) (5 . "2BA") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "DIM_LEAD") (100 . "TDbEntity") (46 . 0.0) (47 . 100.0) (68 . 1) (100 . "TDbSymbWithText") (7 . "_TCH_DIM") (40 . 3.5) (52 . 0.0) (410 . "PUB_TEXT") (100 . "TDbSymbMultiLeader") (70 . 1) (71 . 0) (11 22339.8 32794.1 0.0) (41 . 3.0) (42 . 29.3158) (1 . "mao 10m^U2^U") (2 . "") (10 21250.9 30448.9 0.0))

 

in T20V10, I can't get the text block code of Tch object via (entget (car (entsel))), when using (vlax-dump-object (vlax-ename->vla-object (car (entsel))) t), I got this:

command: (vlax-dump-object (vlax-ename->vla-object (car (entsel))) t)
选择对象: ; IComSymbMultiLeader: IComSymbMultiLeader Interface
;特性值:
; AlignType = "末端对齐"
; Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff6d0b61e30>
; ArrowSize = "3.0"
; ArrowStyle = "点"
; Document (RO) = #<VLA-OBJECT IAcadDocument 000001d4ea68bb58>
; DownPageWidth = "0.0"
; DownText = ""
; DownTextType = "单行文字"
; EntityTransparency = "ByLayer"
; FontStyle = "_TCH_DIM"
; Handle (RO) = "2B9"
; HasExtensionDictionary (RO) = 0
; Height = "3.5"
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000001ccb31edf48>
; Layer = "DIM_LEAD"
; LayoutRotation = 0.0
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; MaskFlag = "否"
; Material = "ByLayer"
; ObjectControl = "无"
; ObjectID (RO) = 43
; ObjectName (RO) = "TDbSymbMultiLeader"
; OwnerID (RO) = 44
; PlotStyleName = "ByLayer"
; Scale = 100.0
; Text2BaseRatio = "0.30"
; TextColor = 7
; TextLayer = "DIM_LEAD"
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 000001ccb31ee540>
; UpPageWidth = "11.8"
; UpText = "mao123"
; UpTextType = "single text"
; Visible = -1
;支持的方法:
; ArrayPolar (3)
; ArrayRectangular (6)
; Copy ()
; Delete ()
; GetBoundingBox (2)
; GetExtensionDictionary ()
; GetXData (3)
; Highlight (1)
; IntersectWith (2)
; Mirror (2)
; Mirror3D (3)
; Move (2)
; Rotate (2)
; Rotate3D (3)
; ScaleEntity (2)
; SetXData (2)
; TransformBy (1)
; Update ()
T

0 Likes
Message 5 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, so this should work in tv20v5. I also have no experience with chinese signs..

 

(vl-load-com)
(defun c:sum ( / LM:parsenumbers e i x n l) ;; Parse Numbers - Lee Mac ;; https://www.lee-mac.com/parsenumbers.html (defun LM:parsenumbers ( str ) ( (lambda ( l ) (read (strcat "(" (vl-list->string (mapcar '(lambda ( a b c ) (if (or (< 47 b 58) (and (= 45 b) (< 47 c 58) (not (< 47 a 58))) (and (= 46 b) (< 47 a 58) (< 47 c 58)) ) b 32)) (cons nil l) l (append (cdr l) '(())))) ")"))) (vl-string->list str))) ; =================== (if (setq s (ssget '((0 . "TEXT,MTEXT,TCH_TEXT,TCH_LEADERTEXT")))) (repeat (setq i (sslength s)) (and (setq x (cdr (assoc 1 (entget (ssname s (setq i (1- i))))))) (setq n (car (LM:parsenumbers x))) (setq p (substr x 1 (vl-string-search (itoa n) x))) (setq p (vl-string-right-trim " " p)) (setq l (if (setq a (assoc p l)) (subst (cons p (+ (cdr a) n)) a l) (cons (cons p n) l)))))) (print l) (princ) )

 

 

BTW This example of yours seems weird to me (sum of AAA is 20M + 50m2 ??) ... Just pointing this out, the routine counts them as you wanted.

for example, there are text objects bellow

AAA 20M

BBB60M

aaa 10m2

AAA50m2

80m

 

Message 6 of 6

32471490
Contributor
Contributor

thank you so much! the units after numbers are just for testing to ensure the code will run correctly and won't be affected by the subsequent characters. and last night, DS also get right code and the result is the same with yours.😀 but your code looks more concise.

0 Likes