Jump to content

Pre fill in (getstring)


Emmanuel Delay

Recommended Posts

Is there a way to pre fill in a part of the value of getstring?

 

(setq new_text (getstring_prefilled "\nNew value: " "new_value_" ))

 

So it already fills in "new_value_", and now I can add a number, "new_value_123", but just as well I can remove that "new_value_"... 

 

(is this question clear?)

attch.png

 

 

[code]

;; change attribute
(defun c:attch ( / blk att tag)
  (while T
    (setq att (car (nentsel "\n select attribute to change: ")))
    (setq blk (cdr (assoc 330 (entget att))))  ;; get parent block of a nentsel
    (setq tag (cdr (assoc 2 (entget att))))
    (princ tag)
    (LM:vl-setattributevalue (vlax-ename->vla-object blk) tag (getstring T "\nNew value: "))
  )
)
[/code]

Edited by Emmanuel Delay
Link to comment
Share on other sites

Yes, it's possible :

 

;; change attribute ;; https://www.cadtutor.net/forum/topic/73972-pre-fill-in-getstring/
(defun c:attch ( / LM:vl-setattributevalue adoc att blk tag )

  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))

  ;; Set Attribute Value  -  Lee Mac
  ;; Sets the value of the first attribute with the given tag found within the block, if present.
  ;; blk - [vla] VLA Block Reference Object
  ;; tag - [str] Attribute TagString
  ;; val - [str] Attribute Value
  ;; Returns: [str] Attribute value if successful, else nil.

  (defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
      (function
        (lambda ( att )
          (if (= tag (strcase (vla-get-tagstring att)))
            (progn (vla-put-textstring att val) val)
          )
        )
      )
      (vlax-invoke blk 'getattributes)
    )
  )

  (while (setq att (car (nentsel "\n select attribute to change: ")))
    (setq blk (cdr (assoc 330 (entget att))))  ;; get parent block of a nentsel
    (setq tag (cdr (assoc 2 (entget att))))
    (princ tag)
    (vla-sendcommand adoc "new_value_") ;; this is the trick to add predefined prefix to (getstring) specification that follows...
    (LM:vl-setattributevalue (vlax-ename->vla-object blk) tag (getstring T "\nNew value : "))
  )
  (princ)
)

 

HTH.

M.R.

Edited by marko_ribar
  • Like 2
Link to comment
Share on other sites

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