Jump to content

help with extracting text from one dimension....


Recommended Posts

Posted

Yes, welcome to the corporate world.

Posted
On 4/15/2024 at 9:21 PM, pkenewell said:

I recommend that you also provide instructions on your GITHUB on how to download and install the ObjectARX Library properly. Maybe also start a "releases" section?

 

I have made a compressed package version, no EXE is required, you can try it if you are interested.

 

https://github.com/xdcad/XDrx-API-zip

 

https://github.com/xdcad

  • 1 year later...
Posted
On 7/14/2022 at 1:54 AM, ronjonp said:

And another that allows a pick of any part of the dimension :)

(defun c:foo (/ e el m p1 p2)
 (if
 (and
 (setq e (car (entsel "\nPick dimension: ")))
 (progn (vlax-for a (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
 (cdr (assoc 2 (entget e)))
 )
 (and (= "AcDbMText" (vla-get-objectname a)) (setq m (vlax-vla-object->ename a)))
 )
 m
 )
 (setq p1 (cdr (assoc 10 (setq el (entget m)))))
 (setq p2 (getpoint p1 "\nSpecify second point: "))
 )
 (entmakex (append (vl-remove-if '(lambda (x) (= 330 (car x))) el) (list (cons 10 p2))))
 )
 (princ)
)

How can I convert the text size for insertion to the number x by 0.001, that is, if the size is 4250, then we get 4.250 when inserting?  Thanks!

Posted

Something like this?

(defun c:foo (/ e el m p1 p2)
  (cond
    ((and
       (setq e (car (entsel "\nPick dimension: ")))
       (progn (vlax-for	a (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
				    (cdr (assoc 2 (entget e)))
			  )
		(and (= "AcDbMText" (vla-get-objectname a)) (setq m (vlax-vla-object->ename a)))
	      )
	      m
       )
       (setq p1 (cdr (assoc 10 (setq el (entget m)))))
       (setq p2 (getpoint p1 "\nSpecify second point: "))
     )
     (setq
       e (entmakex (append (vl-remove-if '(lambda (x) (= 330 (car x))) el) (list (cons 10 p2))))
     )
     (vla-put-height (setq e (vlax-ename->vla-object e)) (* 0.001 (vla-get-height e)))
    )
  )
  (princ)
)

 

  • Thanks 1
Posted (edited)
8 hours ago, ronjonp said:
 (vla-put-height (setq e (vlax-ename->vla-object e)) (* 0.001 (vla-get-height e)))

@ronjonp thanks.

This code reduces the height of the text, 
but I need to reduce the dimension value (x 0.001) and insert the text (angle  text 0, 
text height = height of the dimtext).

DimTxtCopy.png

Edited by Nikon
Posted (edited)
On 7/13/2022 at 8:31 PM, mhupp said:
;; Copy dimension value to another location
(defun C:DimCopy (/ dim BP LastEnt  en)

Probably, for my task, it will be easier to change the @mhupp code.

;; Copy dimension value to another location (x0.001) + text angle = 0
;; DimCopy.lsp the original / creator mhupp
;; https://www.cadtutor.net/forum/topic/75587-help-with-extracting-text-from-one-dimension/#findComment-597630
;; modification using AI 

(defun _DimCopy001:OnlyNum (s / lst out c)
  ;; we leave only numbers, minus sign, period/comma
  (setq lst (vl-string->list s)
        out "")
  (foreach c lst
    (if (member c (vl-string->list "0123456789-.,"))
      (setq out (strcat out (chr c)))
    )
  )
 ;; comma -> period
  (vl-string-subst "." "," out)
)

(defun _DimCopy001:SetText (e / ed txt num new r50)
  (setq ed  (entget e)
        txt (cdr (assoc 1 ed)))

  ;; change the text to *0.001
  (if (and txt (/= txt ""))
    (progn
      (setq txt (_DimCopy001:OnlyNum txt))
      (if (and txt (/= txt ""))
        (progn
          (setq num (atof txt))
          (setq new (rtos (* num 0.001) 2 3))  ; for example 4250 -> 4.250

          (setq ed (subst (cons 1 new) (assoc 1 ed) ed))
        )
      )
    )
  )

  ;;   ang 0 (DXF 50)
  (if (setq r50 (assoc 50 ed))
    (setq ed (subst (cons 50 0.0) r50 ed))
    (setq ed (append ed (list (cons 50 0.0))))
  )

  (entmod ed)
  (entupd e)
)

(defun C:DimCopy001Txt (/ dim BP LastEnt en obj oldEcho)
  (vl-load-com)
  (setq oldEcho (getvar 'cmdecho))
  (setvar 'cmdecho 0)

  (while (setq dim (car (entsel "\nSelect Dimension: ")))
    (setq obj (vlax-ename->vla-object dim))
    (setq BP (vlax-get obj 'TextPosition))
    (setq LastEnt (entlast))

    (command "_.Copy" dim "" "_non" BP (getpoint BP "\nCopy to: "))
    (command "_Explode" (entlast))

    (if (setq en (entnext LastEnt))
      (while en
        (cond
          ((= "MTEXT" (cdr (assoc 0 (entget en))))
           (command "_Explode" en) ; convert mtext to text
          )
          ((= "TEXT" (cdr (assoc 0 (entget en))))
           (_DimCopy001:SetText en) ; <<< scale + angle 0
          )
          (t
           (entdel en)
          )
        )
        (setq en (entnext en))
      )
    )
  )

  (setvar 'cmdecho oldEcho)
  (princ)
)

Perhaps this code can be made prettier and shorter...😉

Edited by Nikon

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