Text Picking Problem

Discussion in 'AutoCAD' started by spencer1971, Sep 29, 2004.

  1. spencer1971

    spencer1971 Guest

    Can anyone help with this text listing problem,

    The following lisp is supposed to read the height of existing text and amended dimscale ltscale etc. to allow for swapping between detailing scales.

    Is wotrks about 50% of the time but sometimes does not seem to recognise the text when it is picked.

    Any help would be greatly appreciated..

    (defun c:setsc (/ d h ds1 dst ds1)
    (setq e (entsel "\nSelect Text: ")
    d (entget (car e))
    h (cdr (assoc 40 d))
    )
    (if (= h 2.5) (setq ds1 1))
    (if (= h 5) (setq ds1 2))
    (if (= h 12.5) (setq ds1 5))
    (if (= h 25) (setq ds1 10))
    (if (= h 50) (setq ds1 20))
    (if (= h 62.5) (setq ds1 25))
    (if (= h 125) (setq ds1 50))
    (if (= h 250) (setq ds1 100))
    (if (= h 500) (setq ds1 200))
    (setvar "ltscale" ds1)
    (setvar "dimscale" ds1)

    (setq dst (strcat (itoa ds1) "-DIM"))
    (command "-dimstyle" "R" dst)
    (command "regen")
    (princ)
    )

    Thanks

    Spencer
     
    spencer1971, Sep 29, 2004
    #1
  2. spencer1971

    zeha Guest

    Spencer,

    there are many things where it go wrong.
    You can pick a none text entity
    Dimstyle not exist
    Texhtheigth can not exactly the value the code 40 returned.

    In that case you can use the condition statement (cond

    Look below to the modified routine
    (defun c:setsc (/ d h ds1 dst ds1)
    (setq e (entsel "\nSelect Text: ")
    d (entget (car e))
    h (cdr (assoc 40 d))
    )
    (setq ds1
    (cond ((<= h 2.5) 1)
    ((<= h 5) 2)
    ((<= h 12.5) 5)
    ((<= h 25) 10)
    ((<= h 50) 20)
    ((<= h 62.5) 25)
    ((<= h 125) 50)
    ((<= h 250) 100)
    (T 200)
    ))
    (setvar "ltscale" ds1)
    (setvar "dimscale" ds1)

    (setq dst (strcat (itoa ds1) "-DIM"))
    (if (tblsearch "dimstyle" dst)
    (command "-dimstyle" "R" dst); existing style
    (alert(strcat "Style "dst not exist))) ; make your style here style not exist
    ;something like (command "-dimstyle" "save" dst)
    (command "regen")
    (princ)
    )

    Good luck
    Cheers.

    Harrie
     
    zeha, Sep 29, 2004
    #2
  3. spencer1971

    spencer1971 Guest

    Harrie

    It works great.

    Thank you for your help, Ive never used the cond command as Im only starting out with lisp writing, Ill remember that for next time.



    Spencer
     
    spencer1971, Sep 29, 2004
    #3
  4. spencer1971

    Paul Turvill Guest

    Wouldn't it be a lot simpler to just divide h by 2.5?
    ___

    starting out with lisp writing, Ill remember that for next time.
     
    Paul Turvill, Sep 29, 2004
    #4
  5. spencer1971

    spencer1971 Guest

    Paul,

    You are absolutely right. Amazing what you miss when concentrating on getting a lisp to work.

    Spencer
     
    spencer1971, Sep 30, 2004
    #5
  6. spencer1971

    zeha Guest

    Spencer,

    Only a hint

    every textheigth give's a new dimstyle
    maybe 1000 or more dimstyles can be created.
    of course this is dependent on de different textheigth you picked.
    I don't now if you want that.


    With the cond statement there only the given conditions
     
    zeha, Sep 30, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.