Change Dimstyle TextStyle

Discussion in 'AutoCAD' started by John Avitt, Jan 26, 2005.

  1. John Avitt

    John Avitt Guest

    I am trying to change the textstyle associated with a particular dimension
    style. The code that follows only sets an override for the text style; it
    does not change the original dimension style. Also, it must be done without
    using the (command) function.

    (defun c:fixStyle2 (/ a b c DS SN1 SN2)
    (setq DS "STANDARD") ; dimension style affected
    (setq SN1 (strcase "BAD_STYLE")) ; style that I don't want
    (setq SN2 (strcase "STANDARD")) ; style that I want to change to
    (setq a (tblobjname "DIMSTYLE" DS)) ; get dimstyle entity name
    (setq b (entget a)) ; get dimstyle entity data
    (setq c (cdr (assoc 340 b))) ; get textstyle pointer
    (if
    (equal c (tblobjname "STYLE" SN1)) ; compare pointers
    (entmod
    (subst
    (cons 340 (tblobjname "STYLE" SN2))
    (assoc 340 b)
    b
    )
    )
    )
    (princ)
    )
     
    John Avitt, Jan 26, 2005
    #1
  2. John Avitt

    Walt Engle Guest

    If you're interested, below is a lsp routine that changes text style globally:

    ; CHGSTY.LSP
    ; CHANGES text GLOBALLY
    (defun c:chgsty ()
    (prompt "GLOBAL TEXT STYLE CHANGE.")
    (terpri)
    (setvar "cmdecho" 0)
    (initget 1 "SE ST ")
    (setq G (strcase (substr (getkword "SElection/<STyle>: ")1 2)))
    (cond
    ((= G "SE")
    (setq A (ssget))
    (setq B (sslength A))
    (initget 1) (setq C (getstring "\nEnter new text style: "))
    (extang C)
    (while
    (> B 0)
    (setq B (1- B))
    (setq D (ssname A B))
    (setq D (entget D))
    (setq E (assoc 7 D))
    (setq F (cons 7 C))
    (setq D (subst F E D))
    (setq H (assoc 51 D))
    (setq I (cons 51 J))
    (entmod (subst I H D))
    )
    (setq A nil)
    )
    ((or (= G "ST") (= G ""))
    (initget 1)
    (setq A (strcase (getstring "\nEnter text style to change: ")))
    (initget 1) (setq C (getstring "\nEnter new text style: "))
    (setq D (entnext))
    (extang C)
    (while
    D
    (princ ".")
    (setq E (entget D))
    (if
    (and (= "TEXT" (cdr (assoc 0 E))) (= A (cdr (assoc 7 E))))
    (progn
    (setq F (assoc 7 E))
    (setq G (cons 7 C))
    (setq E (subst G F E))
    (setq H (assoc 51 E))
    (setq I (cons 51 J))
    (entmod (subst I H E))
    )
    )
    (setq D (entnext D))
    )
    )
    )
    (princ)
    )
     
    Walt Engle, Jan 26, 2005
    #2
  3. John Avitt

    John Avitt Guest

    Walt,

    Thank you for the post. Unfortunately, it does not do everything I want it
    to. The code I posted is only a small part of a larger function. This larger
    function is intended to find EVERY reference to a particular text style and
    replace it with another text style. This means that several things have to
    be checked:

    - Entities of type TEXT, MTEXT, or ATTDEF.
    - Any DimStyle that references the said text style.
    - Existing dimensions that use the text style as an override.
    - Any attributes associated with existing INSERT entities.
    - Any of the above entities that are nested within a block.
    - (there may be others that I have not considered)

    I have managed to get it all working except for one thing. It works for all
    dimstyles except the current dimstyle, for which it only sets an override.
    The associated code for this step is as posted before.

    One way I have been able to work around it is to create a temporary
    dimstyle, set it current, change the textstyle for all the other dimstyles,
    set the original dimstyle current, and then delete the temporary dimstyle.
    But, once I am done, I have not been able to delete the table entry for the
    temp dimstyle with (entdel). (That is the subject of another post).

    The only way I have been able to get rid of the temp dimstyle and the (now
    unreferenced) text style is to PURGE, which I cannot do in AutoLISP without
    using the (command) function, which I do not like to use.

    Any ideas are appreciated.

    Thank you.

    John
     
    John Avitt, Jan 26, 2005
    #3
  4. John Avitt

    Adesu Guest

    Hi Walt,I am not yet understanding,what do you mean and purpose "(extang C)"
     
    Adesu, Jan 27, 2005
    #4
  5. John Avitt

    Walt Engle Guest

    I can't remember - this was written in 1986 and I haven't worked with lsp
    programming for the last nine years. Try the routine - I use it all the time to
    either select (SE) individual text or to change any style (ST). Works like a
    charm.
     
    Walt Engle, Jan 27, 2005
    #5
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.