Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

extract attribute value (elevation) and move attribute to z

20 REPLIES 20
Reply
Message 1 of 21
Anonymous
1395 Views, 20 Replies

extract attribute value (elevation) and move attribute to z

is there a routine out there to extract the value of a attribute (lets say 55.8) and move the attribute insertion point to that elevation?

this would be helpful so i can osnap to insertion of the attribute with a 3d polyline line. thanks everyone.
20 REPLIES 20
Message 2 of 21
Anonymous
in reply to: Anonymous

i have tried this routine:

(defun c:elevate ()
(setq ss (ssget) i 0)
(while (< i (sslength ss))
(setq eg (entget (ssname ss i)) i (1+ i)
eltxt (cdr (assoc 1 eg))
p (cdr (assoc 10 eg))
neg (subst
(list 10 (car p) (cadr p) (atof eltxt))
(assoc 10 eg)
eg
)
)
(entmod neg)
)
)


but i get this prompt:

Command: ELEVATE

Select objects: 1 found

Select objects:
; error: bad argument type: stringp nil


my block is called spt-r and it contains the text 50.5. any ideas???

i have also tried this routine:

Revised "TUP":
;=================================================
; > > > TUP < < <
;BILL TONNESEN EMAIL >> bt_dnd@hotmail.com
;TUP.LSP 040426
;=================================================
(defun C:TUP ()
;(svar)
;------------------------------------------------------
;... interface
(prompt "Pick Text")
(setq
t2e (ssname (ssget) 0)
v2 (scvc k (rtos (get 1 t2e)))
v3 (get 10 t2e)
v4 (vc2 (vc2 v2 v0) v3) )
(command "move" t2e "" v3 v4)
(itzovr) )
;------------------------------------------------------
;...BT.LSP Routines


but it wants to move text...i explode my attribute to text and it works but that is not the insertion point of the block. please help.
Message 3 of 21
Anonymous
in reply to: Anonymous

Try this:

