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

Hight Label LISP

23 REPLIES 23
SOLVED
Reply
Message 1 of 24
Klingi162
1005 Views, 23 Replies

Hight Label LISP

Hey guys,

 

I'm trying to set up a hight label for sections and elevations. I then want to update it with a shortcut.

I already tried it with a field that shows me the y coordinates, but it won't show me the "+-"0.00 sign,when I put it to zero level. It only writes "0.00".

So I guess I have to ork with attributes. Any solutions how I can manage that?

 

cheers

23 REPLIES 23
Message 2 of 24

perhaps an "if" statement? something to the effect of If your elev = 0, then strcat +/-  and elev.

Message 3 of 24
hmsilva
in reply to: Klingi162


@Klingi162 wrote:
...

So I guess I have to ork with attributes. Any solutions how I can manage that?

 


With attributes, quick and dirty...

(defun c:test ( / *error* OLD_DIA OLD_REC OLD_ZIN PT TXT Y)

(defun *error* ( msg )
  (if Old_dia (setvar 'ATTDIA Old_dia))
  (if Old_rec (setvar 'ATTREQ Old_rec))
  (if Old_zin (setvar 'DIMZIN Old_zin))
  (if (not (member msg '("Function cancelled" "quit / exit abort")))
    (princ (strcat "\nError: " msg)))
  (princ)
  )
  
  (if (and (setq pt (getpoint "\nSpecify insertion point: "))
	   (or (findfile "Tag_.dwg");; change "Tag_.dwg" to your block name
	   (tblsearch "block" "TAG_");; change "TAG_" to your block name
	   );; or
	   );; and
    (progn
      (setq Old_dia (getvar 'ATTDIA)
	    Old_rec (getvar 'ATTREQ)
	    Old_zin (getvar 'DIMZIN))
      (setvar 'ATTDIA 0)
      (setvar 'ATTREQ 1)
      (setvar 'DIMZIN 0) 
    (setq y (cadr pt))
    (if (> y 0.0)
      (setq txt (strcat "+" (rtos y 2 2)))
      (setq txt (rtos y 2 2))
      );; if
      (command "_insert" "Tag_" "_non" pt "" "" ""  txt)
      (setvar 'ATTDIA Old_dia)
      (setvar 'ATTREQ Old_rec)
      (setvar 'DIMZIN Old_zin)
    );; progn
    (prompt "\nBlock not find or insertion point not specified! ")
    );; if
  (princ)
  );; test

HTH

Henrique

EESignature

Message 4 of 24
Klingi162
in reply to: hmsilva

your code looks nice, but doesn't do the trick I'm looking for.

I'd like to update all the hight labels that are already in the file and not a new one, because if I move the label to a different hight, it won't update with your code, right?

The other problem is that I'm using a different location for my blocklibrary, so your code won't find it. 😞

 

but thanks anyway for your help. I appreciate it alot.

Message 5 of 24

an "if" statement sounds great. but how can I put that into a field!?!?!

thanks for the input

Message 6 of 24
hmsilva
in reply to: Klingi162


@Klingi162 wrote:
...

I'd like to update all the hight labels that are already in the file ...

...


Attach one of your's labels.


@Klingi162 wrote:
...

 

The other problem is that I'm using a different location for my blocklibrary, so your code won't find it. 😞

 ...


Add the your blocklibrary location to the Support File Search Path, or at the code try:

(or (findfile "x:/blocklibrary/MyLabel.dwg");; change to the correct one

 


@Klingi162 wrote:
...

 

but thanks anyway for your help. I appreciate it alot.


You're welcome, Klingi162

 

Henrique

 

EESignature

Message 7 of 24

Hrmm well you wouldnt put the if statment into the field, you would take the elevation before hand, then test it with "if", then strcat the field and the +/- sign. Difficult wihout seeing your code Smiley Happy. So assuming your using (vlax-3d-point(getpoint )) or something similar, you would (setq) the y value to something else that would be tested before you inserted the label. I dont really have time to play with this, but i think it would go something like this:

(setq pointY ;grab y coord from selection)
(if (= pointY 0) (strcat +/- (your field code here)) (your field code here) )

 

Message 8 of 24
hmsilva
in reply to: Klingi162


@Klingi162 wrote:

...

I'd like to update all the hight labels that are already in the file

...


Klingi162,

 

if your block has only one attribute, perhaps something like this

Change the "MyBlk" to your block name

(defun c:test ( / *error* ATT ENT HND ITM NUM OLD_ZIN S1 TXT Y)

  (defun *error* ( msg )
  (if Old_zin (setvar 'DIMZIN Old_zin))
  (if (not (member msg '("Function cancelled" "quit / exit abort")))
    (princ (strcat "\nError: " msg)))
  (princ)
  )

  (if (setq s1 (ssget "_X" (list '(0 . "INSERT") '(2 . "MyBlk") '(66 . 1) (cons 410 (getvar 'CTAB)))))
    (progn
      (setq Old_zin (getvar 'DIMZIN))
      (setvar 'DIMZIN 0)
      (setq itm 0 num (sslength s1))
      (while (< itm num)
      (setq hnd	(ssname s1 itm)
	    ent	(entget hnd)
	    att	(entget (entnext hnd))
	    y	(cadr (cdr (assoc 10 ent))))
	(if (> y 0.0)
	  (setq txt (strcat "+" (rtos y 2 2)))
	  (setq txt (rtos y 2 2))
	  );; if
	(entmod (subst (cons 1 txt) (assoc 1 att) att))
	(setq itm (1+ itm))
	);; while
      (setvar 'DIMZIN Old_zin)
      );; progn
    );; if
  (princ)
  );; test

HTH

Henrique

EESignature

Message 9 of 24
Klingi162
in reply to: hmsilva

hey hmsilva,

thx for the code. Just tried it, but nothing happens. Smiley Sad

I changed the blockname to mine. when I run the script it doesn't do anything...what am I doing wrong?

Message 10 of 24
hmsilva
in reply to: Klingi162

Hi Klingi162

 

Attach one of your's labels.

 

Henrique

EESignature

Message 11 of 24
Klingi162
in reply to: hmsilva

simple and easy label...

 

 

Message 12 of 24
hmsilva
in reply to: Klingi162


@Klingi162 wrote:

simple and easy label...

 

 


 

Klingi162,

 

as I said in post # 8 
Change the "MyBlk" to your block name, according to your sample block "__Hoehenkote", try

 

(defun c:test ( / *error* ATT ENT HND ITM NUM OLD_ZIN S1 TXT Y)

  (defun *error* ( msg )
  (if Old_zin (setvar 'DIMZIN Old_zin))
  (if (not (member msg '("Function cancelled" "quit / exit abort")))
    (princ (strcat "\nError: " msg)))
  (princ)
  )

  (if (setq s1 (ssget "_X" (list '(0 . "INSERT") '(2 . "__Hoehenkote") '(66 . 1) (cons 410 (getvar 'CTAB)))))
    (progn
      (setq Old_zin (getvar 'DIMZIN))
      (setvar 'DIMZIN 0)
      (setq itm 0 num (sslength s1))
      (while (< itm num)
      (setq hnd	(ssname s1 itm)
	    ent	(entget hnd)
	    att	(entget (entnext hnd))
	    y	(cadr (cdr (assoc 10 ent))))
	(if (> y 0.0)
	  (setq txt (strcat "+" (rtos y 2 2)))
	  (setq txt (rtos y 2 2))
	  );; if
	(entmod (subst (cons 1 txt) (assoc 1 att) att))
	(setq itm (1+ itm))
	);; while
      (setvar 'DIMZIN Old_zin)
      );; progn
    );; if
  (princ)
  );; test

HTH

Henrique

EESignature

Message 13 of 24
Klingi162
in reply to: hmsilva

Thx for the help henrique. it works pretty good.

The only thing where I have still troubles is that it only works with the WCS,wright?

Because if I it to a section or an elevation with it's own UCS it won't work. Smiley Sad

 

cheers klingi

Message 14 of 24
hmsilva
in reply to: Klingi162

You're welcome, klingi

 

fixed for UCS, the code asks to select the blocks and you can select with a large window, that only the blocks will be selected...

 

(defun c:test ( / *error* ATT ENT HND ITM NUM OLD_ZIN PT S1 TXT Y)

  (defun *error* ( msg )
  (if Old_zin (setvar 'DIMZIN Old_zin))
  (if (not (member msg '("Function cancelled" "quit / exit abort")))
    (princ (strcat "\nError: " msg)))
  (princ)
  )

  (if (setq s1 (ssget "_:L" (list '(0 . "INSERT") '(2 . "__Hoehenkote") '(66 . 1) (cons 410 (getvar 'CTAB)))))
    (progn
      (setq Old_zin (getvar 'DIMZIN))
      (setvar 'DIMZIN 0)
      (setq itm 0 num (sslength s1))
      (while (< itm num)
      (setq hnd	(ssname s1 itm)
	    ent	(entget hnd)
	    att	(entget (entnext hnd))
	    pt  (trans (cdr (assoc 10 ent)) 0 1)
	    y	(cadr pt))
	(if (> y 0.0)
	  (setq txt (strcat "+" (rtos y 2 2)))
	  (setq txt (rtos y 2 2))
	  );; if
	(entmod (subst (cons 1 txt) (assoc 1 att) att))
	(setq itm (1+ itm))
	);; while
      (setvar 'DIMZIN Old_zin)
      );; progn
    );; if
  (princ)
  );; test

hope that helps

Henrique

EESignature

Message 15 of 24
Klingi162
in reply to: hmsilva

wow, you are fast. 😉

thx again. people like you let noobs like me dream of a finally working autocad system. 😉

 

is there also a way that it scales the output-height, because I'm working with centimeters? so everything needs to be scaled by hundred i guess.

also when I put it to ±0.00 it loses the prefix and only writes 0.00...

 

I hope I don't ask to much from you, I already tried to understand the code and change it, but didn't succeed. 😞

 

 

Message 16 of 24
hmsilva
in reply to: Klingi162


@Klingi162 wrote:
...

is there also a way that it scales the output-height, because I'm working with centimeters? so everything needs to be scaled by hundred i guess.

also when I put it to ±0.00 it loses the prefix and only writes 0.00...

 ...


Ok, let's see if I understand,

the code puts 0,0 with no prefix, do you want the 0,0 as  ±0.00?

Units are meters and you need to work with centimeters?

Is easier to me if you attache a sample dwg with your blocks in place and written as you intend.

 

Henrique

EESignature

Message 17 of 24
Klingi162
in reply to: hmsilva

I wrote the issue in the dwg.

thx Henrique

Message 18 of 24
hmsilva
in reply to: Klingi162

klingi,
let's see if the code already works as you intend...

 

(defun c:test ( / *error* ATT ENT HND ITM NUM OLD_ZIN PT S1 TXT Y)

  (defun *error* ( msg )
  (if Old_zin (setvar 'DIMZIN Old_zin))
  (if (not (member msg '("Function cancelled" "quit / exit abort")))
    (princ (strcat "\nError: " msg)))
  (princ)
  )

  (if (setq s1 (ssget "_:L" (list '(0 . "INSERT") '(2 . "__Hoehenkote") '(66 . 1) (cons 410 (getvar 'CTAB)))))
    (progn
      (setq Old_zin (getvar 'DIMZIN))
      (setvar 'DIMZIN 0)
      (setq itm 0 num (sslength s1))
      (while (< itm num)
      (setq hnd	(ssname s1 itm)
	    ent	(entget hnd)
	    att	(entget (entnext hnd))
	    pt  (trans (cdr (assoc 10 ent)) 0 1)
	    y	(/ (cadr pt) 100.0))
	(cond ((> y 0.0)
	       (setq txt (strcat "+" (rtos y 2 2))))
	      ((= y 0.0)
	       (setq txt (strcat "±" (rtos y 2 2))))
	      (T (setq txt (rtos y 2 2)))
	);; cond
	(entmod (subst (cons 1 txt) (assoc 1 att) att))
	(setq itm (1+ itm))
	);; while
      (setvar 'DIMZIN Old_zin)
      );; progn
    );; if
  (princ)
  );; test

 

Henrique

EESignature

Message 19 of 24
Klingi162
in reply to: hmsilva

JUHU! works great. thx henrique

 

i appreciate it a lot. Smiley Very Happy

Message 20 of 24
hmsilva
in reply to: Klingi162

You're welcome, klingi
Glad I could help

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost