Jump to content

Height on points


ninjaroo5075

Recommended Posts

Hello i have found a code that creates text from a Z Value of a point. But I can not get it to make the text from the Z value and put an SL in front of the height like SL45.12, can any one help the code is below:

 

(defun c:zheight45 ()

(setvar "cmdecho" 0)

(setq u 0)

(setq numss (sslength (setq ss (ssget))))

(setq th (cdr (assoc 40 (tblsearch "STYLE" "HEIGHT"))))

(ls "height")

(command "style" "height" "" "" "" "" "" "")

(while (/= numss 0)

(setq numss (1- numss))

(setq etl (entget (ssname ss numss)))

(if (= "INSERT" (cdr (assoc '0 etl)))

(progn ;; only do it for blocks

(setq u (1+ u))

(setq hgt (cadddr (assoc 10 etl)))

(if (/= hgt 0.0)

(progn (setq hgtx (rtos hgt 2 2))

(setq p1 (2d (polar (trans (cdr (assoc 10 etl)) 0 1) 0.0 th)))

(command "text" p1 45.0 hgtx)

)

)

)

)

)

(princ)

)

Link to comment
Share on other sites

But I can not get it to make the text from the Z value and put an SL in front of the height like SL45.12

 

Adding "SL" as prefix can be done. But what does this means? ?? Explain it again

 

([color="red"]ls[/color] "height")  ;<- This function doesn't exist in your code

Edited by satishrajdev
Link to comment
Share on other sites

Thank you BIGAL that works. satishrajdev I found the LS function and 2d function at the bottom of the lsp file that runs in this code. Everything works now, code is below in case anyone else would need this.

 

(defun c:slheight () ;; This code puts a SL in front of the Z Value of the point you choose in a layer called HEIGHT
 (defun ls (ln) 
 (if (= nil (tblsearch "LAYER" ln))
 (command "layer" "M" ln "")
 (command "layer" "t" ln "on" ln "M" ln "")))
 (defun 2d (l)
 (list (car l) 
 (cadr l)))
 (setvar "cmdecho" 0)
 (setq u 0)
 (setq numss (sslength (setq ss (ssget))))
 (setq th (cdr (assoc 40 (tblsearch "STYLE" "HEIGHT"))))
 (ls "height")
 (command "style" "height" "" "" "" "" "" "")
 (while (/= numss 0)
   (setq numss (1- numss))
   (setq etl (entget (ssname ss numss)))
   (if    (= "INSERT" (cdr (assoc '0 etl)))
     (progn ;; only do it for blocks                        
        (setq u (1+ u))
        (setq hgt (cadddr (assoc 10 etl)))
        (if (/= hgt 0.0)
           (progn (setq hgtx (StrCat "SL" (rtos hgt 2 2)))
             (setq p1 (2d (polar (trans (cdr (assoc 10 etl)) 0 1) 0.0 th)))
             (command "text" p1 90.0 hgtx)
          )
        )
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

With little variation... try this

(defun c:test (/ ss layc cmd i bp ele)
 (if (setq ss (ssget '((0 . "insert"))))
   (progn
     (defun layc (a)
(if (not (tblsearch "style" a))
  (command "layer" "m" a "")
  (command "layer" "t" a "on" a "m" a "")
)
     )
     (setq cmd (getvar 'cmdecho))
     (setvar "cmdecho" 0)
     (layc "height")
     (command "style" "height" "" "" "" "" "" "" "") ;<- edit here as per your requirement
     (repeat (setq i (sslength ss))
(setq bp  (cdr (assoc 10 (entget (ssname ss (setq i (1- i))))))
      ele (caddr bp)
)
(if (> ele 0.0)
  (command "text"
	   (trans bp 0 1)
	   1.8
	   90.
	   (strcat "SL" (rtos ele 2 2))
  )
)
     )
     (setvar "cmdecho" cmd)
   )
 )
 (princ)
)

Edited by satishrajdev
Link to comment
Share on other sites

It happened because of

[b]([color="blue"]command [/color][color="#ff00ff"]"text"[/color] point [color="red"]height[/color] rotation textvalue)[/b] ;<- height added here

[b]([color="blue"]command [/color][color="#ff00ff"]"text"[/color] point rotation textvalue)[/b] ;<- as per your code

 

Which autocad are you using? I am using Autocad 2013 and in it Text command asks height to specify :( you just remove that to work properly

Link to comment
Share on other sites

I am using Autocad 2015. I have other commands that change the USERR4 settings to the scale I need my drawing to be and therefore scales my text to align with the scale of the USERR4 settings. With the last code I just put on here c:slheight works as you can see on the picture i just added. The code grabs the height of the point and puts an SL in front of it for example if you need a surface level height on a manhole. I am in surveying so this will come in real handy.

attachment.php?attachmentid=55597&cid=1&stc=1

slheight.jpg

Link to comment
Share on other sites

It happened because of

[b]([color="blue"]command [/color][color="#ff00ff"]"text"[/color] point [color="red"]height[/color] rotation textvalue)[/b] ;<- height added here

[b]([color="blue"]command [/color][color="#ff00ff"]"text"[/color] point rotation textvalue)[/b] ;<- as per your code

Which autocad are you using? I am using Autocad 2013 and in it Text command asks height to specify :( you just remove that to work properly

 

Doesn't matter which version if height is set to 0.0 in the text style AutoCAD will prompt for height otherwise it will not.

 

If you wish to code for either case

(cdr(assoc 40(entget(tblobjname "style" (getvar "TEXTSTYLE")))))

will return the height of the current text style. Test and run with height if needed, without if not.

Link to comment
Share on other sites

Doesn't matter which version if height is set to 0.0 in the text style AutoCAD will prompt for height otherwise it will not.

 

If you wish to code for either case

(cdr(assoc 40(entget(tblobjname "style" (getvar "TEXTSTYLE")))))

will return the height of the current text style. Test and run with height if needed, without if not.

 

Great... Thank you :thumbsup:

I wasn't aware of it. Will update code tomorrow.

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