LISP - Change lisp to accept 2 atts

LISP - Change lisp to accept 2 atts

cool.stuff
Collaborator Collaborator
1,681 Views
22 Replies
Message 1 of 23

LISP - Change lisp to accept 2 atts

cool.stuff
Collaborator
Collaborator

Good evening,

I have this lisp from an unknown author (sorry!) that allows to select all blocks given an attribute and its value (see attachment).
Could this be changed accept another attribute and value after the first inputs.
If possible, could the input be like this:


Pick first attribute:

Pick second attribute:

 

And then it would select, for the selected block, all that matches those two criteria.
I have a drawing with multiple blocks, which are defined by pairs and this would reduce my search time considerably 🙂

Many thanks in advance 🙂

0 Likes
Accepted solutions (3)
1,682 Views
22 Replies
Replies (22)
Message 2 of 23

vladimir_michl
Advisor
Advisor

The block and tag names can be specified my a mask, so try e.g. "blockname1,blockname2" and "attname1,attname2". It will select the pairs using the "OR" condition.

 

Vladimir Michl, www.arkance.world  -  www.cadforum.cz

 

0 Likes
Message 3 of 23

cool.stuff
Collaborator
Collaborator

Thank you for your reply.

 

Sorry I do not know how to code in LISP.

Based on Lee Mac lisp, the blockname is retrieved once we select the block.

Then, based on two attributes and two values, it selects all blocks given a user selection area.

0 Likes
Message 4 of 23

vladimir_michl
Advisor
Advisor
Accepted solution

There is no need to code. In BSEL, you select the block and tag names by typing - so type a list of two block names and then two tag names.

 

Vladimir Michl, www.arkance.world  -  www.cadforum.cz

 

Message 5 of 23

Sea-Haven
Mentor
Mentor
Accepted solution

I posted this yesterday and will change to update any block by name. You just pick a block and the tag names are displayed so enter new values for that tagname. 

 

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/numeri-crescenti-nei-blocchi-con-attributo/td-p/13308410
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-change-lisp-to-accept-2-atts/td-p/13313319

(defun c:updateatt ( / ans att atts lst lst2 obj val x)

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(setq obj (vlax-ename->vla-object (car (entsel "\nPick block object "))))
(setq bname (vlax-get obj 'name))
(setq atts (vlax-invoke obj 'Getattributes))

(setq lst '())
(foreach att atts
  (setq lst (cons (vlax-get att 'Tagstring) lst))
)

(setq lst2 '())
(foreach val lst
  (setq lst2 (cons "" lst2))
  (setq lst2 (cons 20 lst2))
  (setq lst2 (cons 21 lst2))
  (setq lst2 (cons val lst2))
)
(setq lst2 (cons "Please choose " lst2))

(setq ans (AH:getvalsm lst2))
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 bname))))

(repeat (setq K (sslength ss))
(setq blk (vlax-ename->vla-object  (ssname ss (setq k (1- k)))))
(setq attsblk (vlax-invoke blk 'Getattributes))
(setq x 0)
(foreach val ans
  (if (= val "")
   (princ)
   (vlax-put (nth x attsblk) 'textstring (nth x ans))
  )
  (setq x (1+ x))
)
)

(princ)

(c:updateatt)

 

 

Save multi getvals.lsp in a support path or use full path in (load "c:\\yourdirectory\\multigetvals.lsp")

 

SeaHaven_0-1739318574730.png

 

Message 6 of 23

cool.stuff
Collaborator
Collaborator

I got an error with your lisp.

I pick the block, get all attributes displayed and I fill the one I want it to search but got an error "Pick block object (T10-0.125 ???-0.25 ); error: bad argument type: lselsetp nil". Could you help?

 

Do I need to fill all attributes' fields in order to make it work? I would like just to select one field and those empty fields should be ignored.

 

Also, could this lisp also lists custom properties?

 

many thanks 🙂

0 Likes
Message 7 of 23

cool.stuff
Collaborator
Collaborator

I got wrong lisp, sorry. Could you please check again? Many thanks again 🙂

0 Likes
Message 8 of 23

cool.stuff
Collaborator
Collaborator

@Sea-Haven  could you please take a look at the edited attached lisp please?

it would save me tons of time 🙂

Thanks

0 Likes
Message 9 of 23

Sea-Haven
Mentor
Mentor

Yes you only fill in the value for the attribute you want to change if you leave the value blank it is ignored.

 

Not sure about block name "T10-0.125 ???-0.25 " explain more the ??? may be a problem.

Message 10 of 23

cool.stuff
Collaborator
Collaborator

@Sea-Haventhanks for your reply.

"T10-0.125 ???-0.25 " is not the block name, but the search words for 2 attributes, the first is "T10-0.125" and the second is "???-0.25 ".

I pick the block that I want and then I type in both search words and gives me that error.

If I write just the first search word is the same.

 

And this happens for any block in my computer.

 

Could you post a working example please?

 

Many thanks again 🙂

0 Likes
Message 11 of 23

Sea-Haven
Mentor
Mentor

If you "you select the block and tag names by typing" then that is code by @vladimir_michl not me.

 

Make sure  "Multi getvals.lsp" is being loaded automatically use this as a test.

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

Then run the code above you should see your tagnames with blank values, fill in any value you want changed, leave blank if no change, see image above.

0 Likes
Message 12 of 23

cool.stuff
Collaborator
Collaborator

@Sea-HavenI am trying your code.

I have the lisp you mentioned above.

I type in different atteibutes the search words that show in a dcl (I think that is the name of the UI input dialog.

 

The error is the result that I got after rubning your lisps.

 

Do you have a sample dwg and block that works for you please?

 

Many thanks

0 Likes
Message 13 of 23

Sea-Haven
Mentor
Mentor

The tag name should be appearing in the dcl created then the value for that tag is blank and you can change. This code works with any block, possible disclaimer not checked with dynamic blocks. 

 

Post your real dwg. 

 

 This is just a random dwg downloaded from here, containing a block and I picked the block. You can see tag names. The values are blank change as required can do more than 1 tag name.

SeaHaven_0-1739409668540.png

 

0 Likes
Message 14 of 23

vladimir_michl
Advisor
Advisor

It is not my code. I was just trying to interpret what that code expects.

 

Vladimir Michl, www.arkance.world  -  www.cadforum.cz

 

0 Likes
Message 15 of 23

cool.stuff
Collaborator
Collaborator

Thanks @Sea-Haven 🙂

This is a dynamic block, maybe that is the problem.

Please find attached an example.

 

Many thanks 🙂

0 Likes
Message 16 of 23

vladimir_michl
Advisor
Advisor

If you refer the blocks or attributes by name (i.e. your original LISP code), the list elements should be referred as comma-delimited wildcards (see the Help for the wcmatch function) - i.e. in your case (without the quotes):
"T10-0.125,???-0.25"

 

Vladimir Michl, www.arkance.world  -  www.cadforum.cz

 

Message 17 of 23

cool.stuff
Collaborator
Collaborator

@vladimir_michl  thanks form your reply 🙂

 

I managed to do what you said.

That works.

But there are many blocks and it is not very practical...

Hence I asked for help in working out the lisp from @Sea-Haven , which is way practical and more usefull.

 

Thanks

0 Likes
Message 18 of 23

Sea-Haven
Mentor
Mentor

The dynamic block does not appear to have attributes but does have properties, I do have code for a similar output to dcl it reads the property value names. So can change the value and update the Block, is that what you want. 

Message 19 of 23

cool.stuff
Collaborator
Collaborator

@Sea-Haventhanks for your help 🙂

 

That is exactly waht I need 🙂

 

Could you please share your lisp and dcl please?

If I am not wrong, the dcl you have already shared above right?

 

Many thanks again

0 Likes
Message 20 of 23

Sea-Haven
Mentor
Mentor
Accepted solution

To change dynamic block properties you can do the same as the get Tag names but rather get Property names and display in a dcl. I am busy at moment, will see what I can do I do have something all ready done for visibility should be easy to change to properties.

 

I have not done a check is dynamic block ultimate would be to combine the two lisp codes, looking at block type.

 

Try this for dynamic block, download Multi getvals.lsp.

SeaHaven_0-1739870853261.png

 

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-change-lisp-to-accept-2-atts/td-p/13313319
; Update a dynamic block by display property name in dcl
; By AlanH Fen 2025

(defun c:dynup ( / x obj prop props)

;; Set Dynamic Block Property Value  -  Lee Mac
;; Modifies the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; val - [any] New value for property
;; Returns: [any] New value if successful, else nil

(defun LM:setdynpropvalue ( blk prp val)
    (setq prp (strcase prp))
    (vl-some
       '(lambda ( x )
            (if (= prp (strcase (vla-get-propertyname x)))
                (progn
                    (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
                    (cond (val) (t))
                )
            )
        )
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

;; Get Dynamic Block Properties  -  Lee Mac
;; Returns an association list of Dynamic Block properties & values.
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [lst] Association list of ((<prop> . <value>) ... )

(defun LM:getdynprops ( blk )
    (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

(setq obj (vlax-ename->vla-object (car (entsel "\nPick block object "))))
(setq props (LM:getdynprops obj))
(setq lst '() lst2 '())
(foreach prop props
  (setq bname (car prop))
  (if (= bname "Origin")
  (princ)
  (progn
   (setq lst (cons "" lst))
   (setq lst (cons 19 lst))
   (setq lst (cons 20 lst))
   (setq lst (cons bname lst))
   (setq lst2 (cons bname lst2))
  )
)
)
(setq lst (cons "please edit" lst))

(alert "Enter new value leave blank for no change")

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm lst))

(setq X 0)
(foreach val ans
  (if (= val "")
  (princ)
  (LM:setdynpropvalue obj (nth x lst2) (atof val))
)
(setq x (1+ x))
)

(princ)
)