(defun c:elevate (/ eg eltxt en i p ss)
(setq ss (ssget '((0 . "INSERT")(66 . 1))) i 0)
(while (< i (sslength ss))
(setq en (entnext(ssname ss i))
eg (entget en)
i (1+ i)
eltxt (cdr (assoc 1 eg))
p (cdr (assoc 10 eg))
eg (subst (cons 10 (list (car p) (cadr p) (atof eltxt)))(assoc 10
eg) eg)
)
(entmod eg)(entupd en)(princ)
)
)(princ)

Paul
wrote in message news:5800582@discussion.autodesk.com...
i have tried this routine:

(defun c:elevate ()
(setq ss (ssget) i 0)
(while (< i (sslength ss))
(setq eg (entget (ssname ss i)) i (1+ i)
eltxt (cdr (assoc 1 eg))
p (cdr (assoc 10 eg))
neg (subst
(list 10 (car p) (cadr p) (atof eltxt))
(assoc 10 eg)
eg
)
)
(entmod neg)
)
)


but i get this prompt:

Command: ELEVATE

Select objects: 1 found

Select objects:
; error: bad argument type: stringp nil


my block is called spt-r and it contains the text 50.5. any ideas???

i have also tried this routine:

Revised "TUP":
;=================================================
; > > > TUP < < <
;BILL TONNESEN EMAIL >> bt_dnd@hotmail.com
;TUP.LSP 040426
;=================================================
(defun C:TUP ()
;(svar)
;------------------------------------------------------
;... interface
(prompt "Pick Text")
(setq
t2e (ssname (ssget) 0)
v2 (scvc k (rtos (get 1 t2e)))
v3 (get 10 t2e)
v4 (vc2 (vc2 v2 v0) v3) )
(command "move" t2e "" v3 v4)
(itzovr) )
;------------------------------------------------------
;...BT.LSP Routines


but it wants to move text...i explode my attribute to text and it works but
that is not the insertion point of the block. please help.
Message 4 of 21
Anonymous
in reply to: Anonymous

that didnt do it either...i have post the attributed block i am using if that helps.

it is acad2008 format
Message 5 of 21
EC-CAD
in reply to: Anonymous

If your Attribute is 'centered'.. change all the 10's to 11's....

Bob
Message 6 of 21
Anonymous
in reply to: Anonymous

that is moving the grip of the text to the correct elevation but not the insertion point of the block. i need the insertion to move so i can snap 3dpolys to it. thanks.
Message 7 of 21
EC-CAD
in reply to: Anonymous

Try this modified version..

(defun c:elevate (/ eg eltxt en i p ss)
(setq ss (ssget '((0 . "INSERT")(66 . 1))) i 0)
(while (< i (sslength ss))
(setq blk (ssname ss i))
(setq elist (entget blk))
(setq X (car (cdr (assoc 10 elist))))
(setq Y (cadr (cdr (assoc 10 elist))))
(setq en (entnext(ssname ss i))
eg (entget en)
i (1+ i)
eltxt (cdr (assoc 1 eg))
p (cdr (assoc 10 eg))
eg (subst (cons 10 (list (car p) (cadr p) (atof eltxt)))(assoc 10
eg) eg)
)
(entmod eg)(entupd en)(princ)
(setq new_pt (list X Y (atof eltxt)))
(command "_move" blk "" "@" new_pt)
)
)
(princ)

Bob
Message 8 of 21
Anonymous
in reply to: Anonymous

when i applied the latest elevate.lsp several of the blocks changed x and y locations. i have attached the dwg i am working with.
Message 9 of 21
Anonymous
in reply to: Anonymous

Oh, so you want to move the Block and not the Attribute. Try this modified
version:

(defun c:elevate (/ bs eg eltxt en i p sen ss)
(setq ss (ssget '((0 . "INSERT")(66 . 1))) i 0)
(while (< i (sslength ss))
(setq en (ssname ss i)
ed (entget en)
p (cdr (assoc 10 ed))
sen (entnext en)
eg (entget sen)
eltxt (cdr (assoc 1 eg))
i (1+ i)
ed (subst (cons 10 (list (car p) (cadr p) (atof eltxt)))(assoc 10
ed) ed)
)
(entmod ed)(entupd en)(princ)
)
)(princ)


Paul

wrote in message news:5800655@discussion.autodesk.com...
that is moving the grip of the text to the correct elevation but not the
insertion point of the block. i need the insertion to move so i can snap
3dpolys to it. thanks.
Message 10 of 21
Anonymous
in reply to: Anonymous

that did it. AWESOME!
Message 11 of 21
Anonymous
in reply to: Anonymous

This modification takes care of both the Block insertion & the Attribute
insertion points:

(defun c:elevate (/ bs eg eltxt en i p pe sen ss)
(setq ss (ssget '((0 . "INSERT")(66 . 1))) i 0)
(while (< i (sslength ss))
(setq en (ssname ss i)
ed (entget en)
p (cdr (assoc 10 ed))
sen (entnext en)
eg (entget sen)
pe (cdr (assoc 10 eg))
eltxt (cdr (assoc 1 eg))
i (1+ i)
eg (subst (cons 10 (list (car pe) (cadr pe) (atof eltxt)))(assoc 10
eg) eg)
ed (subst (cons 10 (list (car p) (cadr p) (atof eltxt)))(assoc 10
ed) ed)
)
(entmod eg)(entupd sen)(princ)
(entmod ed)(entupd en)(princ)
)
)(princ)


Paul

wrote in message news:5800655@discussion.autodesk.com...
that is moving the grip of the text to the correct elevation but not the
insertion point of the block. i need the insertion to move so i can snap
3dpolys to it. thanks.
Message 12 of 21
EC-CAD
in reply to: Anonymous

I see A+P has it.
My sample program did not accomodate for
rotation angle.. just moved the blocks.
Sorry about that.

Bob
Message 13 of 21
krkec
in reply to: Anonymous

i have att with 2 tags, your lsp elevates block on the elevation value in 1st tag. Can U change the lsp that it can lift the 2nd value and leave the 1st alone.

THX
Message 14 of 21
Anonymous
in reply to: Anonymous

Sure, try this:

(defun c:elevate2 (/ bs eg eltxt en i p pe sen ss)
(setq ss (ssget '((0 . "INSERT")(66 . 1))) i 0)
(while (< i (sslength ss))
(setq en (ssname ss i)
ed (entget en)
p (cdr (assoc 10 ed))
sen (entnext(entnext en))
eg (entget sen)
pe (cdr (assoc 10 eg))
eltxt (cdr (assoc 1 eg))
i (1+ i)
eg (subst (cons 10 (list (car pe) (cadr pe) (atof eltxt)))(assoc
10 eg) eg)
ed (subst (cons 10 (list (car p) (cadr p) (atof eltxt)))(assoc 10
ed) ed)
)
(entmod eg)(entupd sen)(princ)
(entmod ed)(entupd en)(princ)
)
)(princ)


Paul

wrote in message news:5814623@discussion.autodesk.com...
i have att with 2 tags, your lsp elevates block on the elevation value in
1st tag. Can U change the lsp that it can lift the 2nd value and leave the
1st alone.

THX
Message 15 of 21
Craig.O
in reply to: Anonymous

This is a great lisp by the way, it works great. I have a question though... I made a spot elevation block, then I want to use your lisp to change those blocks to the given elevation. However, I'd like to preface the elevation with a character or two (P, TC, TW, G) to indicate pavement, top of curb, top of wall, ground, etc. i.e.: G125.5 or TC137.89 etc. I know I can just add another attribute, but I'd like to have just the one since it will be easier to move a single attribute around when there is other linework in the way. Is it possible to extract only the number from the attribute and assign that value for the Z coordinate?

Craig
Message 16 of 21
bob.at
in reply to: Anonymous

If you *always* have exactly n characters in front of the number, you can
use the following:

(atof (substr a (+ n 1)))

with n=1 for G125.5 etc. or n=2 for TC137.89 etc. (where a is the string
with the attribute value)

If you have different numbers of text you can use a loop like this (not
tested!):

(setq zvalue 0.0)
(setq n 0)
(while (and (= zvalue 0.0) (< n (strlen a)))
(setq zvalue (atof (subst a (+ n 1))))
(setq n (1+ n))
)

--
bob.at
CAD & GIS Services, Graz, Austria


schrieb im Newsbeitrag news:5966228@discussion.autodesk.com...
This is a great lisp by the way, it works great. I have a question
though... I made a spot elevation block, then I want to use your lisp to
change those blocks to the given elevation. However, I'd like to preface the
elevation with a character or two (P, TC, TW, G) to indicate pavement, top
of curb, top of wall, ground, etc. i.e.: G125.5 or TC137.89 etc. I know I
can just add another attribute, but I'd like to have just the one since it
will be easier to move a single attribute around when there is other
linework in the way. Is it possible to extract only the number from the
attribute and assign that value for the Z coordinate?

Craig
Message 17 of 21
Craig.O
in reply to: Anonymous

Thanks for your help Bob. But I'm sorry to say that I can't figure out where to put your modification to the lisp above. I tried and failed. This is what I see:

(defun c:elevate (/ eg eltxt en i p ss)
blah blah blah
blah blah blah
blah blah blah
blah blah blah
(princ)

Would you mind doing a cut and paste on the working lisp? Once I see where it goes, I should be able to cut/paste your second option and give that a try too. I'd like to have the option of one or two characters in the block, but it's easy enough to just use two different blocks, depending on the situation.

Thanks,
Craig
Message 18 of 21
bob.at
in reply to: Anonymous

Well I dont know wich of the above versions you are using. But between the
different "blah's" you will find in Pauls code these two lines:

*****old code****
eltxt (cdr (assoc 1 eg))
i (1+ i)

*****oend old code****

Take them, replace it with the follwoing code, and it will work (not
tested - if there is a problem please send me your block for testing):

*****new code****
eltxt (cdr (assoc 1 eg))
zvalue 0.0)
n 0))
(while (and (= zvalue 0.0) (< n (strlen eltxt)))
(setq zvalue (atof (substr eltxt (+ n 1)))
(1+ n))
)
(setq eltxt (substr eltxt n)
i (1+ i)

*****end new code****

In addition you can add the new variables to the defun line. Change it from:

(defun c:elevate (/ bs eg eltxt en i p pe sen ss)

(or something like this) to:

(defun c:elevate (/ bs eg eltxt en i p pe sen ss n zvalue)


--
bob.at
CAD & GIS Services, Graz, Austria


schrieb im Newsbeitrag news:5966318@discussion.autodesk.com...
Thanks for your help Bob. But I'm sorry to say that I can't figure out
where to put your modification to the lisp above. I tried and failed. This
is what I see:

(defun c:elevate (/ eg eltxt en i p ss)
blah blah blah
blah blah blah
blah blah blah
blah blah blah
(princ)

Would you mind doing a cut and paste on the working lisp? Once I see where
it goes, I should be able to cut/paste your second option and give that a
try too. I'd like to have the option of one or two characters in the block,
but it's easy enough to just use two different blocks, depending on the
situation.

Thanks,
Craig
Message 19 of 21
Craig.O
in reply to: Anonymous

Bob,

Thanks for your help, this code is going help enormously! I did the cut and paste, but the lisp won't even load now. Maybe it has to do with the formatting, I don't know. Here is the version of the code I am trying to modify:

Reply From: A+P
Date: Dec/13/07 - 19:42 (GMT)
Re: extract attribute value (elevation) and move attribute to z
Oh, so you want to move the Block and not the Attribute. Try this modified
version:

(defun c:elevate (/ bs eg eltxt en i p sen ss)
(setq ss (ssget '((0 . "INSERT")(66 . 1))) i 0)
(while (< i (sslength ss))
(setq en (ssname ss i)
ed (entget en)
p (cdr (assoc 10 ed))
sen (entnext en)
eg (entget sen)
eltxt (cdr (assoc 1 eg))
i (1+ i)
ed (subst (cons 10 (list (car p) (cadr p) (atof eltxt)))(assoc 10
ed) ed)
)
(entmod ed)(entupd en)(princ)
)
)(princ)

I have attached a copy of my simple spot block. It will prompt for an elevation; I would type G78.2 or TC142.78 or whatever. I would then run the elevate lisp to take the 142.78 for instance and move the donut (which is a block in the attached drawing) to the elevation 142.78. The text would remain at elevation 0. This is all to help generate a DTM of the proposed conditions for a site.

Craig
craig@DELETETHISTEXTbohleyconsulting.com
Message 20 of 21
bob.at
in reply to: Anonymous

Sorry 😞
Please give this new code a second chance:

(defun c:elevate (/ bs eg eltxt en i p sen ss)
(setq ss (ssget '((0 . "INSERT")(66 . 1))) i 0)
(while (< i (sslength ss))
(setq en (ssname ss i)
ed (entget en)
p (cdr (assoc 10 ed))
sen (entnext en)
eg (entget sen)
eltxt (cdr (assoc 1 eg))
zvalue 0.0
n 0)
(while (and (= zvalue 0.0) (< n (strlen eltxt)))
(setq zvalue (atof (substr eltxt (+ n 1)))
n (1+ n))
)
(setq eltxt (substr eltxt n)
i (1+ i)
ed (subst (cons 10 (list (car p) (cadr p) (atof eltxt)))(assoc 10 ed) ed)
)
(entmod ed)(entupd en)(princ)
)
)(princ)


--
bob.at
CAD & GIS Services, Graz, Austria


schrieb im Newsbeitrag news:5966547@discussion.autodesk.com...
Bob,

Thanks for your help, this code is going help enormously! I did the cut and
paste, but the lisp won't even load now. Maybe it has to do with the
formatting, I don't know. Here is the version of the code I am trying to
modify:

Reply From: A+P
Date: Dec/13/07 - 19:42 (GMT)
Re: extract attribute value (elevation) and move attribute to z
Oh, so you want to move the Block and not the Attribute. Try this modified
version:

(defun c:elevate (/ bs eg eltxt en i p sen ss)
(setq ss (s
sget '((0 . "INSERT")(66 . 1))) i 0)
(while (< i (sslength ss))
(setq en (ssname ss i)
ed (entget en)
p (cdr (assoc 10 ed))
sen (entnext en)
eg (entget sen)
eltxt (cdr (assoc 1 eg))
i (1+ i)
ed (subst (cons 10 (list (car p) (cadr p) (atof eltxt)))(assoc 10
ed) ed)
)
(entmod ed)(entupd en)(princ)
)
)(princ)

I have attached a copy of my simple spot block. It will prompt for an
elevation; I would type G78.2 or TC142.78 or whatever. I would then run the
elevate lisp to take the 142.78
for instance and move the donut (which is a block in the attached drawing)
to the elevation 142.78. The text would remain at elevation 0. This is all
to help generate a DTM of the proposed conditions for a site.

Craig
craig@DELETETHISTEXTbohleyconsulting.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost