(defun c:t05 (/ ss en ed i)
(and (setq ss (ssget "X" (list (cons 0 "TEXT"))))
(setq i 0)
(while (setq en (ssname ss i))
(setq ed (entget en))
(entmod (subst (cons 40 0.05) (assoc 40 ed) ed))
(setq i (1+ i))))
(prin1))
(defun c:b01 (/ ss en ed i)
(and (setq ss (ssget "X" (list (cons 0 "INSERT"))))
(setq i 0)
(while (setq en (ssname ss i))
(setq ed (entget en))
(foreach g '(41 42 43)
(setq ed (subst (cons g 0.001) (assoc g ed) ed)))
(entmod ed)
(setq i (1+ i))))
(prin1))
Here's a much quicker way :Quicker in what way? If it happens in the blink of an eye how do you know it quicker?
Quicker in what way? If it happens in the blink of an eye how do you know it quicker?That's because I can see faster than the blinking of an eye ! 8-) That's a joke of course !
Welcome to the Swamp.
;blockselect function
(defun bls (/ s blk bn opt selection )
(vl-load-com)
(while (not
(progn
(initget "N")
(setq blk (entsel "\nSelect Block/N for Block name:"))
(cond
((null blk) (prompt "\n<<Null selection>>"))
((eq blk "N")
(while (not
(and (Setq bn (getstring "\nEnter Block Name: "))
(tblsearch "Block" bn)
)
)
(princ (Strcat "\n<< " bn " Invalid block name>>"))
) T
)
((setq s (car blk))
(if (eq (cdr (Assoc 0 (entget s))) "INSERT")
(setq bn (vla-get-EffectiveName (vlax-ename->vla-object s)))
(prompt "\n<<Invalid Object>>")
)
)
)
)
)
)
(princ (Strcat "\nBlock Name Filter: " (Strcase BN)))
(initget "A W")
(setq opt (cond ((getkword
(strcat "\n Choose option [Window/All] <Window>: ")
)
)
("W")
)
)
(setq selection
(ssget (if (eq opt "A") "_X" "_:L")
(list '(0 . "insert")
(cons 2 (strcat bn ",`*U*"))
)
)
)
(sssetfirst nil selection)
(princ)
)
(defun c:bls()
(bls)
(princ)
)
QuoteQuicker in what way? If it happens in the blink of an eye how do you know it quicker?That's because I can see faster than the blinking of an eye ! 8-) That's a joke of course !QuoteWelcome to the Swamp.
Thanks ! I was in the swamp before . For years ! Now that I came back , though , my account had been terminated . But that's no problem . And the truth is i remember you ; yes , with the cab picture ! Oh , by the way , is Keith Blackie still around ? I knew him long before coming to the Swamp ; although I can't remember the name of the previous glorious site :-( .
Any way , as far as concerning the coding :
I didn't mean "faster" as far as concerning the time needed for the code to get executed . I was referring to the number of the lines . Of course what I thing of "faster" is personal ; there was no offense to David , who afterall kindly wrote down those codes .
I also tried to work it a little myself . I managed to find out that I can set the value of a property of an entinity (specifically here the Scale X , Y and Z factor of a Block object) by this :
( setq ObjectToChange ( ssget ":S" ) )
( setq PROPSsausage ( entget ( ssname ObjectToChange 0 ) ) ) ;(retrieve the sausage as it currently is)
( setq PROPSsausage ( subst ( cons 41 0.001 ) ( assoc 41 PROPSsausage) PROPSsausage) ) ;substitute the list with the new
( setq PROPSsausage ( subst ( cons 42 0.001 ) ( assoc 42 PROPSsausage) PROPSsausage) ) ;then for Scale Y
( setq PROPSsausage ( subst ( cons 43 0.001 ) ( assoc 43 PROPSsausage) PROPSsausage) ) ;then for Scale Z
( entmod PROPSsausage)
In which 41 is the characteristic number in the list of the property (for Scale X) and 0.001 is the new value .
Now all this made me happy for making me remember some of the old Lisp ! But soon I found out that this is not enough ! ... This code only works if you specifically select a single object ... But what about when there are a dozen of such blocks that need to be changed ? Well this is hard for me . Selecting them is easy (with SSget X) , but how will I set the value to each of the block ? I thing I'll have to somehow use the foreach function . And I see that David has already used it . So I'll try to see if I can adopt it to my own code . Afterall , that's why I like programing : it's like Mathematics ; you can do the same thing through various of ways ! :-) However , any suggestion will be welcomed !
( setq BlocksOnLayerPOINT ( ssget "X" ( list ( cons 0 "INSERT" ) ( cons 8 "POINT" ) ) ) )
Then I tried the foreach function in order to scale each object based on its insertion point :( foreach element BlocksOnLayerPOINT
( command "SCALE" element "" ( cdr ( assoc 10 ( entget element ) ) ) 0.5 )
( setq index ( + index 1 ) ) )
The problem is that the entget function needs names and not the entinities themselves .( setq index 0 )
( while ( < index ( sslength BlocksOnLayerPOINT ) )
( command "SCALE" ( ssname BlocksOnLayerPOINT index ) "" ( cdr ( assoc 10 ( entget ( ssname BlocksOnLayerPOINT index ) ) ) ) 0.5 )
( setq index ( + index 1 ) ) )
I think I made it . Instead of trying to access the properties of each block (and change the properties Scale X , Y , Z) , I tried accessing the block itself and scale it with AutoCAD's SCALE command !FWIW .. I'd recommend NOT using commands whenever possible. They are generally slower and can have issues between versions.
First I select all the desired objects (this is no big deal) :Code: [Select]( setq BlocksOnLayerPOINT ( ssget "X" ( list ( cons 0 "INSERT" ) ( cons 8 "POINT" ) ) ) )
Then I tried the foreach function in order to scale each object based on its insertion point :Code: [Select]( foreach element BlocksOnLayerPOINT
The problem is that the entget function needs names and not the entinities themselves .
( command "SCALE" element "" ( cdr ( assoc 10 ( entget element ) ) ) 0.5 )
( setq index ( + index 1 ) ) )
So I tried the while function :Code: [Select]( setq index 0 )
( while ( < index ( sslength BlocksOnLayerPOINT ) )
( command "SCALE" ( ssname BlocksOnLayerPOINT index ) "" ( cdr ( assoc 10 ( entget ( ssname BlocksOnLayerPOINT index ) ) ) ) 0.5 )
( setq index ( + index 1 ) ) )
Finally it works ! :)