Hello, I have some question. I tried to modify your code below.You can see the example in dwg.If I use this lisp, it can do like the picture show.First question,if I want to add text like"Top Height:" bu using cons 1, how can I modify that part to let me have text I need and value in excel at the same time.Second question,I used cons 10 set distance to put mtext near by original text position.But the positions are the same,so if I faced vertical text ,the mtext created by lisp which position is not fit,is there any way to figure this problem?
In the example.dwg ,those marks were created by artificial one by one.The final goal is that do the lisp to auto label that.If you have some great idea,please let me know.Thank you very much.
(defun c:QTEXTFIND (/ CELL FILENAME I ICOL INS1 IROW IROWS RNG SSET XLAPP XLBOOK XLCELL XLFRANGE XLRANGE XLRANGEC XLSHEET)
(vl-load-com)
(setq dic (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))
(mapcar 'setvar svnames '(0 0)); turn off Osnap, command echoing
(command "_.layer" "_make" "0S-EL" "_color" 7 "" "p" "N" "" "");; <---EDIT Layer name/color as desired
(setq styht (cdr (assoc 40 (tblsearch "style" (getvar 'dimtxsty))))); height of text style in current dimension style
(if (= styht 0.0) (setq styht (* (getvar 'dimtxt) (getvar 'dimscale)))); if above is non-fixed-height
(if (AND
(setq sset (ssget '((-4 . "<OR") (0 . "MTEXT") (0 . "TEXT") (-4 . "OR>"))))
(setq fileName (getfiled "Select Excel file to find cell address :" (getvar "dwgprefix") "xlsx;xls" 16))
)
(progn
(setq xlApp (vlax-create-object "Excel.Application"))
(vlax-put-property xlApp "Visible" :vlax-true)
(setq xlBook (vlax-invoke-method (vlax-get-property xlApp 'WorkBooks) "Open" fileName ) )
(vlax-invoke-method xlBook "Activate")
(setq xlSheet (vlax-get-property (vlax-get-property xlBook "WorkSheets") "Item" 1) )
(setq xlRangeC (vlax-invoke-method xlSheet "Activate") )
(setq xlRange (vlax-get-property xlSheet "Range" "A1:A1000"))
(vlax-invoke-method xlRange "Select")
(setq iCol (vlax-get-property xlRange "Column"))
(setq iRows (vlax-get-property(vlax-get-property xlRange "Rows") "Count" )iRow (vlax-get-property xlRange "Row") )
(setq rng (vlax-get-property xlApp 'Cells))
(setq i 0)
(repeat (sslength sset)
(setq xlCell (vlax-invoke-method
xlRange
"Find"
(vlax-make-variant (vla-get-TEXTSTRING (vlax-ename->vla-object (ssname sset i)) ))
xlFRange
-4163
1
1
1
nil
nil
)
)
(setq cell (vlax-variant-value (vlax-get-property rng 'Item (vlax-get-property xlCell "Row") (+ 5 (vlax-get-property xlCell "Column")) ) ) ) ;第幾列
(setq cell2 (vlax-variant-value (vlax-get-property rng 'Item (vlax-get-property xlCell "Row") (+ 6 (vlax-get-property xlCell "Column")) ) ) ) ;第幾列
(setq ins1 (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint (vlax-ename->vla-object (ssname sset i))))))
(entmakex (list '(0 . "MTEXT")
'(100 . "AcDbEntity")
'(67 . 0) '(8 . "0S-EL") '(62 . 0)
'(6 . "Continuous")
'(100 . "AcDbMText")
(cons 10 (LIST (+(CAR ins1)85) (+(CADR ins1) 25) (CADDR ins1) ))
'(40 . 12) '(41 . 100)
'(46 . 0) '(71 . 1) '(72 . 5)
(cons 1 (RTOS (vlax-variant-value (vlax-get-property cell 'value2)) 2 2 ))
'(7 . "NOTE") '(11 1 0 0)
'(42 . 133.3333333333333) '(43 . 100)
'(50 . 0) '(73 . 1) '(44 . 1)
)
)
(setq p1 (LIST (+(CAR ins1)70) (+(CADR ins1) 30) (CADDR ins1))
p2 (LIST (+(CAR ins1)160) (-(CADR ins1) 20) (CADDR ins1))
p3 (LIST (+(CAR ins1)70) (+(CADR ins1) 5) (CADDR ins1))
p4 (LIST (+(CAR ins1)160) (+(CADR ins1) 5) (CADDR ins1))
)
(command "rectang" p1 p2)
(command "line" p3 p4 "")
(entmakex (list '(0 . "MTEXT")
'(100 . "AcDbEntity")
'(67 . 0) '(8 . "0S-EL") '(62 . 2)
'(6 . "Continuous")
'(100 . "AcDbMText")
(cons 10 (LIST (+(CAR ins1)85) (CADR ins1) (CADDR ins1) ))
'(40 . 12) '(41 . 100)
'(46 . 0) '(71 . 1) '(72 . 5)
(cons 1 (RTOS (vlax-variant-value (vlax-get-property cell2 'value2)) 2 2 ))
'(7 . "NOTE") '(11 1 0 0)
'(42 . 133.3333333333333) '(43 . 100)
'(50 . 0) '(73 . 1) '(44 . 1)
)
)
(setq i (1+ i))
)
)
)
(princ)
)