PDA

View Full Version : Move block to Z co-ord



Aubrey.kieren68998
2004-06-08, 10:06 AM
Please help! I'm very new to lisp.
I found this routine a few days ago on the AutoDESK forums, it looks for the "top attribute"(?) I assume this means the first attribute in the list?
I cannot for the life of me work out how to change it to search for a "named" attribute in a block that I wish to use (attribute name is "INVERT").
I would be most grateful if someone could tell me how to to do this! It would save me SOOOO much time!

Thanks,
..::KIEREN::..




;;;C:bel changes a blocks z coordinate to the elevation listed in the top attribute ;
;;;----------------------------
(defun C:bel()
(setq ss (ssget)
ucsf (getvar "ucsfollow"))
(if (/= ss nil)
(progn
(setq ssl (sslength ss))
(setvar "ucsfollow" 0)
(if (/= 1 (getvar "worlducs"))(setq wucs 0)(setq wucs 1))
(command "ucs" "")
(setq numchg ssl
n ssl
newss (ssadd))
(while (> n 0)
(setq n (1- n)
blk (ssname ss n))
(setq ent (vlax-ename->vla-object blk))
(setq atts (vla-getattributes ent))
(setq temp (vlax-variant-value atts))
(setq elem1 (vlax-safearray-get-element temp 0))
(setq el (atof (vla-get-textstring elem1)))
(command "CHANGE" blk "" "P" "E" el "")

);end while
(setq ssl (sslength newss)
n ssl)
(setq txt "block(s) raised to elevation.")
(if (/= numchg 0)
(progn
(print numchg)
(princ txt))
(prompt "No blocks selected."))
)
(prompt "Empty selection set."))
(if (= 0 wucs)(command "ucs" "p"))
(setvar "ucsfollow" ucsf)
(princ)
);end defun

stig.madsen
2004-06-08, 11:08 AM
Something like this maybe?


(defun C:bel (/ att atts blk el ent n numchg ss ucsf wucs)
;; we want to make sure the selection holds blocks
;; with attributes as not to run into an empty safearray
(setq ss (ssget '((0 . "INSERT")(66 . 1)))
n 0
numchg 0
ucsf (getvar "ucsfollow")
)
(if ss
(progn
(setvar "ucsfollow" 0)
(if (/= 1 (getvar "worlducs"))
(setq wucs 0)
(setq wucs 1)
)
(command "ucs" "")
(repeat (sslength ss)
(setq blk (ssname ss n)
n (1+ n)
)
(setq ent (vlax-ename->vla-object blk)
atts (vla-getattributes ent)
)
(foreach a (vlax-safearray->list (vlax-variant-value atts))
(and (= (vla-get-tagstring a) "INVERT")
(setq att a)
)
)
(cond (att
(setq el (atof (vla-get-textstring att)))
(command "CHANGE" blk "" "P" "E" el "")
;; recording actual changes should happen
;; here - we just assume it went well
(setq numchg (1+ numchg))
)
)
) ;_ end repeat
;; reporting 0 changes is also good information
(princ (strcat (itoa numchg) "block(s) raised to elevation."))
) ;_ end progn
(prompt "Empty selection set.")
) ;_ end if
(if (= 0 wucs) (command "ucs" "p"))
(setvar "ucsfollow" ucsf)
(princ)
)

Aubrey.kieren68998
2004-06-08, 11:33 AM
Just like that!

Thank you,
..::KIEREN::..

stig.madsen
2004-06-08, 05:36 PM
Darn it, just realized I made an all too common mistake .. please substitute the line

(setq numchg (1+ numchg))

with
(setq numchg (1+ numchg) att nil)

Aubrey.kieren68998
2004-06-09, 07:47 AM
Thanks for that, but just for my info, what difference would that change make, and why should it need to be changed?

..::KIEREN::..

stig.madsen
2004-06-09, 08:17 AM
If the loop finds an attribute with the tag "INVERT", it'll point the variable att to it. If it runs into a block that does not contain the attribute, it will already have att pointing at an attribute - a wrong attribute in a wrong insert. So it needs to be cleared before searching next insert.

Aubrey.kieren68998
2004-06-09, 11:48 AM
Cheers! Thanks for the help!

AAristizabal
2012-05-29, 03:01 PM
I'm getting an error when using the lisp routine above:

error: no function definition: VLAX-ENAME->VLA-OBJECT

Any idea how to fix it? Thank you

BlackBox
2012-05-29, 04:19 PM
I'm getting an error when using the lisp routine above:

error: no function definition: VLAX-ENAME->VLA-OBJECT

Any idea how to fix it? Thank you

Add this to the top of the code:



(vl-load-com)


FWIW - Most developers tend to place this in AcadDoc.lsp which is loaded automagically at startup, so they don't need to place it within each routine. Thread officially zombified. :(

HTH

irneb
2012-05-30, 06:56 AM
... automagically ...Is that your favorite word already? :lol:

I suppose it's mine as well ... wish everything would just happen auto... :Puffy:

BlackBox
2012-06-04, 04:04 PM
Is that your favorite word already? :lol:


It very much is! :lol: