Jump to content

Incrementing Number Lisp


qball

Recommended Posts

I have this incrementing number lisp. But now I am using Annotative text. So I need to take out and clean up the references to Dimscale and Textsize I think. But I'm not really sure what to do. Can someone help?

 

; inserts increasing numbers
(defun c:nm (/ p n ni ts oecho ds th txt na)
 
 (setq ts (getvar "textsize"))
 (if (= 0 (getvar "dimscale"))(setq ds 1.0)(setq ds (getvar "dimscale")))
 (setq th (getvar "dimtxt"))
 (setq txt (* th ds))
 (if nn (setq nn (fix nn))(setq nn 1))
 (if (= nn 0)(setq nn 1))
 (princ "\n Increment by < ")
 (princ nn)
 (princ " >? : ")
 (setq ni (getint))
 (if (= ni nil)(setq ni nn)(setq nn ni))
 
 (if np
   ()
   (setq np 1)
 )
 (princ "\n Start or continue with number < ")
 (princ np)
 (princ " >? : ")
 (setq n (getint))
 (if (= n nil)
   (setq n np)
   (setq np n)
 )
 (setq p (getpoint "\n Number location: "))
 (setq oecho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 
 (while p
   (setq na (itoa n))
   (entmake (list (cons 0 "TEXT") 
     (cons 10 p) 
     (cons 11 p) 
     (cons 1 na); actual text
     (cons 7 (getvar "TEXTSTYLE"))
     (cons 40 txt)
     (cons 72 4)
      )
    )
   (setq p (getpoint "\n Next number location: ")
  n (+ ni n)
  np n
   )
 )
 
 (setvar "cmdecho" oecho)
 (princ)
)
(princ "\n Type > NM <   to insert numbers.")

Link to comment
Share on other sites

yes, this one works. But not for annotative text. It also asks a starting point so you can continue where you left off when last used the command.

Link to comment
Share on other sites

Maybe ? :)

 

(defun c:Test (/ str p)
 (if (setq str (getint "\n Start Number :"))
   (progn
     (while
       (setq p (getpoint "\n Text Location :"))
        (entmakex (list (cons 0 "MTEXT")
                        '(100 . "AcDbEntity")
                        '(100 . "AcDbMText")
                        '(7 . "[color=red][b]YourAnnotativeTextStyle[/b][/color]")
                        (cons 1 (rtos str 2 0))
                        (cons 10 (trans p 1 0))
                        (cons 40 (getvar 'textsize))
                        '(50 . 0.0)
                        '(210 0.0 0.0 1.0)
                  )
        )
        (command "_.chprop" (entlast) "" "_A" "_Y" "")
        (setq str (1+ str))
     )
   )
   (princ)
 )
 (princ)
)

 

Tharwat

Link to comment
Share on other sites

I got around to trying it and it inserts the same text height of 5/128" Paper height regardless of which Annotative scale I'm set to. I changed your red text to my Style. I also changed the Mtext to Text for this.

After executing the lisp then using the Dtext command, then doing the Lisp again, the text converted to 5/64" Model height.

Link to comment
Share on other sites

"Textsize" variable will give you the height for the current TEXTSTYLE, need to mulitply that by the current annoscale unit.

 

try this:

 

 
(defun c:Test (/ str p i a Found)
    [color=blue] (if (not scle)
     (foreach
           scle  (dictsearch (namedobjdict) "ACAD_SCALELIST")
          (if (= 350 (car scle))
               (setq a (cons (cdr scle) a)))
          )
         )
[/color]  (if (setq str (getint "\n Start Number :"))
   (progn
     (setq i -1)
[color=blue](while (not Found)
             (if (eq (cdr (assoc 300
              (setq Factor (entget (nth (setq i (1+ i)) a))))) (getvar 'Cannoscale))
                  (setq Height (* (cdr (assoc 40
                                          (tblsearch "STYLE" "YourAnnotativeTextStyle")))
                                          (cdr (assoc 141 Factor)))
                             Found T))
             )[/color]    
     (while
       (setq p (getpoint "\n Text Location :"))
        (entmakex (list (cons 0 "MTEXT")
                        '(100 . "AcDbEntity")
                        '(100 . "AcDbMText")
                        '(7 . "YourAnnotativeTextStyle")
                        (cons 1 (rtos str 2 0))
                        (cons 10 (trans p 1 0))
                       [color=blue] (cons 40 Height)
[/color]                         '(50 . 0.0)
                        '(210 0.0 0.0 1.0)
                  )
        )
        (command "_.chprop" (entlast) "" "_A" "_Y" "")
        (setq str (1+ str))
     )
   )
   (princ)
 )
 (princ)
)

Hope this helps

Edited by pBe
Link to comment
Share on other sites

I changed "YourAnnotativeTextStyle" in 2 locations only.

It still did not work. Text size is 15/256" Paper Text Height.

Link to comment
Share on other sites

Tell you what my friend.. you need to check your annotative textstyle.

 

you MUST specify text hieght for Annotative text style (because thats the whole point of Annotative text), now the height indicated on that style will be the text height in PAPERPSACE as the scale is always 1:1 on _.pspace not _.mspace

 

say you use 1/8" text height for your annotative textstyle. and your current annoscale is 1/4"=1'-0" the model text height will be 6" and paper space height will be 1/8".. for 1/2=1'-0" annoscale model text height will ne 3" and paper space height will still be 1/8". so no matter what scale you're using height for paperspace viewport will be 1/8" or whatever you indicated on your annotative textstyle.

 

we use 0.00 height for regular textstyle as we used it for dimensions (which is also annotative).

 

Play around with it and give us a holler

 

BTW:do you annotate your drawings on Paperspace? (hope not) 8)

Link to comment
Share on other sites

I think there is something wrong with the code. My Textstyle has a Paper Text Height of 5/64". I changed that to 1" and then executed the Lisp, Listed the objects and their Paper Text Height is 1/8" when using any Annotative Scale. Basically the Lisp isn't being annotative at all. It's multiplying the Paper Text Height somehow, but incorrectly. I changed the Text Style Height to 0" and the numbers all come in at 3 3/4" Model Text Height, the properties say that the Paper Text Height is 5/128" or 15/64".... or something else depending on which Annoscale I use. But Model Text Height remains the same. It's very strange.

Link to comment
Share on other sites

strange indeed... post that particular drawing (2009) here and let me have a look/see.... :)

 

or try it this way....

 

 
(defun c:Test  (/ str p)
     (vl-load-com)
     (if (setq str (getint "\n Start Number :"))
           (progn
                 (while
                       (setq p (getpoint "\n Text Location :"))
                            (vlax-invoke
                                  (vlax-get
                                        (vla-get-ActiveLayout
                                              (vla-get-activedocument
                                                    (vlax-get-acad-object)))
                                        'Block)
                                  'AddMText
                                  p
                                  0.0
                                  (rtos str 2 0))
                            (setq str (1+ str))
                            )
                 )
           )
     (princ)
     )   

 

This would follow tjhe CURRENT textstyle (annotative or regular)

Edited by pBe
Link to comment
Share on other sites

The problem is that using DXF codes in annotative text works very strangely. I'm going to explain it using metric scales, since it's a bit "easier" to understand (more straight-forward fractions :wink:). But it should give the idea, whatever measurement system you're using:

 

When you get hold of the dxf data through the entget function, you have the currently displayed model space text height in code 40. Say the text is set to be 1.0 high in paper space. Thus if the actively displayed version of the text is showing the 1:10 scale this value will return 10.0.

 

However, when you send the 40 code through to entmake/entmod the opposite occurs: If you send 10.0 it gets interpreted as "That's the paper space height". So the text is made/modified to now have a model space height of 100.0.

 

I generally just go with the ActiveX methods instead when working with annotative text. Then you don't need to worry about this.

 

It gets even worse when you modify text instead of creating it. The problem is that the model-space text height is that which is displayed (which might be something different than your CAnnoScale). So you can't simply divide/multiply by the CAnnoScaleValue to convert to/from PS/MS.

Link to comment
Share on other sites

I agree Irneb.. i just picked up where Tharwat left off.. i updated my previous post and show one using ADD-MTEXT instead of entmake.. i find it weird why the modified entmake code fails on his drawing.. did you try it on your end?

Link to comment
Share on other sites

That latest one made the text too large. 1/8" = 1'-0" Annoscale the text should be 5/64 paper, 7 1/2" model. The properties say 3 3/4" paper and 30'-0" model.

Link to comment
Share on other sites

  • 3 years later...

Hi,

I am new in Lisp but mader the following adjustment because I need a prefix of zero´s depending size of text:

I do not understand why, but it holds at string declaration: (setq mystr "whatever")

Any ideas?

 

Thankx a lot

 

; inserts increasing numbers

(defun c:nm (/ p n ni ts oecho ds th txt na)

 

(setq ts (getvar "textsize"))

(if (= 0 (getvar "dimscale"))(setq ds 1.0)(setq ds (getvar "dimscale")))

(setq th (getvar "dimtxt"))

(setq txt (* th ds))

(if nn (setq nn (fix nn))(setq nn 1))

(if (= nn 0)(setq nn 1))

(princ "\n Increment by

(princ nn)

(princ " >? : ")

(setq ni (getint))

(if (= ni nil)(setq ni nn)(setq nn ni))

 

(if np

()

(setq np 1)

)

(princ "\n Start or continue with number

(princ np)

(princ " >? : ")

(setq n (getint))

(if (= n nil)

(setq n np)

(setq np n)

)

(setq p (getpoint "\n Number location: "))

(setq oecho (getvar "cmdecho"))

(setvar "cmdecho" 0)

 

(while p

(setq na (itoa n))

(setq mystr "whatever")

 

(cond

 

((> 999 n) (= mystr ""))

((> 99 n) (= mystr "0"))

((> 9 n) (= mystr "00"))

((

)

(setq na2(strcat(mystr na)))

 

(entmake (list (cons 0 "TEXT")

(cons 10 p)

(cons 11 p)

(cons 1 na)

(cons 7 (getvar "TEXTSTYLE"))

(cons 40 txt)

(cons 72 4)

)

)

(setq p (getpoint "\n Next number location: ")

n (+ ni n)

np n

)

)

 

(setvar "cmdecho" oecho)

(princ)

)

(princ "\n Type > NM

Link to comment
Share on other sites

Hi,

I am new in Lisp but mader the following adjustment because I need a prefix of zero´s depending size of text:

I do not understand why, but it holds at string declaration: (setq mystr "whatever")

Any ideas?

 

...
...
(setq mystr [color="red"]"whatever"[/color]) ; <--- if this problem ?? remove it

(cond

((> 999 n) (= mystr "")) ; <--- if need this as prefix? then change [color="red"](= mystr "")[/color] to ([color="blue"]setq[/color] mystr "")?
((> 99 n) (= mystr "0")) ; <--- ([color="blue"]setq[/color] mystr "0")
((> 9 n) (= mystr "00")) ; <--- ([color="blue"]setq[/color] mystr "00")
((< 10 n) (= mystr "000")) ; <--- ([color="blue"]setq[/color] mystr "000")
)
 
(setq [color="red"]na2[/color](strcat [color="red"]mystr na[/color])) ;<----  was (setq na2(strcat (mystr na))) ; mystr is not a function
 
(entmake (list (cons 0 "TEXT") 
(cons 10 p) 
(cons 11 p) 
(cons 1 [color="red"]na2[/color]) ; <---- was (cons 1 na) 
(cons 7 (getvar "TEXTSTYLE"))
(cons 40 txt)
(cons 72 4)
)
)
...
...
...

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