while/if?

Discussion in 'AutoCAD' started by chuck, Oct 22, 2004.

  1. chuck

    chuck Guest

    Hi everyone Iv'e written a lisp routine which might seem primitive to some.
    This is what I want to happen.... I want the routine to perform an operation
    "txtfr" which will format the text of all dimension entities on the drawing
    to a customized font and then exit the progar "quietly". As it stands every
    time I rum the program I will get an error message following the execution
    of the program. The program works perfectly the first time, with the
    exception of the error message, but on subsequent attempts, I have to run
    the program twice in order for it to take effect. I am quite new at using
    the "while" and "if" logic combination in a program and am wondering if
    there might be something wrong here. Can anyone help?


    ;chdim written by Chuck Fluri 20/10/04
    ;converts dimension text to a formatted text string

    (defun c:chdim ()
    (setq ent1 (entnext)) ;sets the entity to the first entity in the
    table
    (while (/= nil ent1) ;checks to see if the end of the table has been
    reached
    (progn (setq entype (cdr (assoc 0 entlist))
    ;defines the entity type
    )
    (if (= entype "DIMENSION") ;if the entity is a dimension...
    (progn
    (setq entlist (entget ent1)
    ;creates a list of the entity codes
    dimlen (cdr (assoc 42 entlist))
    ;retrieves the dimension length
    reptxt (txtfr dimlen)
    ;converts the dimension length to a formatted string
    arxcode (cons 1 reptxt)
    ;constructs the new code for the dimension string
    ) ;setq
    (setq entlist (subst arxcode (assoc 1 entlist) entlist)
    ;replaces the formated string code for the the existing one
    ) ;setq
    (entmod entlist) ;updates the data base
    ) ;progn
    ) ;if
    (setq ent1 (entnext ent1) ;procceed to the next entity
    entlist (entget ent1) ;constructs the new list of codes
    ) ;setq
    ) ;progn
    ) ;while
    (setq ent1 nil) ;sets the entity to nil
    (princ) ;exit quietly
    ) ;defun
     
    chuck, Oct 22, 2004
    #1
  2. chuck

    Jeff Guest

    Hi Chuck,
    A couple small things and one BIG reccomendation......
    The small things.....I believe your error is coming from this portion:
    (setq ent1 (entnext ent1) ;;procceed to the next entity
    entlist (entget ent1))

    You are using (entget), which is normally fine except when the end of the
    database is reached and (entnext) returns nil. Relocating the (entget) would
    solve this.
    Next, why change the values to a string? If the conversion function is just
    appending text to the value then you can do that AND keep the associative
    values by using prefixes & suffixes.

    Now the big thing......(entnext)'ing through a drawing is NOT the way to do
    what you want. Look into Filtered Selection Sets! This will dramatically
    reduce the time it takes to run your routine. An example:

    (set counter -1)
    (if (setq ss (ssget "x" '((0 . "DIMENSION")(1 . ""))));;gets ALL dimensions
    that do not use the text override
    (progn
    (while (< (setq counter (1+ counter)) (sslength ss));keep going while
    counter is less than ss length
    (setq ent (ssname ss counter))
    ;;do your stuff with the dimension......
    );while
    );progn
    );if

    HTH,
     
    Jeff, Oct 22, 2004
    #2
  3. chuck

    chuck Guest

    Hi Jeff I've used your suggestion regarding filtered selection sets and it
    works like a charm! Thankyou. The reason I'm not appending the dimension
    text is because what I'm trying to accomplish here is to use a custom font
    whereby the fraction portion of the dimension text is stacked wit no bar and
    no inch marker. Also the romansf font is much nicer than the AutoCAD stacked
    font.

    I have one more question, when I attempt to filter ot the radial and
    diametric dimensions using association 100, I get the wrong result. It seems
    there are 3 associated values for 100 in a dimension and it's using the
    first one which is ACDBEntity. How do I get it to recognize the association
    I want? as you can tell I'm quite new to entity handling and so far am
    entirely self-taught. I appreciate any help. Thanks
     
    chuck, Oct 27, 2004
    #3
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.